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. |
| 6643 | * @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] | 6644 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6645 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6646 | * @param packageName The name of the package that the current configuration will be replaced |
| 6647 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6648 | * @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] | 6649 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6651 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6654 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6655 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | final long identity = Binder.clearCallingIdentity(); |
| 6657 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6658 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6659 | // may happen if the device does not support IMS. |
| 6660 | return false; |
| 6661 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6662 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6663 | for (int featureType : featureTypes) { |
| 6664 | featureConfig.put(featureType, packageName); |
| 6665 | } |
| 6666 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6667 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | } finally { |
| 6669 | Binder.restoreCallingIdentity(identity); |
| 6670 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6671 | } |
| 6672 | |
| 6673 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6674 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6675 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6676 | * |
| 6677 | * This should only be used for testing. |
| 6678 | * |
| 6679 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6680 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6681 | */ |
| 6682 | @Override |
| 6683 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6684 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6685 | "clearCarrierImsServiceOverride"); |
| 6686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6687 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6688 | |
| 6689 | final long identity = Binder.clearCallingIdentity(); |
| 6690 | try { |
| 6691 | if (mImsResolver == null) { |
| 6692 | // may happen if the device does not support IMS. |
| 6693 | return false; |
| 6694 | } |
| 6695 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(identity); |
| 6698 | } |
| 6699 | } |
| 6700 | |
| 6701 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6702 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6703 | * |
| 6704 | * @param slotId The slot that the ImsService is associated with. |
| 6705 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6706 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6707 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6708 | * @return the package name of the ImsService configuration. |
| 6709 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6710 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6711 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6712 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6713 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6714 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6718 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6719 | // may happen if the device does not support IMS. |
| 6720 | return ""; |
| 6721 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6722 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6723 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6724 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6725 | } finally { |
| 6726 | Binder.restoreCallingIdentity(identity); |
| 6727 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6728 | } |
| 6729 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6730 | /** |
| 6731 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6732 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6733 | * @param callback A callback with an integer containing the |
| 6734 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6735 | */ |
| 6736 | @Override |
| 6737 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6738 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6739 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6741 | "IMS not available on device."); |
| 6742 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6743 | final long token = Binder.clearCallingIdentity(); |
| 6744 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6745 | int slotId = getSlotIndex(subId); |
| 6746 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6747 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6748 | + subId + "'"); |
| 6749 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6750 | } |
| 6751 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6752 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6753 | try { |
| 6754 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6755 | } catch (RemoteException e) { |
| 6756 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6757 | + "Ignore"); |
| 6758 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6759 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6760 | } catch (ImsException e) { |
| 6761 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6762 | } finally { |
| 6763 | Binder.restoreCallingIdentity(token); |
| 6764 | } |
| 6765 | } |
| 6766 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6767 | /** |
| 6768 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6769 | */ |
| 6770 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6771 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
| 6774 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6775 | // NOTE: Before S, this method only set the default phone. |
| 6776 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6777 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6778 | phone.setImsRegistrationState(registered); |
| 6779 | } |
| 6780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | } finally { |
| 6782 | Binder.restoreCallingIdentity(identity); |
| 6783 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6787 | * Set the network selection mode to automatic. |
| 6788 | * |
| 6789 | */ |
| 6790 | @Override |
| 6791 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6793 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6794 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6795 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6796 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6797 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6798 | final long identity = Binder.clearCallingIdentity(); |
| 6799 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6800 | if (!isActiveSubscription(subId)) { |
| 6801 | return; |
| 6802 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6804 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 6805 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | } finally { |
| 6807 | Binder.restoreCallingIdentity(identity); |
| 6808 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6809 | } |
| 6810 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6811 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6812 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6813 | * |
| 6814 | * @param subId the id of the subscription. |
| 6815 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6816 | * the operator to attach to. |
| 6817 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6818 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6819 | * normal network selection next time. |
| 6820 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6821 | */ |
| 6822 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6823 | public boolean setNetworkSelectionModeManual( |
| 6824 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6826 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6827 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6828 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6829 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6830 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6831 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6832 | if (!isActiveSubscription(subId)) { |
| 6833 | return false; |
| 6834 | } |
| 6835 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6837 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6839 | if (DBG) { |
| 6840 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6841 | + " operator: " + operatorInfo); |
| 6842 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6843 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6844 | } finally { |
| 6845 | Binder.restoreCallingIdentity(identity); |
| 6846 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6847 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6848 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6849 | * Get the manual network selection |
| 6850 | * |
| 6851 | * @param subId the id of the subscription. |
| 6852 | * |
| 6853 | * @return the previously saved user selected PLMN |
| 6854 | */ |
| 6855 | @Override |
| 6856 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6857 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6858 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6859 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6860 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6861 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6862 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6863 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6864 | final long identity = Binder.clearCallingIdentity(); |
| 6865 | try { |
| 6866 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6867 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6868 | } |
| 6869 | |
| 6870 | final Phone phone = getPhone(subId); |
| 6871 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6872 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6873 | } |
| 6874 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6875 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6876 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6877 | } finally { |
| 6878 | Binder.restoreCallingIdentity(identity); |
| 6879 | } |
| 6880 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6881 | |
| 6882 | /** |
| 6883 | * Scans for available networks. |
| 6884 | */ |
| 6885 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6886 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6887 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6889 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6890 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6891 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6892 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6893 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6894 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6895 | .setCallingPid(Binder.getCallingPid()) |
| 6896 | .setCallingUid(Binder.getCallingUid()) |
| 6897 | .setMethod("getCellNetworkScanResults") |
| 6898 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6899 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6900 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6901 | .build()); |
| 6902 | switch (locationResult) { |
| 6903 | case DENIED_HARD: |
| 6904 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6905 | case DENIED_SOFT: |
| 6906 | return null; |
| 6907 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6908 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6909 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | try { |
| 6911 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6912 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6913 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6914 | } finally { |
| 6915 | Binder.restoreCallingIdentity(identity); |
| 6916 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6917 | } |
| 6918 | |
| 6919 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6920 | * Get the call forwarding info, given the call forwarding reason. |
| 6921 | */ |
| 6922 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6923 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6924 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6925 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6926 | |
| 6927 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6928 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6929 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6930 | long identity = Binder.clearCallingIdentity(); |
| 6931 | try { |
| 6932 | if (DBG) { |
| 6933 | log("getCallForwarding: subId " + subId |
| 6934 | + " callForwardingReason" + callForwardingReason); |
| 6935 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6936 | |
| 6937 | Phone phone = getPhone(subId); |
| 6938 | if (phone == null) { |
| 6939 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6940 | callback.onError( |
| 6941 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6942 | } catch (RemoteException e) { |
| 6943 | // ignore |
| 6944 | } |
| 6945 | return; |
| 6946 | } |
| 6947 | |
| 6948 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6949 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6950 | @Override |
| 6951 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6952 | try { |
| 6953 | callback.onCallForwardingInfoAvailable(info); |
| 6954 | } catch (RemoteException e) { |
| 6955 | // ignore |
| 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | @Override |
| 6960 | public void onError(int error) { |
| 6961 | try { |
| 6962 | callback.onError(error); |
| 6963 | } catch (RemoteException e) { |
| 6964 | // ignore |
| 6965 | } |
| 6966 | } |
| 6967 | }); |
| 6968 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6969 | } finally { |
| 6970 | Binder.restoreCallingIdentity(identity); |
| 6971 | } |
| 6972 | } |
| 6973 | |
| 6974 | /** |
| 6975 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6976 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6977 | */ |
| 6978 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6979 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6980 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6981 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6982 | |
| 6983 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6984 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6985 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6986 | long identity = Binder.clearCallingIdentity(); |
| 6987 | try { |
| 6988 | if (DBG) { |
| 6989 | log("setCallForwarding: subId " + subId |
| 6990 | + " callForwardingInfo" + callForwardingInfo); |
| 6991 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6992 | |
| 6993 | Phone phone = getPhone(subId); |
| 6994 | if (phone == null) { |
| 6995 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6996 | callback.accept( |
| 6997 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6998 | } catch (RemoteException e) { |
| 6999 | // ignore |
| 7000 | } |
| 7001 | return; |
| 7002 | } |
| 7003 | |
| 7004 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7005 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7006 | |
| 7007 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
| 7011 | } |
| 7012 | |
| 7013 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7014 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7015 | */ |
| 7016 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7017 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7018 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7019 | |
| 7020 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7021 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7022 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7023 | long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7025 | Phone phone = getPhone(subId); |
| 7026 | if (phone == null) { |
| 7027 | try { |
| 7028 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7029 | } catch (RemoteException e) { |
| 7030 | // ignore |
| 7031 | } |
| 7032 | return; |
| 7033 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7034 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7035 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7036 | boolean requireUssd = c.getBoolean( |
| 7037 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7038 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7039 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7040 | if (requireUssd) { |
| 7041 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7042 | getSubscriptionCarrierId(subId)); |
| 7043 | String newUssdCommand = ""; |
| 7044 | try { |
| 7045 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7046 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7047 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7048 | } catch (NullPointerException e) { |
| 7049 | loge("Failed to generate USSD number" + e); |
| 7050 | } |
| 7051 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7052 | mMainThreadHandler, callback, carrierXmlParser, |
| 7053 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7054 | final String ussdCommand = newUssdCommand; |
| 7055 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7056 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7057 | }); |
| 7058 | } else { |
| 7059 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7060 | callback::accept); |
| 7061 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7062 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7069 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7070 | */ |
| 7071 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7072 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7073 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7074 | |
| 7075 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7076 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7077 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7078 | long identity = Binder.clearCallingIdentity(); |
| 7079 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7080 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7081 | |
| 7082 | Phone phone = getPhone(subId); |
| 7083 | if (phone == null) { |
| 7084 | try { |
| 7085 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7086 | } catch (RemoteException e) { |
| 7087 | // ignore |
| 7088 | } |
| 7089 | return; |
| 7090 | } |
| 7091 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7092 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7093 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7094 | boolean requireUssd = c.getBoolean( |
| 7095 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7096 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7097 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7098 | if (requireUssd) { |
| 7099 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7100 | getSubscriptionCarrierId(subId)); |
| 7101 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7102 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7103 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7104 | String newUssdCommand = ""; |
| 7105 | try { |
| 7106 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7107 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7108 | .makeCommand(ssAction, null); |
| 7109 | } catch (NullPointerException e) { |
| 7110 | loge("Failed to generate USSD number" + e); |
| 7111 | } |
| 7112 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7113 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7114 | final String ussdCommand = newUssdCommand; |
| 7115 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7116 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7117 | }); |
| 7118 | } else { |
| 7119 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7120 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7121 | |
| 7122 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7123 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
| 7126 | } |
| 7127 | } |
| 7128 | |
| 7129 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7130 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7131 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7132 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7133 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7134 | * location related information which will be sent if the caller already possess |
| 7135 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7136 | * @param request contains the radio access networks with bands/channels to scan |
| 7137 | * @param messenger callback messenger for scan results or errors |
| 7138 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7139 | * @return the id of the requested scan which can be used to stop the scan. |
| 7140 | */ |
| 7141 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7142 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7143 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7144 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7146 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7147 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7148 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7149 | if (!renounceFineLocationAccess) { |
| 7150 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7151 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7152 | .setCallingPackage(callingPackage) |
| 7153 | .setCallingFeatureId(callingFeatureId) |
| 7154 | .setCallingPid(Binder.getCallingPid()) |
| 7155 | .setCallingUid(Binder.getCallingUid()) |
| 7156 | .setMethod("requestNetworkScan") |
| 7157 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7158 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7159 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7160 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7161 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7162 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7163 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7164 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7165 | if (e != null) { |
| 7166 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7167 | throw e; |
| 7168 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7169 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7170 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7171 | } |
| 7172 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7173 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7174 | |
| 7175 | enforceTelephonyFeatureWithException(callingPackage, |
| 7176 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7177 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7178 | int callingUid = Binder.getCallingUid(); |
| 7179 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7183 | renounceFineLocationAccess, request, messenger, binder, |
| 7184 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7185 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7191 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7192 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7193 | boolean hasCarrierPriv; |
| 7194 | final long identity = Binder.clearCallingIdentity(); |
| 7195 | try { |
| 7196 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7197 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7198 | } finally { |
| 7199 | Binder.restoreCallingIdentity(identity); |
| 7200 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7201 | boolean hasNetworkScanPermission = |
| 7202 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7203 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7204 | |
| 7205 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7206 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7207 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7208 | } |
| 7209 | |
| 7210 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7211 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7212 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7213 | return new SecurityException("Specific channels must not be" |
| 7214 | + " scanned without location access."); |
| 7215 | } |
| 7216 | } |
| 7217 | } |
| 7218 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7219 | return null; |
| 7220 | } |
| 7221 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7222 | /** |
| 7223 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7224 | * |
| 7225 | * @param subId id of the subscription |
| 7226 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7227 | */ |
| 7228 | @Override |
| 7229 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7231 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7233 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | final long identity = Binder.clearCallingIdentity(); |
| 7235 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7236 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7237 | } finally { |
| 7238 | Binder.restoreCallingIdentity(identity); |
| 7239 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7243 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7244 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7245 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7246 | */ |
| 7247 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7248 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7249 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7250 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7251 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7253 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7254 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7255 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7258 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7259 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7260 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7261 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7262 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7263 | } finally { |
| 7264 | Binder.restoreCallingIdentity(identity); |
| 7265 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7266 | } |
| 7267 | |
| 7268 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7269 | * Get the allowed network types for certain reason. |
| 7270 | * |
| 7271 | * @param subId the id of the subscription. |
| 7272 | * @param reason the reason the allowed network type change is taking place |
| 7273 | * @return the allowed network types. |
| 7274 | */ |
| 7275 | @Override |
| 7276 | public long getAllowedNetworkTypesForReason(int subId, |
| 7277 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7278 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7279 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7280 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7281 | if (!mApp.getResources().getBoolean( |
| 7282 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7283 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7284 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7285 | "getAllowedNetworkTypesForReason"); |
| 7286 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7287 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7288 | final long identity = Binder.clearCallingIdentity(); |
| 7289 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7290 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7297 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7298 | * @param subId subscription id of the sim card |
| 7299 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7300 | * This can be passed following states |
| 7301 | * <ol> |
| 7302 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7303 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7304 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7305 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7306 | * </ol> |
| 7307 | * @return operation result. |
| 7308 | */ |
| 7309 | @Override |
| 7310 | public int setNrDualConnectivityState(int subId, |
| 7311 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7313 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7314 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7315 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7316 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7317 | } |
| 7318 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7319 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
| 7322 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7323 | nrDualConnectivityState, subId, |
| 7324 | workSource); |
| 7325 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7326 | return result; |
| 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
| 7330 | } |
| 7331 | |
| 7332 | /** |
| 7333 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7334 | * @return true if dual connectivity is enabled else false |
| 7335 | */ |
| 7336 | @Override |
| 7337 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7338 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7339 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7340 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7341 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7342 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7343 | return false; |
| 7344 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7345 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7346 | final long identity = Binder.clearCallingIdentity(); |
| 7347 | try { |
| 7348 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7349 | null, subId, workSource); |
| 7350 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7351 | return isEnabled; |
| 7352 | } finally { |
| 7353 | Binder.restoreCallingIdentity(identity); |
| 7354 | } |
| 7355 | } |
| 7356 | |
| 7357 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7358 | * Set the allowed network types of the device and |
| 7359 | * provide the reason triggering the allowed network change. |
| 7360 | * |
| 7361 | * @param subId the id of the subscription. |
| 7362 | * @param reason the reason the allowed network type change is taking place |
| 7363 | * @param allowedNetworkTypes the allowed network types. |
| 7364 | * @return true on success; false on any failure. |
| 7365 | */ |
| 7366 | @Override |
| 7367 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7368 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7369 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7371 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7372 | // If the caller only has carrier privileges, then they should not be able to override |
| 7373 | // any network types which were set for security reasons. |
| 7374 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7375 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7376 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7377 | throw new SecurityException( |
| 7378 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7379 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7380 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7381 | |
| 7382 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7383 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7384 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7385 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7386 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7387 | return false; |
| 7388 | } |
| 7389 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7390 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7391 | return false; |
| 7392 | } |
| 7393 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7394 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7395 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7396 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7397 | Phone phone = getPhone(subId); |
| 7398 | if (phone == null) { |
| 7399 | return false; |
| 7400 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7401 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7402 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7403 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7404 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7405 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7406 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7407 | final long identity = Binder.clearCallingIdentity(); |
| 7408 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7409 | Boolean success = (Boolean) sendRequest( |
| 7410 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7411 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7412 | |
| 7413 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7414 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7421 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7422 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7423 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7424 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7425 | * @hide |
| 7426 | */ |
| 7427 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7428 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7429 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7430 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7431 | if (!mApp.getResources().getBoolean( |
| 7432 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7433 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7434 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7435 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7438 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7440 | if (phone != null) { |
| 7441 | return phone.hasMatchedTetherApnSetting(); |
| 7442 | } else { |
| 7443 | return false; |
| 7444 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | } finally { |
| 7446 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7447 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7448 | } |
| 7449 | |
| 7450 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7451 | * Get the user enabled state of Mobile Data. |
| 7452 | * |
| 7453 | * TODO: remove and use isUserDataEnabled. |
| 7454 | * This can't be removed now because some vendor codes |
| 7455 | * calls through ITelephony directly while they should |
| 7456 | * use TelephonyManager. |
| 7457 | * |
| 7458 | * @return true on enabled |
| 7459 | */ |
| 7460 | @Override |
| 7461 | public boolean getDataEnabled(int subId) { |
| 7462 | return isUserDataEnabled(subId); |
| 7463 | } |
| 7464 | |
| 7465 | /** |
| 7466 | * Get whether mobile data is enabled per user setting. |
| 7467 | * |
| 7468 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7469 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7470 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7471 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7472 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7473 | * |
| 7474 | * @return {@code true} if data is enabled else {@code false} |
| 7475 | */ |
| 7476 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7477 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7478 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7479 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7480 | try { |
| 7481 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7482 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7483 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7484 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7485 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7486 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7488 | mApp, subId, functionName); |
| 7489 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7490 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7491 | |
| 7492 | final long identity = Binder.clearCallingIdentity(); |
| 7493 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7494 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7496 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7497 | if (phone != null) { |
| 7498 | boolean retVal = phone.isUserDataEnabled(); |
| 7499 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7500 | return retVal; |
| 7501 | } else { |
| 7502 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7503 | return false; |
| 7504 | } |
| 7505 | } finally { |
| 7506 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7507 | } |
| 7508 | } |
| 7509 | |
| 7510 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7511 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7512 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7513 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7514 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7515 | * @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] | 7516 | */ |
| 7517 | @Override |
| 7518 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7519 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7520 | try { |
| 7521 | try { |
| 7522 | mApp.enforceCallingOrSelfPermission( |
| 7523 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7524 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7525 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7526 | try { |
| 7527 | mApp.enforceCallingOrSelfPermission( |
| 7528 | android.Manifest.permission.READ_PHONE_STATE, |
| 7529 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7530 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7531 | mApp.enforceCallingOrSelfPermission( |
| 7532 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7533 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7534 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7535 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7536 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7537 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7539 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7540 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | final long identity = Binder.clearCallingIdentity(); |
| 7543 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7544 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7546 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7547 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7548 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7549 | return retVal; |
| 7550 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7551 | if (DBG) { |
| 7552 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7553 | + subId + " retVal=false"); |
| 7554 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7555 | return false; |
| 7556 | } |
| 7557 | } finally { |
| 7558 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7559 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7560 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7561 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7562 | /** |
| 7563 | * Check if data is enabled for a specific reason |
| 7564 | * @param subId Subscription index |
| 7565 | * @param reason the reason the data enable change is taking place |
| 7566 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7567 | */ |
| 7568 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7569 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7570 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7571 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7572 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7573 | try { |
| 7574 | mApp.enforceCallingOrSelfPermission( |
| 7575 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7576 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7577 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7578 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7579 | functionName); |
| 7580 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7581 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7582 | try { |
| 7583 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7584 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7585 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7587 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7588 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7589 | } |
| 7590 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7591 | if (!mApp.getResources().getBoolean( |
| 7592 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7593 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7594 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7595 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7596 | |
| 7597 | final long identity = Binder.clearCallingIdentity(); |
| 7598 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7599 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7600 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7601 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7602 | + " reason=" + reason); |
| 7603 | } |
| 7604 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7605 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7606 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7607 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7608 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7609 | return retVal; |
| 7610 | } else { |
| 7611 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7612 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7613 | + subId + " retVal=false"); |
| 7614 | } |
| 7615 | return false; |
| 7616 | } |
| 7617 | } finally { |
| 7618 | Binder.restoreCallingIdentity(identity); |
| 7619 | } |
| 7620 | } |
| 7621 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7622 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7623 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7625 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7626 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7627 | // No permission needed; this only lets the caller inspect their own status. |
| 7628 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7629 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7630 | |
| 7631 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7632 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7633 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7634 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7635 | if (!mApp.getResources().getBoolean( |
| 7636 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7637 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7638 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7639 | "getCarrierPrivilegeStatusForUid"); |
| 7640 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7641 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7642 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7643 | } |
| 7644 | |
| 7645 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7646 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7647 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7648 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7649 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7650 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7651 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7652 | if (cpt == null) { |
| 7653 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7654 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7655 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7656 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7657 | } |
| 7658 | |
| 7659 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7660 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7661 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7662 | |
| 7663 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7664 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7665 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7666 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7667 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7668 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7669 | Phone phone = getPhone(subId); |
| 7670 | if (phone == null) { |
| 7671 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7672 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7673 | } |
| 7674 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7675 | if (cpt == null) { |
| 7676 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7677 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7678 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7679 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | @Override |
| 7683 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7684 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7685 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7686 | if (!mApp.getResources().getBoolean( |
| 7687 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7688 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7689 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7690 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7691 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7692 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7693 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7694 | } |
| 7695 | |
| 7696 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7697 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7698 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7699 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7700 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7701 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7702 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7703 | if (phone == null) { |
| 7704 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7705 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7706 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7707 | if (cpt == null) { |
| 7708 | continue; |
| 7709 | } |
| 7710 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7711 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7712 | break; |
| 7713 | } |
| 7714 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7715 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7716 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7717 | |
| 7718 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7719 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7720 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7721 | |
| 7722 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7723 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7724 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7725 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7726 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7727 | if (phone == null) { |
| 7728 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7729 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7730 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7731 | if (cpt == null) { |
| 7732 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7733 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7734 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7735 | } |
| 7736 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7737 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7738 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7739 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Yan Yan | 965c84f | 2024-09-24 18:14:17 -0700 | [diff] [blame] | 7740 | |
| 7741 | enforceTelephonyFeatureWithException( |
| 7742 | getCurrentPackageName(), |
| 7743 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7744 | "getPackagesWithCarrierPrivileges"); |
| 7745 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7746 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7747 | if (phone == null) { |
| 7748 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7749 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7750 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7751 | if (cpt == null) { |
| 7752 | return Collections.emptyList(); |
| 7753 | } |
| 7754 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7755 | } |
| 7756 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7757 | @Override |
| 7758 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7759 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7760 | |
| 7761 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7762 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7763 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7764 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7765 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7766 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7767 | try { |
| 7768 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7769 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7770 | } |
| 7771 | } finally { |
| 7772 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7773 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7774 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7775 | } |
| 7776 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7777 | @Override |
| 7778 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7779 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7780 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7781 | if (!mApp.getResources().getBoolean( |
| 7782 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7783 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7784 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7785 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7786 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7787 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7788 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7789 | if (phone == null) { |
| 7790 | return null; |
| 7791 | } |
| 7792 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7793 | if (cpt == null) { |
| 7794 | return null; |
| 7795 | } |
| 7796 | return cpt.getCarrierServicePackageName(); |
| 7797 | } |
| 7798 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7799 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7800 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7801 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7802 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7803 | return null; |
| 7804 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7805 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7806 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7807 | return null; |
| 7808 | } |
| 7809 | return iccId; |
| 7810 | } |
| 7811 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7812 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7813 | public void setCallComposerStatus(int subId, int status) { |
| 7814 | enforceModifyPermission(); |
| 7815 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7816 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7817 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7818 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7819 | final long identity = Binder.clearCallingIdentity(); |
| 7820 | try { |
| 7821 | Phone phone = getPhone(subId); |
| 7822 | if (phone != null) { |
| 7823 | Phone defaultPhone = phone.getImsPhone(); |
| 7824 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7825 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7826 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7827 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7828 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7829 | } |
| 7830 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7831 | } catch (ImsException e) { |
| 7832 | throw new ServiceSpecificException(e.getCode()); |
| 7833 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7834 | Binder.restoreCallingIdentity(identity); |
| 7835 | } |
| 7836 | } |
| 7837 | |
| 7838 | @Override |
| 7839 | public int getCallComposerStatus(int subId) { |
| 7840 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7841 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7842 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7843 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7844 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7845 | final long identity = Binder.clearCallingIdentity(); |
| 7846 | try { |
| 7847 | Phone phone = getPhone(subId); |
| 7848 | if (phone != null) { |
| 7849 | Phone defaultPhone = phone.getImsPhone(); |
| 7850 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7851 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7852 | return imsPhone.getCallComposerStatus(); |
| 7853 | } |
| 7854 | } |
| 7855 | } finally { |
| 7856 | Binder.restoreCallingIdentity(identity); |
| 7857 | } |
| 7858 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7859 | } |
| 7860 | |
| 7861 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7862 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7863 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7864 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7865 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7866 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7867 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7868 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7869 | "setLine1NumberForDisplayForSubscriber"); |
| 7870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7871 | final long identity = Binder.clearCallingIdentity(); |
| 7872 | try { |
| 7873 | final String iccId = getIccId(subId); |
| 7874 | final Phone phone = getPhone(subId); |
| 7875 | if (phone == null) { |
| 7876 | return false; |
| 7877 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7878 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7879 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7880 | return false; |
| 7881 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7882 | final String subscriberId = phone.getSubscriberId(); |
| 7883 | |
| 7884 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7885 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7886 | + subscriberId + " to " + number); |
| 7887 | } |
| 7888 | |
| 7889 | if (TextUtils.isEmpty(iccId)) { |
| 7890 | return false; |
| 7891 | } |
| 7892 | |
| 7893 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7894 | |
| 7895 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7896 | if (alphaTag == null) { |
| 7897 | editor.remove(alphaTagPrefKey); |
| 7898 | } else { |
| 7899 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7900 | } |
| 7901 | |
| 7902 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7903 | // track all merged IMSIs based on line number |
| 7904 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7905 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7906 | if (number == null) { |
| 7907 | editor.remove(numberPrefKey); |
| 7908 | editor.remove(subscriberPrefKey); |
| 7909 | } else { |
| 7910 | editor.putString(numberPrefKey, number); |
| 7911 | editor.putString(subscriberPrefKey, subscriberId); |
| 7912 | } |
| 7913 | |
| 7914 | editor.commit(); |
| 7915 | return true; |
| 7916 | } finally { |
| 7917 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7918 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7919 | } |
| 7920 | |
| 7921 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7922 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7923 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7924 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7926 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7927 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7928 | return null; |
| 7929 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7930 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7931 | if (!mApp.getResources().getBoolean( |
| 7932 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7933 | enforceTelephonyFeatureWithException(callingPackage, |
| 7934 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7935 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7937 | final long identity = Binder.clearCallingIdentity(); |
| 7938 | try { |
| 7939 | String iccId = getIccId(subId); |
| 7940 | if (iccId != null) { |
| 7941 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7942 | if (DBG_MERGE) { |
| 7943 | log("getLine1NumberForDisplay returning " |
| 7944 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7945 | } |
| 7946 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7948 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7949 | return null; |
| 7950 | } finally { |
| 7951 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7952 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7956 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7957 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7958 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7959 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7960 | return null; |
| 7961 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7963 | final long identity = Binder.clearCallingIdentity(); |
| 7964 | try { |
| 7965 | String iccId = getIccId(subId); |
| 7966 | if (iccId != null) { |
| 7967 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7968 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7969 | } |
| 7970 | return null; |
| 7971 | } finally { |
| 7972 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7973 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7974 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7975 | |
| 7976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7977 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7978 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7979 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7980 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7981 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7982 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7983 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7984 | return null; |
| 7985 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7986 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7987 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7988 | // the process, where TelephonyManager was instantiated. |
| 7989 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7990 | final long identity = Binder.clearCallingIdentity(); |
| 7991 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7992 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7994 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7995 | |
| 7996 | // Figure out what subscribers are currently active |
| 7997 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7998 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7999 | // Only consider subs which match the current subId |
| 8000 | // This logic can be simplified. See b/131189269 for progress. |
| 8001 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8002 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8003 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8004 | |
| 8005 | // First pass, find a number override for an active subscriber |
| 8006 | String mergeNumber = null; |
| 8007 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8008 | for (String key : prefs.keySet()) { |
| 8009 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8010 | final String subscriberId = (String) prefs.get(key); |
| 8011 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8012 | final String iccId = key.substring( |
| 8013 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8014 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8015 | mergeNumber = (String) prefs.get(numberKey); |
| 8016 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8017 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | + " for active subscriber " + subscriberId); |
| 8019 | } |
| 8020 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8021 | break; |
| 8022 | } |
| 8023 | } |
| 8024 | } |
| 8025 | } |
| 8026 | |
| 8027 | // Shortcut when no active merged subscribers |
| 8028 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8029 | return null; |
| 8030 | } |
| 8031 | |
| 8032 | // Second pass, find all subscribers under that line override |
| 8033 | final ArraySet<String> result = new ArraySet<>(); |
| 8034 | for (String key : prefs.keySet()) { |
| 8035 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8036 | final String number = (String) prefs.get(key); |
| 8037 | if (mergeNumber.equals(number)) { |
| 8038 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8039 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8040 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8041 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8042 | result.add(subscriberId); |
| 8043 | } |
| 8044 | } |
| 8045 | } |
| 8046 | } |
| 8047 | |
| 8048 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8049 | Arrays.sort(resultArray); |
| 8050 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8051 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8052 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8053 | } |
| 8054 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8055 | } finally { |
| 8056 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8057 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8061 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8062 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8063 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8064 | enforceTelephonyFeatureWithException(callingPackage, |
| 8065 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8066 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8067 | final long identity = Binder.clearCallingIdentity(); |
| 8068 | try { |
| 8069 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8070 | TelephonyManager.class); |
| 8071 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8072 | if (subscriberId == null) { |
| 8073 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8074 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8075 | + subId); |
| 8076 | } |
| 8077 | return null; |
| 8078 | } |
| 8079 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8080 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8081 | .getSubscriptionInfo(subId); |
| 8082 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8083 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8084 | if (groupUuid == null) { |
| 8085 | return new String[]{subscriberId}; |
| 8086 | } |
| 8087 | |
| 8088 | // Get all subscriberIds from the group. |
| 8089 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8090 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8091 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8092 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8093 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8094 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8095 | if (subscriberId != null) { |
| 8096 | mergedSubscriberIds.add(subscriberId); |
| 8097 | } |
| 8098 | } |
| 8099 | |
| 8100 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8101 | } finally { |
| 8102 | Binder.restoreCallingIdentity(identity); |
| 8103 | |
| 8104 | } |
| 8105 | } |
| 8106 | |
| 8107 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8108 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8109 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8110 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8111 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8112 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8113 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8115 | final long identity = Binder.clearCallingIdentity(); |
| 8116 | try { |
| 8117 | final Phone phone = getPhone(subId); |
| 8118 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8119 | } finally { |
| 8120 | Binder.restoreCallingIdentity(identity); |
| 8121 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8122 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8123 | |
| 8124 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8125 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8126 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8127 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8128 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8129 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8130 | |
| 8131 | final long identity = Binder.clearCallingIdentity(); |
| 8132 | try { |
| 8133 | final Phone phone = getPhone(subId); |
| 8134 | if (phone == null) { |
| 8135 | return false; |
| 8136 | } |
| 8137 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8138 | cdmaNonRoamingList); |
| 8139 | } finally { |
| 8140 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8141 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8142 | } |
| 8143 | |
| 8144 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8145 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8146 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8147 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8148 | if (phone == null) { |
| 8149 | return raf; |
| 8150 | } |
| 8151 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8152 | try { |
| 8153 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8154 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8155 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8156 | } catch (SecurityException e) { |
| 8157 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8158 | throw e; |
| 8159 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8160 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8161 | if (!mApp.getResources().getBoolean( |
| 8162 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8163 | enforceTelephonyFeatureWithException(callingPackage, |
| 8164 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8165 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8167 | final long identity = Binder.clearCallingIdentity(); |
| 8168 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8169 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8170 | } finally { |
| 8171 | Binder.restoreCallingIdentity(identity); |
| 8172 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8173 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8174 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8175 | |
| 8176 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8177 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8178 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8179 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8180 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8181 | enforceTelephonyFeatureWithException(callingPackage, |
| 8182 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8183 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8184 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8185 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8186 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8187 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8188 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8189 | throw new SecurityException("App must be the dialer role holder to" |
| 8190 | + " upload a call composer pic"); |
| 8191 | } |
| 8192 | |
| 8193 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8194 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8195 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8196 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8197 | boolean readUntilEnd = false; |
| 8198 | int totalBytesRead = 0; |
| 8199 | byte[] buffer = new byte[16 * 1024]; |
| 8200 | while (true) { |
| 8201 | int numRead; |
| 8202 | try { |
| 8203 | numRead = input.read(buffer); |
| 8204 | } catch (IOException e) { |
| 8205 | try { |
| 8206 | fd.checkError(); |
| 8207 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8208 | null); |
| 8209 | } catch (IOException e1) { |
| 8210 | // This means that the other side closed explicitly with an error. If this |
| 8211 | // happens, log and ignore. |
| 8212 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8213 | } |
| 8214 | break; |
| 8215 | } |
| 8216 | if (numRead == -1) { |
| 8217 | readUntilEnd = true; |
| 8218 | break; |
| 8219 | } |
| 8220 | totalBytesRead += numRead; |
| 8221 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8222 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8223 | try { |
| 8224 | input.close(); |
| 8225 | } catch (IOException e) { |
| 8226 | // ignore |
| 8227 | } |
| 8228 | break; |
| 8229 | } |
| 8230 | output.write(buffer, 0, numRead); |
| 8231 | } |
| 8232 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8233 | // close is above, where the picture size is too big. |
| 8234 | |
| 8235 | try { |
| 8236 | fd.checkError(); |
| 8237 | } catch (IOException e) { |
| 8238 | loge("Remote end for call composer closed with an error: " + e); |
| 8239 | return; |
| 8240 | } |
| 8241 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8242 | if (!readUntilEnd) { |
| 8243 | loge("Did not finish reading entire image; aborting"); |
| 8244 | return; |
| 8245 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8246 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8247 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8248 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8249 | new CallComposerPictureTransfer.Factory() {}, |
| 8250 | imageData, |
| 8251 | (result) -> { |
| 8252 | if (result.first != null) { |
| 8253 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8254 | Bundle outputResult = new Bundle(); |
| 8255 | outputResult.putParcelable( |
| 8256 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8257 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8258 | outputResult); |
| 8259 | } else { |
| 8260 | callback.send(result.second, null); |
| 8261 | } |
| 8262 | } |
| 8263 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8264 | }); |
| 8265 | } |
| 8266 | |
| 8267 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8268 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8269 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8270 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8271 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8272 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8273 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8277 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8278 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
| 8281 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8285 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8286 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8287 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8288 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8289 | return false; |
| 8290 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8291 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8292 | enforceTelephonyFeatureWithException(callingPackage, |
| 8293 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8294 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8295 | final long identity = Binder.clearCallingIdentity(); |
| 8296 | try { |
| 8297 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8298 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8299 | // In the long run, we may instead need to check if there exists a connection service |
| 8300 | // which can support video calling. |
| 8301 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8302 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | return imsManager.isVtEnabledByPlatform() |
| 8304 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8305 | && imsManager.isVtEnabledByUser(); |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8309 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8310 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8311 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8312 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8313 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8314 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8315 | mApp, subId, callingPackage, callingFeatureId, |
| 8316 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | return false; |
| 8318 | } |
| 8319 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8320 | enforceTelephonyFeatureWithException(callingPackage, |
| 8321 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8322 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8323 | final long identity = Binder.clearCallingIdentity(); |
| 8324 | try { |
| 8325 | CarrierConfigManager configManager = |
| 8326 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8327 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8328 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8329 | } finally { |
| 8330 | Binder.restoreCallingIdentity(identity); |
| 8331 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8335 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8337 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | return false; |
| 8339 | } |
| 8340 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8341 | enforceTelephonyFeatureWithException(callingPackage, |
| 8342 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | final long identity = Binder.clearCallingIdentity(); |
| 8345 | try { |
| 8346 | CarrierConfigManager configManager = |
| 8347 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8348 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8349 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8350 | } finally { |
| 8351 | Binder.restoreCallingIdentity(identity); |
| 8352 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8353 | } |
| 8354 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8355 | @Override |
| 8356 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8357 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8358 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8359 | } |
| 8360 | |
| 8361 | @Override |
| 8362 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8363 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8364 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8365 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8366 | final long identity = Binder.clearCallingIdentity(); |
| 8367 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8368 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8369 | } finally { |
| 8370 | Binder.restoreCallingIdentity(identity); |
| 8371 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8372 | } |
| 8373 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8374 | /** |
| 8375 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8376 | * support for the feature and device firmware support. |
| 8377 | * |
| 8378 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8379 | */ |
| 8380 | @Override |
| 8381 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8382 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8383 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8384 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8386 | final Phone phone = getPhone(subscriptionId); |
| 8387 | if (phone == null) { |
| 8388 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8389 | return false; |
| 8390 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8392 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8393 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8394 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8395 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8396 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8397 | return isCarrierSupported && isDeviceSupported; |
| 8398 | } finally { |
| 8399 | Binder.restoreCallingIdentity(identity); |
| 8400 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8401 | } |
| 8402 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8403 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8404 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8405 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8406 | * 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] | 8407 | */ |
| 8408 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8411 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8412 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8413 | return false; |
| 8414 | } |
| 8415 | } |
| 8416 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8417 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8418 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8419 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8420 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8421 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8422 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | } finally { |
| 8424 | Binder.restoreCallingIdentity(identity); |
| 8425 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8426 | } |
| 8427 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8428 | @Deprecated |
| 8429 | @Override |
| 8430 | public String getDeviceId(String callingPackage) { |
| 8431 | return getDeviceIdWithFeature(callingPackage, null); |
| 8432 | } |
| 8433 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8434 | /** |
| 8435 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8436 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8437 | * |
| 8438 | * <p>Requires Permission: |
| 8439 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8440 | */ |
| 8441 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8442 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8443 | try { |
| 8444 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8445 | } catch (SecurityException se) { |
| 8446 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8447 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8448 | + Binder.getCallingUid()); |
| 8449 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8450 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8451 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8452 | return null; |
| 8453 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8454 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8455 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8456 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8457 | return null; |
| 8458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8459 | |
| 8460 | final long identity = Binder.clearCallingIdentity(); |
| 8461 | try { |
| 8462 | return phone.getDeviceId(); |
| 8463 | } finally { |
| 8464 | Binder.restoreCallingIdentity(identity); |
| 8465 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8466 | } |
| 8467 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8468 | /** |
| 8469 | * {@hide} |
| 8470 | * Returns the IMS Registration Status on a particular subid |
| 8471 | * |
| 8472 | * @param subId |
| 8473 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8474 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8475 | Phone phone = getPhone(subId); |
| 8476 | if (phone != null) { |
| 8477 | return phone.isImsRegistered(); |
| 8478 | } else { |
| 8479 | return false; |
| 8480 | } |
| 8481 | } |
| 8482 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8483 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8484 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8485 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8487 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8488 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8489 | } |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
| 8495 | } |
| 8496 | } |
| 8497 | |
| 8498 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8499 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8500 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8501 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8502 | mApp, |
| 8503 | subscriptionId, |
| 8504 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8505 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8506 | |
| 8507 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8508 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8509 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8510 | final long identity = Binder.clearCallingIdentity(); |
| 8511 | try { |
| 8512 | Phone phone = getPhone(subscriptionId); |
| 8513 | if (phone == null) { |
| 8514 | return null; |
| 8515 | } |
| 8516 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(identity); |
| 8519 | } |
| 8520 | } |
| 8521 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8522 | /** |
| 8523 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8524 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8525 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
| 8528 | Phone phone = getPhone(subId); |
| 8529 | if (phone != null) { |
| 8530 | return phone.isWifiCallingEnabled(); |
| 8531 | } else { |
| 8532 | return false; |
| 8533 | } |
| 8534 | } finally { |
| 8535 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8536 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8537 | } |
| 8538 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8539 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8540 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8541 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8542 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8543 | final long identity = Binder.clearCallingIdentity(); |
| 8544 | try { |
| 8545 | Phone phone = getPhone(subId); |
| 8546 | if (phone != null) { |
| 8547 | return phone.isVideoEnabled(); |
| 8548 | } else { |
| 8549 | return false; |
| 8550 | } |
| 8551 | } finally { |
| 8552 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8553 | } |
| 8554 | } |
| 8555 | |
| 8556 | /** |
| 8557 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8558 | * defined in {@link ImsRegistrationImplBase}. |
| 8559 | */ |
| 8560 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8561 | final long identity = Binder.clearCallingIdentity(); |
| 8562 | try { |
| 8563 | Phone phone = getPhone(subId); |
| 8564 | if (phone != null) { |
| 8565 | return phone.getImsRegistrationTech(); |
| 8566 | } else { |
| 8567 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8568 | } |
| 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8571 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8572 | } |
| 8573 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8574 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8575 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8576 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8577 | |
| 8578 | enforceTelephonyFeatureWithException(callingPackage, |
| 8579 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8580 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8581 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8582 | return; |
| 8583 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8584 | Phone defaultPhone = getDefaultPhone(); |
| 8585 | if (defaultPhone != null) { |
| 8586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8587 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8588 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8589 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8590 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8591 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8592 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8593 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8594 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8595 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8596 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8597 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8598 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8599 | setDataRoamingEnabled(subId, phone == null ? false |
| 8600 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8601 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8602 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8603 | // There has been issues when Sms raw table somehow stores orphan |
| 8604 | // fragments. They lead to garbled message when new fragments come |
| 8605 | // in and combined with those stale ones. In case this happens again, |
| 8606 | // user can reset all network settings which will clean up this table. |
| 8607 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8608 | // Clean up IMS settings as well here. |
| 8609 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8610 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8611 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8612 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8613 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8614 | if (defaultPhone == null) { |
| 8615 | return; |
| 8616 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8617 | // Erase modem config if erase modem on network setting is enabled. |
| 8618 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8619 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8620 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8621 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8622 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8623 | |
| 8624 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8625 | } finally { |
| 8626 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8627 | } |
| 8628 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8629 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8630 | @VisibleForTesting |
| 8631 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8632 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8633 | return; |
| 8634 | } |
| 8635 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8636 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8637 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8638 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8639 | "user=" + defaultNetworkType); |
| 8640 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8641 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8642 | defaultNetworkType, null); |
| 8643 | } |
| 8644 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8645 | private void cleanUpSmsRawTable(Context context) { |
| 8646 | ContentResolver resolver = context.getContentResolver(); |
| 8647 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8648 | resolver.delete(uri, null, null); |
| 8649 | } |
| 8650 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8651 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8652 | public String getSimLocaleForSubscriber(int subId) { |
| 8653 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8654 | |
| 8655 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8656 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8657 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8658 | final Phone phone = getPhone(subId); |
| 8659 | if (phone == null) { |
| 8660 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8661 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8662 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8663 | final long identity = Binder.clearCallingIdentity(); |
| 8664 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8665 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8666 | phone.getContext().getOpPackageName(), |
| 8667 | phone.getContext().getAttributionTag()); |
| 8668 | if (info == null) { |
| 8669 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8670 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8672 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8673 | // preferences (EF-PL and EF-LI)... |
| 8674 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8675 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8676 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8677 | if (localeFromDefaultSim != null) { |
| 8678 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8679 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8680 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8681 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8682 | } else { |
| 8683 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8684 | } |
| 8685 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8686 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8687 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8688 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8689 | // the SIM and carrier preferences does not include a country we add the country |
| 8690 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8691 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8692 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8693 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8694 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8695 | } |
| 8696 | |
| 8697 | if (DBG) log("No locale found - returning null"); |
| 8698 | return null; |
| 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
| 8701 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8702 | } |
| 8703 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8704 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8705 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8706 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8707 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8708 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8709 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8710 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8711 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8712 | return localeTag; |
| 8713 | } |
| 8714 | } |
| 8715 | return inputLocale.toLanguageTag(); |
| 8716 | } |
| 8717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8718 | /** |
| 8719 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8720 | */ |
| 8721 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8722 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8723 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8724 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8725 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8726 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8727 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8728 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8729 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8730 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8731 | * representing the state of the modem. |
| 8732 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8733 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8734 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8735 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8736 | */ |
| 8737 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8738 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8739 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8740 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8741 | if (!mApp.getResources().getBoolean( |
| 8742 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8743 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8744 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8745 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8746 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8747 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8748 | |
| 8749 | final long identity = Binder.clearCallingIdentity(); |
| 8750 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8751 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8752 | } finally { |
| 8753 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8754 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8755 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8756 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8757 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8758 | // less than total activity duration. |
| 8759 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8760 | if (info == null) { |
| 8761 | return false; |
| 8762 | } |
| 8763 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8764 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8765 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8766 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8767 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8768 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8769 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8770 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8771 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8772 | } |
| 8773 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8774 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8775 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8776 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8777 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8778 | |
| 8779 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8780 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8781 | } |
| 8782 | |
| 8783 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8784 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8785 | rat, |
| 8786 | freq, |
| 8787 | info.getReceiveTimeMillis(rat, freq) |
| 8788 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8789 | } |
| 8790 | |
| 8791 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8792 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8793 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8794 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8795 | |
| 8796 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8797 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8798 | } |
| 8799 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8800 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8801 | rat, |
| 8802 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8803 | } |
| 8804 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8805 | /** |
| 8806 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8807 | * @param info recent ModemActivityInfo |
| 8808 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8809 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8810 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8811 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8812 | boolean matched; |
| 8813 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8814 | matched = false; |
| 8815 | int rat = info.getSpecificInfoRat(i); |
| 8816 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8817 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8818 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8819 | //if it already exists |
| 8820 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8821 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8822 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8823 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8824 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8825 | updateLastModemActivityInfo(info, rat, freq); |
| 8826 | matched = true; |
| 8827 | } |
| 8828 | } else { |
| 8829 | updateLastModemActivityInfo(info, rat); |
| 8830 | matched = true; |
| 8831 | } |
| 8832 | } |
| 8833 | } |
| 8834 | |
| 8835 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8836 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8837 | new ActivityStatsTechSpecificInfo( |
| 8838 | rat, |
| 8839 | freq, |
| 8840 | info.getTransmitTimeMillis(rat, freq), |
| 8841 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8842 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8843 | } |
| 8844 | } |
| 8845 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8846 | mLastModemActivitySpecificInfo = |
| 8847 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8848 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8849 | |
| 8850 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8851 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8852 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8853 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8854 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8855 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8856 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8857 | |
| 8858 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8859 | new ModemActivityInfo( |
| 8860 | mLastModemActivityInfo.getTimestampMillis(), |
| 8861 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8862 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8863 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8867 | ActivityStatsTechSpecificInfo[] info) { |
| 8868 | int infoSize = info.length; |
| 8869 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8870 | for (int i = 0; i < infoSize; i++) { |
| 8871 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8872 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8873 | info[i].getTransmitTimeMillis(), |
| 8874 | (int) info[i].getReceiveTimeMillis()); |
| 8875 | } |
| 8876 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8877 | } |
| 8878 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8879 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8880 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8881 | */ |
| 8882 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8883 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8884 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8885 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8886 | if (phone == null) { |
| 8887 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8888 | return null; |
| 8889 | } |
| 8890 | |
| 8891 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8893 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8894 | return null; |
| 8895 | } |
| 8896 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8897 | enforceTelephonyFeatureWithException(callingPackage, |
| 8898 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8899 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8900 | boolean hasFinePermission = false; |
| 8901 | boolean hasCoarsePermission = false; |
| 8902 | if (!renounceFineLocationAccess) { |
| 8903 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8904 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8905 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8906 | .setCallingPackage(callingPackage) |
| 8907 | .setCallingFeatureId(callingFeatureId) |
| 8908 | .setCallingPid(Binder.getCallingPid()) |
| 8909 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8910 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8911 | .setLogAsInfo(true) |
| 8912 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8913 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8914 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8915 | .build()); |
| 8916 | hasFinePermission = |
| 8917 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8918 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8919 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8920 | if (!renounceCoarseLocationAccess) { |
| 8921 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8922 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8923 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8924 | .setCallingPackage(callingPackage) |
| 8925 | .setCallingFeatureId(callingFeatureId) |
| 8926 | .setCallingPid(Binder.getCallingPid()) |
| 8927 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8928 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8929 | .setLogAsInfo(true) |
| 8930 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8931 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8932 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8933 | .build()); |
| 8934 | hasCoarsePermission = |
| 8935 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8936 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8937 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8938 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8939 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8940 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8941 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8942 | if (subInfo != null && !subInfo.isActive()) { |
| 8943 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8944 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8945 | } |
| 8946 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8947 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8948 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8949 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8950 | |
| 8951 | // Scrub out the location info in ServiceState depending on what level of access |
| 8952 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8953 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8954 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8955 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8956 | } finally { |
| 8957 | Binder.restoreCallingIdentity(identity); |
| 8958 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8959 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8960 | |
| 8961 | /** |
| 8962 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8963 | * |
| 8964 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8965 | * voicemail ringtone. |
| 8966 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8967 | * PhoneAccount. |
| 8968 | */ |
| 8969 | @Override |
| 8970 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8971 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8972 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8974 | final long identity = Binder.clearCallingIdentity(); |
| 8975 | try { |
| 8976 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8977 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8978 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8981 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8982 | } finally { |
| 8983 | Binder.restoreCallingIdentity(identity); |
| 8984 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8985 | } |
| 8986 | |
| 8987 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8988 | * Sets the per-account voicemail ringtone. |
| 8989 | * |
| 8990 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8991 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8992 | * |
| 8993 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8994 | * voicemail ringtone. |
| 8995 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8996 | * PhoneAccount. |
| 8997 | */ |
| 8998 | @Override |
| 8999 | public void setVoicemailRingtoneUri(String callingPackage, |
| 9000 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9001 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9002 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9003 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9004 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9006 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9007 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9009 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9010 | enforceTelephonyFeatureWithException(callingPackage, |
| 9011 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9013 | final long identity = Binder.clearCallingIdentity(); |
| 9014 | try { |
| 9015 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9016 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9017 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9018 | } |
| 9019 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9022 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9023 | } |
| 9024 | |
| 9025 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9026 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9027 | * |
| 9028 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9029 | * voicemail vibration setting. |
| 9030 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9031 | */ |
| 9032 | @Override |
| 9033 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9034 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9035 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9036 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9037 | final long identity = Binder.clearCallingIdentity(); |
| 9038 | try { |
| 9039 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9040 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9041 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9042 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9043 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9044 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9045 | } finally { |
| 9046 | Binder.restoreCallingIdentity(identity); |
| 9047 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9048 | } |
| 9049 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9050 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9051 | * Sets the per-account voicemail vibration. |
| 9052 | * |
| 9053 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9054 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9055 | * |
| 9056 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9057 | * voicemail vibration setting. |
| 9058 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9059 | * specific PhoneAccount. |
| 9060 | */ |
| 9061 | @Override |
| 9062 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9063 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9064 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9065 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9066 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9067 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9069 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9070 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9071 | } |
| 9072 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9073 | enforceTelephonyFeatureWithException(callingPackage, |
| 9074 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9075 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9076 | final long identity = Binder.clearCallingIdentity(); |
| 9077 | try { |
| 9078 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9079 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9080 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9081 | } |
| 9082 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9083 | } finally { |
| 9084 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9085 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9089 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9090 | * |
| 9091 | * @throws SecurityException if the caller does not have the required permission |
| 9092 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9093 | @VisibleForTesting |
| 9094 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9095 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9096 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9097 | } |
| 9098 | |
| 9099 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9100 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9101 | * permission. |
| 9102 | * |
| 9103 | * @throws SecurityException if the caller does not have the required permission |
| 9104 | */ |
| 9105 | private void enforceSendSmsPermission() { |
| 9106 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9107 | } |
| 9108 | |
| 9109 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9110 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9111 | * users permission. |
| 9112 | * |
| 9113 | * @throws SecurityException if the caller does not have the required permission |
| 9114 | */ |
| 9115 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9116 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9117 | } |
| 9118 | |
| 9119 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9120 | * Make sure called from the package in charge of visual voicemail. |
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 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9123 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9124 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9125 | final long identity = Binder.clearCallingIdentity(); |
| 9126 | try { |
| 9127 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9128 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9129 | if (componentName == null) { |
| 9130 | throw new SecurityException( |
| 9131 | "Caller not current active visual voicemail package[null]"); |
| 9132 | } |
| 9133 | String vvmPackage = componentName.getPackageName(); |
| 9134 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9135 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9136 | } |
| 9137 | } finally { |
| 9138 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9139 | } |
| 9140 | } |
| 9141 | |
| 9142 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9143 | * Return the application ID for the app type. |
| 9144 | * |
| 9145 | * @param subId the subscription ID that this request applies to. |
| 9146 | * @param appType the uicc app type. |
| 9147 | * @return Application ID for specificied app type, or null if no uicc. |
| 9148 | */ |
| 9149 | @Override |
| 9150 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9151 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9152 | |
| 9153 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9154 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9155 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9156 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9157 | |
| 9158 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9159 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9160 | if (phone == null) { |
| 9161 | return null; |
| 9162 | } |
| 9163 | String aid = null; |
| 9164 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9165 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9166 | .getApplicationByType(appType).getAid(); |
| 9167 | } catch (Exception e) { |
| 9168 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9169 | } |
| 9170 | return aid; |
| 9171 | } finally { |
| 9172 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9173 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9174 | } |
| 9175 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9176 | /** |
| 9177 | * Return the Electronic Serial Number. |
| 9178 | * |
| 9179 | * @param subId the subscription ID that this request applies to. |
| 9180 | * @return ESN or null if error. |
| 9181 | */ |
| 9182 | @Override |
| 9183 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9184 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9185 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9186 | |
| 9187 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9188 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9189 | if (phone == null) { |
| 9190 | return null; |
| 9191 | } |
| 9192 | String esn = null; |
| 9193 | try { |
| 9194 | esn = phone.getEsn(); |
| 9195 | } catch (Exception e) { |
| 9196 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9197 | } |
| 9198 | return esn; |
| 9199 | } finally { |
| 9200 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9201 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9202 | } |
| 9203 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9204 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9205 | * Return the Preferred Roaming List Version. |
| 9206 | * |
| 9207 | * @param subId the subscription ID that this request applies to. |
| 9208 | * @return PRLVersion or null if error. |
| 9209 | */ |
| 9210 | @Override |
| 9211 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9212 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9213 | |
| 9214 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9215 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9216 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9217 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9218 | |
| 9219 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9220 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9221 | if (phone == null) { |
| 9222 | return null; |
| 9223 | } |
| 9224 | String cdmaPrlVersion = null; |
| 9225 | try { |
| 9226 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9227 | } catch (Exception e) { |
| 9228 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9229 | } |
| 9230 | return cdmaPrlVersion; |
| 9231 | } finally { |
| 9232 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9233 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9234 | } |
| 9235 | |
| 9236 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9237 | * Get snapshot of Telephony histograms |
| 9238 | * @return List of Telephony histograms |
| 9239 | * @hide |
| 9240 | */ |
| 9241 | @Override |
| 9242 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9244 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9245 | |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
| 9248 | return RIL.getTelephonyRILTimingHistograms(); |
| 9249 | } finally { |
| 9250 | Binder.restoreCallingIdentity(identity); |
| 9251 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9252 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9253 | |
| 9254 | /** |
| 9255 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9256 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9257 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9258 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9259 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9260 | * @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] | 9261 | */ |
| 9262 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9263 | @TelephonyManager.SetCarrierRestrictionResult |
| 9264 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9265 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9266 | |
| 9267 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9268 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9269 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9270 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9271 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9272 | if (carrierRestrictionRules == null) { |
| 9273 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9274 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9276 | final long identity = Binder.clearCallingIdentity(); |
| 9277 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9278 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9279 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9280 | } finally { |
| 9281 | Binder.restoreCallingIdentity(identity); |
| 9282 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9283 | } |
| 9284 | |
| 9285 | /** |
| 9286 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9287 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9288 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9289 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9290 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9291 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9292 | */ |
| 9293 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9294 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9295 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9296 | |
| 9297 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9298 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9299 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9300 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9301 | |
| 9302 | final long identity = Binder.clearCallingIdentity(); |
| 9303 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9304 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9305 | if (response instanceof CarrierRestrictionRules) { |
| 9306 | return (CarrierRestrictionRules) response; |
| 9307 | } |
| 9308 | // Response is an Exception of some kind, |
| 9309 | // which is signalled to the user as a NULL retval |
| 9310 | return null; |
| 9311 | } catch (Exception e) { |
| 9312 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9313 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9314 | } finally { |
| 9315 | Binder.restoreCallingIdentity(identity); |
| 9316 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9317 | } |
| 9318 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9319 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9320 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9321 | * through the callback. |
| 9322 | * |
| 9323 | * @param callback The callback that will be used to send the result. |
| 9324 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9325 | * the caller is not allowlisted. |
| 9326 | */ |
| 9327 | @Override |
| 9328 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9329 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9330 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9331 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9332 | try { |
| 9333 | mApp.enforceCallingOrSelfPermission( |
| 9334 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9335 | functionName); |
| 9336 | } catch (SecurityException e) { |
| 9337 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9338 | functionName); |
| 9339 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9340 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9341 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9342 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9343 | throw new SecurityException("Not an authorized caller"); |
| 9344 | } |
| 9345 | final long identity = Binder.clearCallingIdentity(); |
| 9346 | try { |
| 9347 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9348 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9349 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9350 | } finally { |
| 9351 | Binder.restoreCallingIdentity(identity); |
| 9352 | } |
| 9353 | } |
| 9354 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9355 | @Override |
| 9356 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9357 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9358 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9359 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9360 | } |
| 9361 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9362 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9363 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9364 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9365 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9369 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9370 | * @param subId the subscription ID that this action applies to. |
| 9371 | * @param enabled control enable or disable radio. |
| 9372 | * {@hide} |
| 9373 | */ |
| 9374 | @Override |
| 9375 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9376 | enforceModifyPermission(); |
| 9377 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9378 | |
| 9379 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9380 | if (phone == null) { |
| 9381 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9382 | return; |
| 9383 | } |
| 9384 | try { |
| 9385 | phone.carrierActionSetRadioEnabled(enabled); |
| 9386 | } catch (Exception e) { |
| 9387 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9388 | } finally { |
| 9389 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9390 | } |
| 9391 | } |
| 9392 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9393 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9394 | * Enable or disable Voice over NR (VoNR) |
| 9395 | * @param subId the subscription ID that this action applies to. |
| 9396 | * @param enabled enable or disable VoNR. |
| 9397 | * @return operation result. |
| 9398 | */ |
| 9399 | @Override |
| 9400 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9401 | enforceModifyPermission(); |
| 9402 | final Phone phone = getPhone(subId); |
| 9403 | |
| 9404 | final long identity = Binder.clearCallingIdentity(); |
| 9405 | if (phone == null) { |
| 9406 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9407 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9408 | } |
| 9409 | |
| 9410 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9411 | try { |
| 9412 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9413 | workSource); |
| 9414 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9415 | |
| 9416 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9417 | if (DBG) { |
| 9418 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9419 | } |
| 9420 | SubscriptionManager.setSubscriptionProperty( |
| 9421 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9422 | (enabled ? "1" : "0")); |
| 9423 | } |
| 9424 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9425 | return result; |
| 9426 | } finally { |
| 9427 | Binder.restoreCallingIdentity(identity); |
| 9428 | } |
| 9429 | } |
| 9430 | |
| 9431 | /** |
| 9432 | * Is voice over NR enabled |
| 9433 | * @return true if VoNR is enabled else false |
| 9434 | */ |
| 9435 | @Override |
| 9436 | public boolean isVoNrEnabled(int subId) { |
| 9437 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9438 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9439 | final long identity = Binder.clearCallingIdentity(); |
| 9440 | try { |
| 9441 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9442 | null, subId, workSource); |
| 9443 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9444 | return isEnabled; |
| 9445 | } finally { |
| 9446 | Binder.restoreCallingIdentity(identity); |
| 9447 | } |
| 9448 | } |
| 9449 | |
| 9450 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9451 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9452 | * network status based on which carrier apps could apply actions accordingly, |
| 9453 | * enable/disable default url handler for example. |
| 9454 | * |
| 9455 | * @param subId the subscription ID that this action applies to. |
| 9456 | * @param report control start/stop reporting the default network status. |
| 9457 | * {@hide} |
| 9458 | */ |
| 9459 | @Override |
| 9460 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9461 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9462 | |
| 9463 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9464 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9465 | "carrierActionReportDefaultNetworkStatus"); |
| 9466 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9467 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9468 | |
| 9469 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9470 | if (phone == null) { |
| 9471 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9472 | return; |
| 9473 | } |
| 9474 | try { |
| 9475 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9476 | } catch (Exception e) { |
| 9477 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9478 | } finally { |
| 9479 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9480 | } |
| 9481 | } |
| 9482 | |
| 9483 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9484 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9485 | * @param subId the subscription ID that this action applies to. |
| 9486 | * {@hide} |
| 9487 | */ |
| 9488 | @Override |
| 9489 | public void carrierActionResetAll(int subId) { |
| 9490 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9491 | |
| 9492 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9493 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9494 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9495 | final Phone phone = getPhone(subId); |
| 9496 | if (phone == null) { |
| 9497 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9498 | return; |
| 9499 | } |
| 9500 | try { |
| 9501 | phone.carrierActionResetAll(); |
| 9502 | } catch (Exception e) { |
| 9503 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9504 | } |
| 9505 | } |
| 9506 | |
| 9507 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9508 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9509 | * bug report is being generated. |
| 9510 | */ |
| 9511 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9512 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9513 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9514 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9515 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9516 | + Binder.getCallingPid() |
| 9517 | + ", uid=" + Binder.getCallingUid() |
| 9518 | + "without permission " |
| 9519 | + android.Manifest.permission.DUMP); |
| 9520 | return; |
| 9521 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9522 | try { |
| 9523 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9524 | } catch (Exception e) { |
| 9525 | writer.println("Failed to dump phone information: " + e); |
| 9526 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9527 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9528 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9529 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9530 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9531 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9532 | @NonNull String[] args) { |
| 9533 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9534 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9535 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9536 | } |
| 9537 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9538 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9539 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9540 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9541 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9542 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9543 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9544 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9545 | */ |
| 9546 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9547 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9548 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9549 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9550 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9551 | try { |
| 9552 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9553 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9554 | } catch (SecurityException se) { |
| 9555 | enforceModifyPermission(); |
| 9556 | } |
| 9557 | } else { |
| 9558 | enforceModifyPermission(); |
| 9559 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9560 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9561 | enforceTelephonyFeatureWithException(callingPackage, |
| 9562 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9563 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9564 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9565 | final long identity = Binder.clearCallingIdentity(); |
| 9566 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9567 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9568 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9569 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9570 | callingUid, callingPackage, null, null); |
| 9571 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9572 | Phone phone = getPhone(subId); |
| 9573 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9574 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9575 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9576 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9577 | phone.getDataSettingsManager().setDataEnabled( |
| 9578 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9579 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9580 | } |
| 9581 | } finally { |
| 9582 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9583 | } |
| 9584 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9585 | |
| 9586 | /** |
| 9587 | * Get Client request stats |
| 9588 | * @return List of Client Request Stats |
| 9589 | * @hide |
| 9590 | */ |
| 9591 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9592 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9593 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9594 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9595 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9596 | return null; |
| 9597 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9598 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9600 | final long identity = Binder.clearCallingIdentity(); |
| 9601 | try { |
| 9602 | if (phone != null) { |
| 9603 | return phone.getClientRequestStats(); |
| 9604 | } |
| 9605 | |
| 9606 | return null; |
| 9607 | } finally { |
| 9608 | Binder.restoreCallingIdentity(identity); |
| 9609 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9610 | } |
| 9611 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9612 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9613 | PackageManager pm; |
| 9614 | if (mFeatureFlags.hsumPackageManager()) { |
| 9615 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9616 | .getPackageManager(); |
| 9617 | } else { |
| 9618 | pm = mApp.getPackageManager(); |
| 9619 | } |
| 9620 | |
| 9621 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9622 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9623 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9624 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9625 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9626 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9627 | // commands that plumb through the RIL as root, like so: |
| 9628 | // $ adb root |
| 9629 | // $ adb shell cmd phone ... |
| 9630 | packageName = "root"; |
| 9631 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9632 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9633 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9634 | |
| 9635 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9636 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9637 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9638 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9639 | * @param state State of SIM (power down, power up, pass through) |
| 9640 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9641 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9642 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9643 | * |
| 9644 | **/ |
| 9645 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9646 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9647 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9648 | |
| 9649 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9650 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9651 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9652 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9653 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9654 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9655 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9656 | final long identity = Binder.clearCallingIdentity(); |
| 9657 | try { |
| 9658 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9659 | phone.setSimPowerState(state, null, workSource); |
| 9660 | } |
| 9661 | } finally { |
| 9662 | Binder.restoreCallingIdentity(identity); |
| 9663 | } |
| 9664 | } |
| 9665 | |
| 9666 | /** |
| 9667 | * Set SIM card power state. |
| 9668 | * |
| 9669 | * @param slotIndex SIM slot id. |
| 9670 | * @param state State of SIM (power down, power up, pass through) |
| 9671 | * @param callback callback to trigger after success or failure |
| 9672 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9673 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9674 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9675 | * |
| 9676 | **/ |
| 9677 | @Override |
| 9678 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9679 | IIntegerConsumer callback) { |
| 9680 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9681 | |
| 9682 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9683 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9684 | "setSimPowerStateForSlotWithCallback"); |
| 9685 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9686 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9687 | |
| 9688 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9689 | |
| 9690 | final long identity = Binder.clearCallingIdentity(); |
| 9691 | try { |
| 9692 | if (phone != null) { |
| 9693 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9694 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9695 | } |
| 9696 | } finally { |
| 9697 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9698 | } |
| 9699 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9700 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9701 | private boolean isUssdApiAllowed(int subId) { |
| 9702 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9703 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9704 | if (configManager == null) { |
| 9705 | return false; |
| 9706 | } |
| 9707 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9708 | if (pb == null) { |
| 9709 | return false; |
| 9710 | } |
| 9711 | return pb.getBoolean( |
| 9712 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9713 | } |
| 9714 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9715 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9716 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9717 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9718 | * @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] | 9719 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9720 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9721 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9722 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9723 | |
| 9724 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9725 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9727 | final long identity = Binder.clearCallingIdentity(); |
| 9728 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9729 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9730 | } finally { |
| 9731 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9732 | } |
| 9733 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9734 | |
| 9735 | /** |
| 9736 | * Get the current signal strength information for the given subscription. |
| 9737 | * Because this information is not updated when the device is in a low power state |
| 9738 | * it should not be relied-upon to be current. |
| 9739 | * @param subId Subscription index |
| 9740 | * @return the most recent cached signal strength info from the modem |
| 9741 | */ |
| 9742 | @Override |
| 9743 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9744 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9745 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9747 | final long identity = Binder.clearCallingIdentity(); |
| 9748 | try { |
| 9749 | Phone p = getPhone(subId); |
| 9750 | if (p == null) { |
| 9751 | return null; |
| 9752 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9754 | return p.getSignalStrength(); |
| 9755 | } finally { |
| 9756 | Binder.restoreCallingIdentity(identity); |
| 9757 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9758 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9759 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9760 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9761 | * Get the current modem radio state for the given slot. |
| 9762 | * @param slotIndex slot index. |
| 9763 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9764 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9765 | * @return the current radio power state from the modem |
| 9766 | */ |
| 9767 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9768 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9769 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9770 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9772 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9773 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9774 | } |
| 9775 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9776 | enforceTelephonyFeatureWithException(callingPackage, |
| 9777 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9778 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9779 | final long identity = Binder.clearCallingIdentity(); |
| 9780 | try { |
| 9781 | return phone.getRadioPowerState(); |
| 9782 | } finally { |
| 9783 | Binder.restoreCallingIdentity(identity); |
| 9784 | } |
| 9785 | } |
| 9786 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9787 | } |
| 9788 | |
| 9789 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9790 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9791 | * |
| 9792 | * <p>Requires one of the following permissions: |
| 9793 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9794 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9795 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9796 | * privileges. |
| 9797 | * |
| 9798 | * @param subId subscription id |
| 9799 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9800 | * {@code false}. |
| 9801 | */ |
| 9802 | @Override |
| 9803 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9804 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9805 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9806 | try { |
| 9807 | mApp.enforceCallingOrSelfPermission( |
| 9808 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9809 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9810 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9811 | mApp.enforceCallingOrSelfPermission( |
| 9812 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9813 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9814 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9815 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9816 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9817 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9818 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9819 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9820 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9821 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9822 | boolean isEnabled = false; |
| 9823 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9824 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9825 | Phone phone = getPhone(subId); |
| 9826 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9827 | } finally { |
| 9828 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9829 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9830 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9831 | } |
| 9832 | |
| 9833 | |
| 9834 | /** |
| 9835 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9836 | * |
| 9837 | * <p> Requires permission: |
| 9838 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9839 | * privileges. |
| 9840 | * |
| 9841 | * @param subId subscription id |
| 9842 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9843 | */ |
| 9844 | @Override |
| 9845 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9847 | mApp, subId, "setDataRoamingEnabled"); |
| 9848 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9849 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9850 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9851 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9852 | final long identity = Binder.clearCallingIdentity(); |
| 9853 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9854 | Phone phone = getPhone(subId); |
| 9855 | if (phone != null) { |
| 9856 | phone.setDataRoamingEnabled(isEnabled); |
| 9857 | } |
| 9858 | } finally { |
| 9859 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9860 | } |
| 9861 | } |
| 9862 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9863 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9864 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9865 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9866 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9867 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9868 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9869 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9870 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9871 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9872 | boolean isAllowed = true; |
| 9873 | final long identity = Binder.clearCallingIdentity(); |
| 9874 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9875 | Phone phone = getPhone(subId); |
| 9876 | if (phone != null) { |
| 9877 | isAllowed = phone.isCspPlmnEnabled(); |
| 9878 | } |
| 9879 | } finally { |
| 9880 | Binder.restoreCallingIdentity(identity); |
| 9881 | } |
| 9882 | return isAllowed; |
| 9883 | } |
| 9884 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9885 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9886 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9887 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9888 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9889 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9890 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9891 | if (phone == null) { |
| 9892 | return false; |
| 9893 | } |
| 9894 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9895 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9896 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9897 | } |
| 9898 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9899 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9900 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9901 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9902 | mApp.getSystemService(AppOpsManager.class) |
| 9903 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9904 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9905 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9906 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9907 | try { |
| 9908 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9909 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9910 | } catch (SecurityException e) { |
| 9911 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9912 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9913 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9914 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9915 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9916 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9917 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9918 | |
| 9919 | enforceTelephonyFeatureWithException(callingPackage, |
| 9920 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9921 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9922 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9923 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9924 | Binder.getCallingUid())) { |
| 9925 | isIccIdAccessRestricted = true; |
| 9926 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9927 | final long identity = Binder.clearCallingIdentity(); |
| 9928 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9929 | UiccController uiccController = UiccController.getInstance(); |
| 9930 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9931 | if (hasReadPermission) { |
| 9932 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9933 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9934 | |
| 9935 | // Remove private info if the caller doesn't have access |
| 9936 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9937 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9938 | //setting the value after compatibility check |
| 9939 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9940 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9941 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9942 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9943 | if (card == null) { |
| 9944 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9945 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9946 | continue; |
| 9947 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9948 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9949 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9950 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9951 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9952 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9953 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9954 | for (UiccPortInfo portInfo : portInfos) { |
| 9955 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9956 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9957 | if (port == null) { |
| 9958 | // assume no access if port is null |
| 9959 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9960 | continue; |
| 9961 | } |
| 9962 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9963 | uiccPortInfos.add(portInfo); |
| 9964 | } else { |
| 9965 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9966 | } |
| 9967 | } |
| 9968 | filteredInfos.add(new UiccCardInfo( |
| 9969 | cardInfo.isEuicc(), |
| 9970 | cardInfo.getCardId(), |
| 9971 | null, |
| 9972 | cardInfo.getPhysicalSlotIndex(), |
| 9973 | cardInfo.isRemovable(), |
| 9974 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9975 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9976 | } |
| 9977 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(identity); |
| 9980 | } |
| 9981 | } |
| 9982 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9983 | /** |
| 9984 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9985 | * generally private and require carrier privileges to view. |
| 9986 | * |
| 9987 | * @hide |
| 9988 | */ |
| 9989 | @NonNull |
| 9990 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9991 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9992 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9993 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9994 | } |
| 9995 | return new UiccCardInfo( |
| 9996 | cardInfo.isEuicc(), |
| 9997 | cardInfo.getCardId(), |
| 9998 | null, |
| 9999 | cardInfo.getPhysicalSlotIndex(), |
| 10000 | cardInfo.isRemovable(), |
| 10001 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10002 | portinfo |
| 10003 | ); |
| 10004 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10005 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10006 | /** |
| 10007 | * @hide |
| 10008 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10009 | * These values are generally private and require carrier privileges to view. |
| 10010 | */ |
| 10011 | @NonNull |
| 10012 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10013 | return new UiccPortInfo( |
| 10014 | UiccPortInfo.ICCID_REDACTED, |
| 10015 | portInfo.getPortIndex(), |
| 10016 | portInfo.getLogicalSlotIndex(), |
| 10017 | portInfo.isActive() |
| 10018 | ); |
| 10019 | } |
| 10020 | @Override |
| 10021 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10022 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10023 | mApp.getSystemService(AppOpsManager.class) |
| 10024 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10025 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10026 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10027 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10028 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10029 | // we are reading iccId which is PII data. |
| 10030 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10031 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10032 | enforceTelephonyFeatureWithException(callingPackage, |
| 10033 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10034 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10035 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10036 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10037 | Binder.getCallingUid())) { |
| 10038 | isLogicalSlotAccessRestricted = true; |
| 10039 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10040 | final long identity = Binder.clearCallingIdentity(); |
| 10041 | try { |
| 10042 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10043 | if (slots == null || slots.length == 0) { |
| 10044 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10045 | return null; |
| 10046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10047 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10048 | for (int i = 0; i < slots.length; i++) { |
| 10049 | UiccSlot slot = slots[i]; |
| 10050 | if (slot == null) { |
| 10051 | continue; |
| 10052 | } |
| 10053 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10054 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10055 | UiccCard card = slot.getUiccCard(); |
| 10056 | if (card != null) { |
| 10057 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10058 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10059 | cardId = slot.getEid(); |
| 10060 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10061 | // If cardId is null, use iccId of default port as cardId. |
| 10062 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10063 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10064 | } |
| 10065 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10066 | if (cardId != null) { |
| 10067 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10068 | // if cardId is an EID, it's all digits so this is fine |
| 10069 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10070 | } |
| 10071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10072 | int cardState = 0; |
| 10073 | switch (slot.getCardState()) { |
| 10074 | case CARDSTATE_ABSENT: |
| 10075 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10076 | break; |
| 10077 | case CARDSTATE_PRESENT: |
| 10078 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10079 | break; |
| 10080 | case CARDSTATE_ERROR: |
| 10081 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10082 | break; |
| 10083 | case CARDSTATE_RESTRICTED: |
| 10084 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10085 | break; |
| 10086 | default: |
| 10087 | break; |
| 10088 | |
| 10089 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10090 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10091 | int[] portIndexes = slot.getPortList(); |
| 10092 | for (int portIdx : portIndexes) { |
| 10093 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10094 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10095 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10096 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10097 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10098 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10099 | slot.isEuicc(), |
| 10100 | cardId, |
| 10101 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10102 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10103 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10104 | //setting the value after compatibility check |
| 10105 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10106 | } |
| 10107 | return infos; |
| 10108 | } finally { |
| 10109 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10110 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10111 | } |
| 10112 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10113 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10114 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10115 | boolean hasReadPermission) { |
| 10116 | String iccId = slot.getIccId(portIndex); |
| 10117 | if (hasReadPermission) { // if has read permission |
| 10118 | return iccId; |
| 10119 | } else { |
| 10120 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10121 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10122 | // if no read permission, checking carrier privilege access |
| 10123 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10124 | return iccId; |
| 10125 | } |
| 10126 | } |
| 10127 | } |
| 10128 | // No read permission or carrier privilege access. |
| 10129 | return UiccPortInfo.ICCID_REDACTED; |
| 10130 | } |
| 10131 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10132 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10133 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10134 | public boolean switchSlots(int[] physicalSlots) { |
| 10135 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10136 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10137 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10138 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10140 | final long identity = Binder.clearCallingIdentity(); |
| 10141 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10142 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10143 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10144 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10145 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10146 | physicalSlots[i], i)); |
| 10147 | } |
| 10148 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10149 | } finally { |
| 10150 | Binder.restoreCallingIdentity(identity); |
| 10151 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10152 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10153 | |
| 10154 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10155 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10156 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10157 | enforceModifyPermission(); |
| 10158 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10159 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10160 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10161 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10162 | final long identity = Binder.clearCallingIdentity(); |
| 10163 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10164 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10165 | } finally { |
| 10166 | Binder.restoreCallingIdentity(identity); |
| 10167 | } |
| 10168 | } |
| 10169 | |
| 10170 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10171 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10172 | enforceTelephonyFeatureWithException(callingPackage, |
| 10173 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10174 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10175 | final long identity = Binder.clearCallingIdentity(); |
| 10176 | try { |
| 10177 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10178 | } finally { |
| 10179 | Binder.restoreCallingIdentity(identity); |
| 10180 | } |
| 10181 | } |
| 10182 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10183 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10184 | * A test API to reload the UICC profile. |
| 10185 | * |
| 10186 | * <p>Requires that the calling app has permission |
| 10187 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10188 | * @hide |
| 10189 | */ |
| 10190 | @Override |
| 10191 | public void refreshUiccProfile(int subId) { |
| 10192 | enforceModifyPermission(); |
| 10193 | |
| 10194 | final long identity = Binder.clearCallingIdentity(); |
| 10195 | try { |
| 10196 | Phone phone = getPhone(subId); |
| 10197 | if (phone == null) { |
| 10198 | return; |
| 10199 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10200 | UiccPort uiccPort = phone.getUiccPort(); |
| 10201 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10202 | return; |
| 10203 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10204 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10205 | if (uiccProfile == null) { |
| 10206 | return; |
| 10207 | } |
| 10208 | uiccProfile.refresh(); |
| 10209 | } finally { |
| 10210 | Binder.restoreCallingIdentity(identity); |
| 10211 | } |
| 10212 | } |
| 10213 | |
| 10214 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10215 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10216 | */ |
| 10217 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10218 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10219 | } |
| 10220 | |
| 10221 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10222 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10223 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10224 | */ |
| 10225 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10226 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10227 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10228 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10229 | return list.get(phoneId); |
| 10230 | } |
| 10231 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10232 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10233 | |
| 10234 | @Override |
| 10235 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10236 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10237 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10238 | |
| 10239 | final long identity = Binder.clearCallingIdentity(); |
| 10240 | try { |
| 10241 | final Phone phone = getPhone(subId); |
| 10242 | if (phone == null) { |
| 10243 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10244 | return; |
| 10245 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10246 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10247 | if (cpt != null) { |
| 10248 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10249 | } |
| 10250 | // 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] | 10251 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10252 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10253 | if (carrierPrivilegeRules == null) { |
| 10254 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10255 | } else { |
| 10256 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10258 | } finally { |
| 10259 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10260 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10261 | } |
| 10262 | |
| 10263 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10264 | public void setCarrierServicePackageOverride( |
| 10265 | int subId, String carrierServicePackage, String callingPackage) { |
| 10266 | TelephonyPermissions.enforceShellOnly( |
| 10267 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10268 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10269 | final long identity = Binder.clearCallingIdentity(); |
| 10270 | try { |
| 10271 | final Phone phone = getPhone(subId); |
| 10272 | if (phone == null || phone.getSubId() != subId) { |
| 10273 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10274 | throw new IllegalArgumentException("No phone for subid"); |
| 10275 | } |
| 10276 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10277 | if (cpt == null) { |
| 10278 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10279 | throw new IllegalStateException("No CPT for phone"); |
| 10280 | } |
| 10281 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10282 | } finally { |
| 10283 | Binder.restoreCallingIdentity(identity); |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10288 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10289 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10290 | |
| 10291 | final long identity = Binder.clearCallingIdentity(); |
| 10292 | try { |
| 10293 | final Phone phone = getPhone(subId); |
| 10294 | if (phone == null) { |
| 10295 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10296 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10297 | } |
| 10298 | return phone.getCarrierIdListVersion(); |
| 10299 | } finally { |
| 10300 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10301 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10302 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10303 | |
| 10304 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10305 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10306 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10308 | mApp, subId, callingPackage, callingFeatureId, |
| 10309 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10310 | return -1; |
| 10311 | } |
| 10312 | |
| 10313 | final long identity = Binder.clearCallingIdentity(); |
| 10314 | try { |
| 10315 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10320 | |
| 10321 | @Override |
| 10322 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10323 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10324 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10325 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10326 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10327 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10328 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10329 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10330 | final long identity = Binder.clearCallingIdentity(); |
| 10331 | try { |
| 10332 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10333 | } finally { |
| 10334 | Binder.restoreCallingIdentity(identity); |
| 10335 | } |
| 10336 | } |
| 10337 | |
| 10338 | @Override |
| 10339 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10341 | mApp, subId, "setCdmaRoamingMode"); |
| 10342 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10343 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10344 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10345 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10346 | final long identity = Binder.clearCallingIdentity(); |
| 10347 | try { |
| 10348 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10349 | } finally { |
| 10350 | Binder.restoreCallingIdentity(identity); |
| 10351 | } |
| 10352 | } |
| 10353 | |
| 10354 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10355 | public int getCdmaSubscriptionMode(int subId) { |
| 10356 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10357 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10358 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10359 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10360 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10361 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10362 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10363 | final long identity = Binder.clearCallingIdentity(); |
| 10364 | try { |
| 10365 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | } |
| 10370 | |
| 10371 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10372 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10374 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10375 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10377 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10378 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10379 | final long identity = Binder.clearCallingIdentity(); |
| 10380 | try { |
| 10381 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10382 | } finally { |
| 10383 | Binder.restoreCallingIdentity(identity); |
| 10384 | } |
| 10385 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10386 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10387 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10388 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10389 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10391 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10392 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10393 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10394 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10395 | |
| 10396 | enforceTelephonyFeatureWithException(callingPackage, |
| 10397 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10398 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10399 | final long identity = Binder.clearCallingIdentity(); |
| 10400 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10401 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10402 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10403 | if (phone.getEmergencyNumberTracker() != null |
| 10404 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10405 | emergencyNumberListInternal.put( |
| 10406 | phone.getSubId(), |
| 10407 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10408 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10409 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10410 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10411 | } finally { |
| 10412 | Binder.restoreCallingIdentity(identity); |
| 10413 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10414 | } |
| 10415 | |
| 10416 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10417 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10418 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10419 | if (!exactMatch) { |
| 10420 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10421 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10422 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10423 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10424 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10425 | if (!mApp.getResources().getBoolean( |
| 10426 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10427 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10428 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10429 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10430 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10431 | final long identity = Binder.clearCallingIdentity(); |
| 10432 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10433 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10434 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10435 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10436 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10437 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10438 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10439 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10440 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10441 | } |
| 10442 | return false; |
| 10443 | } finally { |
| 10444 | Binder.restoreCallingIdentity(identity); |
| 10445 | } |
| 10446 | } |
| 10447 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10448 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10449 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10450 | */ |
| 10451 | @Override |
| 10452 | public void startEmergencyCallbackMode() { |
| 10453 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10454 | "startEmergencyCallbackMode"); |
| 10455 | enforceModifyPermission(); |
| 10456 | final long identity = Binder.clearCallingIdentity(); |
| 10457 | try { |
| 10458 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10459 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10460 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10461 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10462 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10463 | gsmCdmaPhone.obtainMessage( |
| 10464 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10465 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10466 | } |
| 10467 | } |
| 10468 | } finally { |
| 10469 | Binder.restoreCallingIdentity(identity); |
| 10470 | } |
| 10471 | } |
| 10472 | |
| 10473 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10474 | * Update emergency number list for test mode. |
| 10475 | */ |
| 10476 | @Override |
| 10477 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10478 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10479 | "updateEmergencyNumberListTestMode"); |
| 10480 | |
| 10481 | final long identity = Binder.clearCallingIdentity(); |
| 10482 | try { |
| 10483 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10484 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10485 | if (tracker != null) { |
| 10486 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10487 | } |
| 10488 | } |
| 10489 | } finally { |
| 10490 | Binder.restoreCallingIdentity(identity); |
| 10491 | } |
| 10492 | } |
| 10493 | |
| 10494 | /** |
| 10495 | * Get the full emergency number list for test mode. |
| 10496 | */ |
| 10497 | @Override |
| 10498 | public List<String> getEmergencyNumberListTestMode() { |
| 10499 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10500 | "getEmergencyNumberListTestMode"); |
| 10501 | |
| 10502 | final long identity = Binder.clearCallingIdentity(); |
| 10503 | try { |
| 10504 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10505 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10506 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10507 | if (tracker != null) { |
| 10508 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10509 | emergencyNumbers.add(num.getNumber()); |
| 10510 | } |
| 10511 | } |
| 10512 | } |
| 10513 | return new ArrayList<>(emergencyNumbers); |
| 10514 | } finally { |
| 10515 | Binder.restoreCallingIdentity(identity); |
| 10516 | } |
| 10517 | } |
| 10518 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10519 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10520 | public int getEmergencyNumberDbVersion(int subId) { |
| 10521 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10524 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10525 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10526 | final long identity = Binder.clearCallingIdentity(); |
| 10527 | try { |
| 10528 | final Phone phone = getPhone(subId); |
| 10529 | if (phone == null) { |
| 10530 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10531 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10532 | } |
| 10533 | return phone.getEmergencyNumberDbVersion(); |
| 10534 | } finally { |
| 10535 | Binder.restoreCallingIdentity(identity); |
| 10536 | } |
| 10537 | } |
| 10538 | |
| 10539 | @Override |
| 10540 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10541 | enforceModifyPermission(); |
| 10542 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10543 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10544 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10545 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10546 | final long identity = Binder.clearCallingIdentity(); |
| 10547 | try { |
| 10548 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10549 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10550 | if (tracker != null) { |
| 10551 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10552 | } |
| 10553 | } |
| 10554 | } finally { |
| 10555 | Binder.restoreCallingIdentity(identity); |
| 10556 | } |
| 10557 | } |
| 10558 | |
| 10559 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10560 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10561 | enforceActiveEmergencySessionPermission(); |
| 10562 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10563 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10564 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10565 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10566 | final long identity = Binder.clearCallingIdentity(); |
| 10567 | try { |
| 10568 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10569 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10570 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10571 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10572 | } |
| 10573 | } |
| 10574 | } finally { |
| 10575 | Binder.restoreCallingIdentity(identity); |
| 10576 | } |
| 10577 | } |
| 10578 | |
| 10579 | @Override |
| 10580 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10581 | enforceActiveEmergencySessionPermission(); |
| 10582 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10583 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10584 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10585 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10586 | final long identity = Binder.clearCallingIdentity(); |
| 10587 | try { |
| 10588 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10589 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10590 | if (tracker != null) { |
| 10591 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10592 | } |
| 10593 | } |
| 10594 | } finally { |
| 10595 | Binder.restoreCallingIdentity(identity); |
| 10596 | } |
| 10597 | } |
| 10598 | |
| 10599 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10600 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10601 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10602 | Phone phone = getPhone(subId); |
| 10603 | if (phone == null) { |
| 10604 | return null; |
| 10605 | } |
| 10606 | final long identity = Binder.clearCallingIdentity(); |
| 10607 | try { |
| 10608 | UiccProfile profile = UiccController.getInstance() |
| 10609 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10610 | if (profile != null) { |
| 10611 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10612 | } |
| 10613 | } finally { |
| 10614 | Binder.restoreCallingIdentity(identity); |
| 10615 | } |
| 10616 | return null; |
| 10617 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10618 | |
| 10619 | /** |
| 10620 | * Enable or disable a modem stack. |
| 10621 | */ |
| 10622 | @Override |
| 10623 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10624 | enforceModifyPermission(); |
| 10625 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10626 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10627 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10628 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10629 | final long identity = Binder.clearCallingIdentity(); |
| 10630 | try { |
| 10631 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10632 | if (phone == null) { |
| 10633 | return false; |
| 10634 | } else { |
| 10635 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10636 | } |
| 10637 | } finally { |
| 10638 | Binder.restoreCallingIdentity(identity); |
| 10639 | } |
| 10640 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10641 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10642 | /** |
| 10643 | * Whether a modem stack is enabled or not. |
| 10644 | */ |
| 10645 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10646 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10647 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10648 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10649 | if (phone == null) return false; |
| 10650 | |
| 10651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10652 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10653 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10654 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10655 | } |
| 10656 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10657 | enforceTelephonyFeatureWithException(callingPackage, |
| 10658 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10659 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10660 | final long identity = Binder.clearCallingIdentity(); |
| 10661 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10662 | try { |
| 10663 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10664 | } catch (NoSuchElementException ex) { |
| 10665 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10666 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10667 | } finally { |
| 10668 | Binder.restoreCallingIdentity(identity); |
| 10669 | } |
| 10670 | } |
| 10671 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10672 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10673 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10674 | enforceModifyPermission(); |
| 10675 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10676 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10677 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10678 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10679 | final long identity = Binder.clearCallingIdentity(); |
| 10680 | try { |
| 10681 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10682 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10683 | .commit(); |
| 10684 | } finally { |
| 10685 | Binder.restoreCallingIdentity(identity); |
| 10686 | } |
| 10687 | } |
| 10688 | |
| 10689 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10690 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10691 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10692 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10693 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10694 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10695 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10696 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10697 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10698 | enforceTelephonyFeatureWithException(callingPackage, |
| 10699 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10700 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10701 | final long identity = Binder.clearCallingIdentity(); |
| 10702 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10703 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10704 | } finally { |
| 10705 | Binder.restoreCallingIdentity(identity); |
| 10706 | } |
| 10707 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10708 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10709 | @TelephonyManager.IsMultiSimSupportedResult |
| 10710 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10711 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10712 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10713 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10714 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10715 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10716 | } |
| 10717 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10718 | // supported by the modem, indicate that it is restricted. |
| 10719 | PhoneCapability staticCapability = |
| 10720 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10721 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10722 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10723 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10724 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10725 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10726 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10727 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10728 | } |
| 10729 | // Check if support of multiple SIMs is restricted by carrier |
| 10730 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10731 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10732 | } |
| 10733 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10734 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10735 | } |
| 10736 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10737 | /** |
| 10738 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10739 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10740 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10741 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10742 | * @param numOfSims number of active sims we want to switch to |
| 10743 | */ |
| 10744 | @Override |
| 10745 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10746 | if (numOfSims == 1) { |
| 10747 | enforceModifyPermission(); |
| 10748 | } else { |
| 10749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10750 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10751 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10752 | |
| 10753 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10754 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10755 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10756 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10757 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10758 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10759 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10760 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10761 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10762 | return; |
| 10763 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10764 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10765 | } finally { |
| 10766 | Binder.restoreCallingIdentity(identity); |
| 10767 | } |
| 10768 | } |
| 10769 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10770 | @Override |
| 10771 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10772 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10773 | |
| 10774 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10775 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10776 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10777 | Phone phone = getPhone(subId); |
| 10778 | if (phone == null) { |
| 10779 | return false; |
| 10780 | } |
| 10781 | final long identity = Binder.clearCallingIdentity(); |
| 10782 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10783 | UiccPort uiccPort = phone.getUiccPort(); |
| 10784 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10785 | return false; |
| 10786 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10787 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10788 | if (uiccProfile == null) { |
| 10789 | return false; |
| 10790 | } |
| 10791 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10792 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10793 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10794 | } |
| 10795 | return false; |
| 10796 | } finally { |
| 10797 | Binder.restoreCallingIdentity(identity); |
| 10798 | } |
| 10799 | } |
| 10800 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10801 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10802 | * Get whether making changes to modem configurations will trigger reboot. |
| 10803 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10804 | */ |
| 10805 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10806 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10807 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10808 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10809 | mApp, subId, callingPackage, callingFeatureId, |
| 10810 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10811 | return false; |
| 10812 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10813 | |
| 10814 | enforceTelephonyFeatureWithException(callingPackage, |
| 10815 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10816 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10817 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10818 | final long identity = Binder.clearCallingIdentity(); |
| 10819 | try { |
| 10820 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10821 | } finally { |
| 10822 | Binder.restoreCallingIdentity(identity); |
| 10823 | } |
| 10824 | } |
| 10825 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10826 | private void updateModemStateMetrics() { |
| 10827 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10828 | // TODO: check the state for each modem if the api is ready. |
| 10829 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10830 | } |
| 10831 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10832 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10833 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10834 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10835 | // Verify that the callingPackage belongs to the calling UID |
| 10836 | mApp.getSystemService(AppOpsManager.class) |
| 10837 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10838 | |
| 10839 | enforceTelephonyFeatureWithException(callingPackage, |
| 10840 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10841 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10842 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10843 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10844 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10845 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10846 | if (slotInfos != null) { |
| 10847 | for (int i = 0; i < slotInfos.length; i++) { |
| 10848 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10849 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10850 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10851 | portInfo.getLogicalSlotIndex())); |
| 10852 | } |
| 10853 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10854 | } |
| 10855 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10856 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10857 | } finally { |
| 10858 | Binder.restoreCallingIdentity(identity); |
| 10859 | } |
| 10860 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10861 | |
| 10862 | /** |
| 10863 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10864 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10865 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10866 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10867 | @Override |
| 10868 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10869 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10870 | } |
| 10871 | |
| 10872 | /** |
| 10873 | * Get the HAL Version of a specific service |
| 10874 | */ |
| 10875 | @Override |
| 10876 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10877 | Phone phone = getDefaultPhone(); |
| 10878 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10879 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10880 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10881 | return hv.major * 100 + hv.minor; |
| 10882 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10883 | |
| 10884 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10885 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10886 | * |
| 10887 | * @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] | 10888 | */ |
| 10889 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10890 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10891 | if (mFeatureFlags.hsumPackageManager()) { |
| 10892 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10893 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10894 | if (pm == null) return null; |
| 10895 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10896 | return (callingUids == null) ? null : callingUids[0]; |
| 10897 | } |
| 10898 | if (mPackageManager == null) return null; |
| 10899 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10900 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10901 | } |
| 10902 | |
| 10903 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10904 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10905 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10906 | * actually always the caller. |
| 10907 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10908 | */ |
| 10909 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10910 | PackageManager pm; |
| 10911 | if (mFeatureFlags.hsumPackageManager()) { |
| 10912 | pm = mApp.getBaseContext().createContextAsUser( |
| 10913 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10914 | } else { |
| 10915 | pm = mApp.getPackageManager(); |
| 10916 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10917 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10918 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10919 | return getCurrentPackageName(); |
| 10920 | } |
| 10921 | |
| 10922 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10923 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10924 | * corresponding network requests on a subId. |
| 10925 | * |
| 10926 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10927 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10928 | * 2) APN is un-metered for this subscription, or |
| 10929 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10930 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10931 | * |
| 10932 | * @return whether data is allowed for a apn type. |
| 10933 | * |
| 10934 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10935 | */ |
| 10936 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10937 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10938 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10939 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10940 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10941 | enforceTelephonyFeatureWithException(callingPackage, |
| 10942 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10943 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10944 | // Now that all security checks passes, perform the operation as ourselves. |
| 10945 | final long identity = Binder.clearCallingIdentity(); |
| 10946 | try { |
| 10947 | Phone phone = getPhone(subId); |
| 10948 | if (phone == null) return false; |
| 10949 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10950 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10951 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10952 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10953 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10954 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10955 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10956 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10957 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10958 | } finally { |
| 10959 | Binder.restoreCallingIdentity(identity); |
| 10960 | } |
| 10961 | } |
| 10962 | |
| 10963 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10964 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10965 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10966 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10967 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10968 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10969 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10970 | // Now that all security checks passes, perform the operation as ourselves. |
| 10971 | final long identity = Binder.clearCallingIdentity(); |
| 10972 | try { |
| 10973 | Phone phone = getPhone(subId); |
| 10974 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10975 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10976 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10977 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10978 | } finally { |
| 10979 | Binder.restoreCallingIdentity(identity); |
| 10980 | } |
| 10981 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10982 | |
| 10983 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10984 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10985 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10986 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10987 | |
| 10988 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10989 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10990 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10991 | long token = Binder.clearCallingIdentity(); |
| 10992 | try { |
| 10993 | Phone phone = getPhone(subscriptionId); |
| 10994 | if (phone == null) { |
| 10995 | try { |
| 10996 | if (resultCallback != null) { |
| 10997 | resultCallback.accept(false); |
| 10998 | } |
| 10999 | } catch (RemoteException e) { |
| 11000 | // ignore |
| 11001 | } |
| 11002 | return; |
| 11003 | } |
| 11004 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11005 | Pair.create(specifiers, (x) -> { |
| 11006 | try { |
| 11007 | if (resultCallback != null) { |
| 11008 | resultCallback.accept(x); |
| 11009 | } |
| 11010 | } catch (RemoteException e) { |
| 11011 | // ignore |
| 11012 | } |
| 11013 | }); |
| 11014 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11015 | } finally { |
| 11016 | Binder.restoreCallingIdentity(token); |
| 11017 | } |
| 11018 | } |
| 11019 | |
| 11020 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11021 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11022 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11023 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11024 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11025 | |
| 11026 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11027 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11028 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11029 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11030 | final long identity = Binder.clearCallingIdentity(); |
| 11031 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11032 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11033 | if (result instanceof IllegalStateException) { |
| 11034 | throw (IllegalStateException) result; |
| 11035 | } |
| 11036 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11037 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11038 | return specifiers; |
| 11039 | } finally { |
| 11040 | Binder.restoreCallingIdentity(identity); |
| 11041 | } |
| 11042 | } |
| 11043 | |
| 11044 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11045 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11046 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11047 | |
| 11048 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11049 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11050 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11051 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11052 | } |
| 11053 | |
| 11054 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11055 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11056 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11057 | if (callingPackage == null) { |
| 11058 | callingPackage = getCurrentPackageName(); |
| 11059 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11060 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11061 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11062 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11063 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11064 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11065 | } |
| 11066 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11067 | Intent intent = new Intent(); |
| 11068 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11069 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11070 | // Bring up choose default SMS subscription dialog right now |
| 11071 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11072 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11073 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11074 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11075 | |
| 11076 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11077 | public void showSwitchToManagedProfileDialog() { |
| 11078 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11079 | try { |
| 11080 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11081 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11082 | // for work telephony. |
| 11083 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11084 | intent.setData(Uri.parse("smsto:")); |
| 11085 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11086 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11087 | } catch (ActivityNotFoundException e) { |
| 11088 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11089 | Intent intent = new Intent(); |
| 11090 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11091 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11092 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11093 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11094 | } |
| 11095 | |
| 11096 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11097 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11098 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11099 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11100 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11101 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11102 | final long identity = Binder.clearCallingIdentity(); |
| 11103 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11104 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11105 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11106 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11107 | return carrierUAProfUrl; |
| 11108 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11109 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11110 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11111 | } finally { |
| 11112 | Binder.restoreCallingIdentity(identity); |
| 11113 | } |
| 11114 | } |
| 11115 | |
| 11116 | @Override |
| 11117 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11118 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11119 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11120 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11121 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11122 | final long identity = Binder.clearCallingIdentity(); |
| 11123 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11124 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11125 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11126 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11127 | return carrierUserAgent; |
| 11128 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11129 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11130 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11131 | } finally { |
| 11132 | Binder.restoreCallingIdentity(identity); |
| 11133 | } |
| 11134 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11135 | |
| 11136 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11137 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11138 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11139 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11140 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11141 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11142 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11143 | final long identity = Binder.clearCallingIdentity(); |
| 11144 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11145 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11146 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11147 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11148 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11149 | } finally { |
| 11150 | Binder.restoreCallingIdentity(identity); |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11155 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11156 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11157 | enforceModifyPermission(); |
| 11158 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11159 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11160 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11161 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11162 | final long identity = Binder.clearCallingIdentity(); |
| 11163 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11164 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11165 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11166 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11167 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11168 | } finally { |
| 11169 | Binder.restoreCallingIdentity(identity); |
| 11170 | } |
| 11171 | } |
| 11172 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11173 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11174 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11175 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11176 | * otherwise. |
| 11177 | */ |
| 11178 | @Override |
| 11179 | public void setCepEnabled(boolean isCepEnabled) { |
| 11180 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11181 | |
| 11182 | final long identity = Binder.clearCallingIdentity(); |
| 11183 | try { |
| 11184 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11185 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11186 | Phone defaultPhone = phone.getImsPhone(); |
| 11187 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11188 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11189 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11190 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11191 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11192 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11193 | + imsPhone.getMsisdn()); |
| 11194 | } |
| 11195 | } |
| 11196 | } finally { |
| 11197 | Binder.restoreCallingIdentity(identity); |
| 11198 | } |
| 11199 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11200 | |
| 11201 | /** |
| 11202 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11203 | * |
| 11204 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11205 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11206 | * before being read. |
| 11207 | */ |
| 11208 | @Override |
| 11209 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11210 | isCompressed) { |
| 11211 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11212 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11213 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11214 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11215 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11216 | |
| 11217 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11218 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11219 | Binder.getCallingUserHandle())) { |
| 11220 | if (!isImsAvailableOnDevice()) { |
| 11221 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11222 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11223 | throw new IllegalStateException("IMS not available on device."); |
| 11224 | } |
| 11225 | } else { |
| 11226 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11227 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11228 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11229 | } |
| 11230 | |
| 11231 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11232 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11233 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11234 | } finally { |
| 11235 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11236 | } |
| 11237 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11238 | |
| 11239 | @Override |
| 11240 | public boolean isIccLockEnabled(int subId) { |
| 11241 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11242 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11243 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11244 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11245 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11246 | // Now that all security checks passes, perform the operation as ourselves. |
| 11247 | final long identity = Binder.clearCallingIdentity(); |
| 11248 | try { |
| 11249 | Phone phone = getPhone(subId); |
| 11250 | if (phone != null && phone.getIccCard() != null) { |
| 11251 | return phone.getIccCard().getIccLockEnabled(); |
| 11252 | } else { |
| 11253 | return false; |
| 11254 | } |
| 11255 | } finally { |
| 11256 | Binder.restoreCallingIdentity(identity); |
| 11257 | } |
| 11258 | } |
| 11259 | |
| 11260 | /** |
| 11261 | * Set the ICC pin lock enabled or disabled. |
| 11262 | * |
| 11263 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11264 | * three cases: |
| 11265 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11266 | * successfully. |
| 11267 | * - Positive number and zero for remaining password attempts. |
| 11268 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11269 | * |
| 11270 | */ |
| 11271 | @Override |
| 11272 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11273 | enforceModifyPermission(); |
| 11274 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11275 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11276 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11277 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11278 | Phone phone = getPhone(subId); |
| 11279 | if (phone == null) { |
| 11280 | return 0; |
| 11281 | } |
| 11282 | // Now that all security checks passes, perform the operation as ourselves. |
| 11283 | final long identity = Binder.clearCallingIdentity(); |
| 11284 | try { |
| 11285 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11286 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11287 | return attemptsRemaining; |
| 11288 | |
| 11289 | } catch (Exception e) { |
| 11290 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11291 | } finally { |
| 11292 | Binder.restoreCallingIdentity(identity); |
| 11293 | } |
| 11294 | return 0; |
| 11295 | } |
| 11296 | |
| 11297 | /** |
| 11298 | * Change the ICC password used in ICC pin lock. |
| 11299 | * |
| 11300 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11301 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11302 | * - Positive number and zero for remaining password attempts. |
| 11303 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11304 | * |
| 11305 | */ |
| 11306 | @Override |
| 11307 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11308 | enforceModifyPermission(); |
| 11309 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11310 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11311 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11312 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11313 | Phone phone = getPhone(subId); |
| 11314 | if (phone == null) { |
| 11315 | return 0; |
| 11316 | } |
| 11317 | // Now that all security checks passes, perform the operation as ourselves. |
| 11318 | final long identity = Binder.clearCallingIdentity(); |
| 11319 | try { |
| 11320 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11321 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11322 | return attemptsRemaining; |
| 11323 | |
| 11324 | } catch (Exception e) { |
| 11325 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11326 | } finally { |
| 11327 | Binder.restoreCallingIdentity(identity); |
| 11328 | } |
| 11329 | return 0; |
| 11330 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11331 | |
| 11332 | /** |
| 11333 | * Request for receiving user activity notification |
| 11334 | */ |
| 11335 | @Override |
| 11336 | public void requestUserActivityNotification() { |
| 11337 | if (!mNotifyUserActivity.get() |
| 11338 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11339 | mNotifyUserActivity.set(true); |
| 11340 | } |
| 11341 | } |
| 11342 | |
| 11343 | /** |
| 11344 | * Called when userActivity is signalled in the power manager. |
| 11345 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11346 | */ |
| 11347 | @Override |
| 11348 | public void userActivity() { |
| 11349 | // *************************************** |
| 11350 | // * Inherited from PhoneWindowManager * |
| 11351 | // *************************************** |
| 11352 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11353 | // WITH ITS LOCKS HELD. |
| 11354 | // |
| 11355 | // This code must be VERY careful about the locks |
| 11356 | // it acquires. |
| 11357 | // In fact, the current code acquires way too many, |
| 11358 | // and probably has lurking deadlocks. |
| 11359 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11360 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11361 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11362 | } |
| 11363 | |
| 11364 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11365 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11366 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11367 | } |
| 11368 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11369 | |
| 11370 | @Override |
| 11371 | public boolean canConnectTo5GInDsdsMode() { |
| 11372 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11373 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11374 | |
| 11375 | @Override |
| 11376 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11377 | String callingFeatureId) { |
| 11378 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11379 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11380 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11381 | } |
| 11382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11383 | enforceTelephonyFeatureWithException(callingPackage, |
| 11384 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11385 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11386 | Phone phone = getPhone(subId); |
| 11387 | if (phone == null) { |
| 11388 | throw new RuntimeException("phone is not available"); |
| 11389 | } |
| 11390 | // Now that all security checks passes, perform the operation as ourselves. |
| 11391 | final long identity = Binder.clearCallingIdentity(); |
| 11392 | try { |
| 11393 | return phone.getEquivalentHomePlmns(); |
| 11394 | } finally { |
| 11395 | Binder.restoreCallingIdentity(identity); |
| 11396 | } |
| 11397 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11398 | |
| 11399 | @Override |
| 11400 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11401 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11402 | if (!mApp.getResources().getBoolean( |
| 11403 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11404 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11405 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11406 | "isRadioInterfaceCapabilitySupported"); |
| 11407 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11408 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11409 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11410 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11411 | if (radioInterfaceCapabilities == null) { |
| 11412 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11413 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11414 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11415 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11416 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11417 | @Override |
| 11418 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11419 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11420 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11421 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11422 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11423 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11424 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11425 | |
| 11426 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11427 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11428 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11429 | if (DBG) { |
| 11430 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11431 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11432 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11433 | } |
| 11434 | |
| 11435 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11436 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11437 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11438 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11439 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11440 | if (callback != null) { |
| 11441 | try { |
| 11442 | callback.onAuthenticationFailure( |
| 11443 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11444 | } catch (RemoteException exception) { |
| 11445 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11446 | } |
| 11447 | return; |
| 11448 | } |
| 11449 | } |
| 11450 | |
| 11451 | final long token = Binder.clearCallingIdentity(); |
| 11452 | try { |
| 11453 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11454 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11455 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11456 | } finally { |
| 11457 | Binder.restoreCallingIdentity(token); |
| 11458 | } |
| 11459 | } |
| 11460 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11461 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11462 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11463 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11464 | * requested radio power state will actually be set. See {@link |
| 11465 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11466 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11467 | * @param enable {@code true} if trying to turn radio on. |
| 11468 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11469 | * false}. |
| 11470 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11471 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11472 | boolean isPhoneAvailable = false; |
| 11473 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11474 | Phone phone = PhoneFactory.getPhone(i); |
| 11475 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11476 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11477 | isPhoneAvailable = true; |
| 11478 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11479 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11480 | |
| 11481 | // return true if successfully informed the phone object about the thermal radio power |
| 11482 | // request. |
| 11483 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11484 | } |
| 11485 | |
| 11486 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11487 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11488 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11489 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11490 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11491 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11492 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11493 | } |
| 11494 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11495 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11496 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11497 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11498 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11499 | } |
| 11500 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11501 | setDataEnabledForReason( |
| 11502 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11503 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11504 | if (isDataThrottlingSupported) { |
| 11505 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11506 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11507 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11508 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11509 | } else if (thermalMitigationResult |
| 11510 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11511 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11512 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11513 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11514 | } |
| 11515 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11516 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11517 | |
| 11518 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11519 | } |
| 11520 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11521 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11522 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11523 | for (String pckg : context.getResources() |
| 11524 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11525 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11526 | } |
| 11527 | } |
| 11528 | |
| 11529 | return sThermalMitigationAllowlistedPackages; |
| 11530 | } |
| 11531 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11532 | private boolean isAnyPhoneInEmergencyState() { |
| 11533 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11534 | if (tm.isInEmergencyCall()) { |
| 11535 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11536 | return true; |
| 11537 | } |
| 11538 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11539 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11540 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11541 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11542 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11543 | return true; |
| 11544 | } |
| 11545 | } |
| 11546 | |
| 11547 | return false; |
| 11548 | } |
| 11549 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11550 | /** |
| 11551 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11552 | * @param packageName name of package to be allowlisted |
| 11553 | * @param context |
| 11554 | */ |
| 11555 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11556 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11557 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11558 | } |
| 11559 | |
| 11560 | /** |
| 11561 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11562 | * @param packageName name of package to remove from allowlist |
| 11563 | * @param context |
| 11564 | */ |
| 11565 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11566 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11567 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11568 | } |
| 11569 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11570 | /** |
| 11571 | * Thermal mitigation request to control functionalities at modem. |
| 11572 | * |
| 11573 | * @param subId the id of the subscription. |
| 11574 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11575 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11576 | * |
| 11577 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11578 | */ |
| 11579 | @Override |
| 11580 | @ThermalMitigationResult |
| 11581 | public int sendThermalMitigationRequest( |
| 11582 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11583 | ThermalMitigationRequest thermalMitigationRequest, |
| 11584 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11585 | enforceModifyPermission(); |
| 11586 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11587 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11588 | |
| 11589 | enforceTelephonyFeatureWithException(callingPackage, |
| 11590 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11591 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11592 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11593 | .contains(callingPackage)) { |
| 11594 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11595 | + "calling package: " + callingPackage); |
| 11596 | } |
| 11597 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11598 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11599 | final long identity = Binder.clearCallingIdentity(); |
| 11600 | |
| 11601 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11602 | try { |
| 11603 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11604 | switch (thermalMitigationAction) { |
| 11605 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11606 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11607 | handleDataThrottlingRequest(subId, |
| 11608 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11609 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11610 | break; |
| 11611 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11612 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11613 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11614 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11615 | } |
| 11616 | |
| 11617 | // Ensure that radio is on. If not able to power on due to phone being |
| 11618 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11619 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11620 | thermalMitigationResult = |
| 11621 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11622 | break; |
| 11623 | } |
| 11624 | |
| 11625 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11626 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11627 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11628 | break; |
| 11629 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11630 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11631 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11632 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11633 | } |
| 11634 | |
| 11635 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11636 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11637 | Phone phone = getPhone(subId); |
| 11638 | if (phone == null) { |
| 11639 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11640 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11641 | break; |
| 11642 | } |
| 11643 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11644 | TelephonyConnectionService service = |
| 11645 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11646 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11647 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11648 | thermalMitigationResult = |
| 11649 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11650 | break; |
| 11651 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11652 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11653 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11654 | break; |
| 11655 | } |
| 11656 | } else { |
| 11657 | thermalMitigationResult = |
| 11658 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11659 | break; |
| 11660 | } |
| 11661 | |
| 11662 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11663 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11664 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11665 | thermalMitigationResult = |
| 11666 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11667 | break; |
| 11668 | } |
| 11669 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11670 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11671 | break; |
| 11672 | default: |
| 11673 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11674 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11675 | } |
| 11676 | } catch (IllegalArgumentException e) { |
| 11677 | throw e; |
| 11678 | } catch (Exception e) { |
| 11679 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11680 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11681 | } finally { |
| 11682 | Binder.restoreCallingIdentity(identity); |
| 11683 | } |
| 11684 | |
| 11685 | if (DBG) { |
| 11686 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11687 | + thermalMitigationResult); |
| 11688 | } |
| 11689 | |
| 11690 | return thermalMitigationResult; |
| 11691 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11692 | |
| 11693 | /** |
| 11694 | * Set the GbaService Package Name that Telephony will bind to. |
| 11695 | * |
| 11696 | * @param subId The sim that the GbaService is associated with. |
| 11697 | * @param packageName The name of the package to be replaced with. |
| 11698 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11699 | */ |
| 11700 | @Override |
| 11701 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11702 | enforceModifyPermission(); |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11703 | int userId = ActivityManager.getCurrentUser(); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11704 | final long identity = Binder.clearCallingIdentity(); |
| 11705 | try { |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11706 | return getGbaManager(subId).overrideServicePackage(packageName, userId); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11707 | } finally { |
| 11708 | Binder.restoreCallingIdentity(identity); |
| 11709 | } |
| 11710 | } |
| 11711 | |
| 11712 | /** |
| 11713 | * Return the package name of the currently bound GbaService. |
| 11714 | * |
| 11715 | * @param subId The sim that the GbaService is associated with. |
| 11716 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11717 | */ |
| 11718 | @Override |
| 11719 | public String getBoundGbaService(int subId) { |
| 11720 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11721 | |
| 11722 | final long identity = Binder.clearCallingIdentity(); |
| 11723 | try { |
| 11724 | return getGbaManager(subId).getServicePackage(); |
| 11725 | } finally { |
| 11726 | Binder.restoreCallingIdentity(identity); |
| 11727 | } |
| 11728 | } |
| 11729 | |
| 11730 | /** |
| 11731 | * Set the release time for telephony to unbind GbaService. |
| 11732 | * |
| 11733 | * @param subId The sim that the GbaService is associated with. |
| 11734 | * @param interval The release time to unbind GbaService by millisecond. |
| 11735 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11736 | */ |
| 11737 | @Override |
| 11738 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11739 | enforceModifyPermission(); |
| 11740 | |
| 11741 | final long identity = Binder.clearCallingIdentity(); |
| 11742 | try { |
| 11743 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11744 | } finally { |
| 11745 | Binder.restoreCallingIdentity(identity); |
| 11746 | } |
| 11747 | } |
| 11748 | |
| 11749 | /** |
| 11750 | * Return the release time for telephony to unbind GbaService. |
| 11751 | * |
| 11752 | * @param subId The sim that the GbaService is associated with. |
| 11753 | * @return The release time to unbind GbaService by millisecond. |
| 11754 | */ |
| 11755 | @Override |
| 11756 | public int getGbaReleaseTime(int subId) { |
| 11757 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11758 | |
| 11759 | final long identity = Binder.clearCallingIdentity(); |
| 11760 | try { |
| 11761 | return getGbaManager(subId).getReleaseTime(); |
| 11762 | } finally { |
| 11763 | Binder.restoreCallingIdentity(identity); |
| 11764 | } |
| 11765 | } |
| 11766 | |
| 11767 | private GbaManager getGbaManager(int subId) { |
| 11768 | GbaManager instance = GbaManager.getInstance(subId); |
| 11769 | if (instance == null) { |
| 11770 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11771 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11772 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11773 | } |
| 11774 | return instance; |
| 11775 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11776 | |
| 11777 | /** |
| 11778 | * indicate whether the device and the carrier can support |
| 11779 | * RCS VoLTE single registration. |
| 11780 | */ |
| 11781 | @Override |
| 11782 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11783 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11784 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11785 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11786 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11787 | |
| 11788 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11789 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11790 | } |
| 11791 | |
| 11792 | final long identity = Binder.clearCallingIdentity(); |
| 11793 | try { |
| 11794 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11795 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11796 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11797 | if (isCapable != null) { |
| 11798 | return isCapable; |
| 11799 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11800 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11801 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11802 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11803 | } finally { |
| 11804 | Binder.restoreCallingIdentity(identity); |
| 11805 | } |
| 11806 | } |
| 11807 | |
| 11808 | /** |
| 11809 | * Register RCS provisioning callback. |
| 11810 | */ |
| 11811 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11812 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11813 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11814 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11815 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11816 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11817 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11818 | |
| 11819 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11820 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11821 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11822 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11823 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11824 | Binder.getCallingUserHandle())) { |
| 11825 | if (!isImsAvailableOnDevice()) { |
| 11826 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11827 | "IMS not available on device."); |
| 11828 | } |
| 11829 | } else { |
| 11830 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11831 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11832 | } |
| 11833 | |
| 11834 | final long identity = Binder.clearCallingIdentity(); |
| 11835 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11836 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11837 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11838 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11839 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11840 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11841 | } finally { |
| 11842 | Binder.restoreCallingIdentity(identity); |
| 11843 | } |
| 11844 | } |
| 11845 | |
| 11846 | /** |
| 11847 | * Unregister RCS provisioning callback. |
| 11848 | */ |
| 11849 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11850 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11851 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11852 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11853 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11854 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11855 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11856 | |
| 11857 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11858 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11859 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11860 | |
| 11861 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11862 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11863 | Binder.getCallingUserHandle())) { |
| 11864 | if (!isImsAvailableOnDevice()) { |
| 11865 | // operation failed silently |
| 11866 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11867 | return; |
| 11868 | } |
| 11869 | } else { |
| 11870 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11871 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11872 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11873 | } |
| 11874 | |
| 11875 | final long identity = Binder.clearCallingIdentity(); |
| 11876 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11877 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11878 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11879 | } finally { |
| 11880 | Binder.restoreCallingIdentity(identity); |
| 11881 | } |
| 11882 | } |
| 11883 | |
| 11884 | /** |
| 11885 | * trigger RCS reconfiguration. |
| 11886 | */ |
| 11887 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11888 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11889 | "triggerRcsReconfiguration", |
| 11890 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11891 | |
| 11892 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11893 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11894 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11895 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11896 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11897 | Binder.getCallingUserHandle())) { |
| 11898 | if (!isImsAvailableOnDevice()) { |
| 11899 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11900 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11901 | throw new IllegalStateException("IMS not available on device."); |
| 11902 | } |
| 11903 | } else { |
| 11904 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11905 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11906 | } |
| 11907 | |
| 11908 | final long identity = Binder.clearCallingIdentity(); |
| 11909 | try { |
| 11910 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11911 | } finally { |
| 11912 | Binder.restoreCallingIdentity(identity); |
| 11913 | } |
| 11914 | } |
| 11915 | |
| 11916 | /** |
| 11917 | * Provide the client configuration parameters of the RCS application. |
| 11918 | */ |
| 11919 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11920 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11921 | "setRcsClientConfiguration", |
| 11922 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11923 | |
| 11924 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11925 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11926 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11927 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11928 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11929 | Binder.getCallingUserHandle())) { |
| 11930 | if (!isImsAvailableOnDevice()) { |
| 11931 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11932 | "IMS not available on device."); |
| 11933 | } |
| 11934 | } else { |
| 11935 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11936 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11937 | } |
| 11938 | |
| 11939 | final long identity = Binder.clearCallingIdentity(); |
| 11940 | |
| 11941 | try { |
| 11942 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11943 | if (configBinder == null) { |
| 11944 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11945 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11946 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11947 | } else { |
| 11948 | configBinder.setRcsClientConfiguration(rcc); |
| 11949 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11950 | |
| 11951 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11952 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11953 | } catch (RemoteException e) { |
| 11954 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11955 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11956 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11957 | } finally { |
| 11958 | Binder.restoreCallingIdentity(identity); |
| 11959 | } |
| 11960 | } |
| 11961 | |
| 11962 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11963 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11964 | */ |
| 11965 | @Override |
| 11966 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11967 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11968 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11969 | |
| 11970 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11971 | } |
| 11972 | |
| 11973 | /** |
| 11974 | * Gets the test mode for RCS VoLTE single registration. |
| 11975 | */ |
| 11976 | @Override |
| 11977 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11978 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11979 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11980 | |
| 11981 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11982 | } |
| 11983 | |
| 11984 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11985 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11986 | */ |
| 11987 | @Override |
| 11988 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11990 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11991 | enforceModifyPermission(); |
| 11992 | |
| 11993 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11994 | : Boolean.parseBoolean(enabledStr); |
| 11995 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11996 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11997 | } |
| 11998 | |
| 11999 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12000 | * Sends a device to device communication message. Only usable via shell. |
| 12001 | * @param message message to send. |
| 12002 | * @param value message value. |
| 12003 | */ |
| 12004 | @Override |
| 12005 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12006 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12007 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12008 | enforceModifyPermission(); |
| 12009 | |
| 12010 | final long identity = Binder.clearCallingIdentity(); |
| 12011 | try { |
| 12012 | TelephonyConnectionService service = |
| 12013 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12014 | if (service == null) { |
| 12015 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12016 | return; |
| 12017 | } |
| 12018 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12019 | } finally { |
| 12020 | Binder.restoreCallingIdentity(identity); |
| 12021 | } |
| 12022 | } |
| 12023 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12024 | /** |
| 12025 | * Sets the specified device to device transport active. |
| 12026 | * @param transport The transport to set active. |
| 12027 | */ |
| 12028 | @Override |
| 12029 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12031 | "setActiveDeviceToDeviceTransport"); |
| 12032 | enforceModifyPermission(); |
| 12033 | |
| 12034 | final long identity = Binder.clearCallingIdentity(); |
| 12035 | try { |
| 12036 | TelephonyConnectionService service = |
| 12037 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12038 | if (service == null) { |
| 12039 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12040 | return; |
| 12041 | } |
| 12042 | service.setActiveDeviceToDeviceTransport(transport); |
| 12043 | } finally { |
| 12044 | Binder.restoreCallingIdentity(identity); |
| 12045 | } |
| 12046 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12047 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12048 | @Override |
| 12049 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12051 | "setDeviceToDeviceForceEnabled"); |
| 12052 | |
| 12053 | final long identity = Binder.clearCallingIdentity(); |
| 12054 | try { |
| 12055 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12056 | p -> { |
| 12057 | Phone thePhone = p.getImsPhone(); |
| 12058 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12059 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12060 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12061 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12062 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12063 | (ImsPhoneCallTracker) tracker; |
| 12064 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12065 | } |
| 12066 | } |
| 12067 | } |
| 12068 | ); |
| 12069 | } finally { |
| 12070 | Binder.restoreCallingIdentity(identity); |
| 12071 | } |
| 12072 | } |
| 12073 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12074 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12075 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12076 | */ |
| 12077 | @Override |
| 12078 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12079 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12080 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12081 | } |
| 12082 | |
| 12083 | /** |
| 12084 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12085 | */ |
| 12086 | @Override |
| 12087 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12088 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12089 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12090 | enforceModifyPermission(); |
| 12091 | |
| 12092 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12093 | : Boolean.parseBoolean(enabledStr); |
| 12094 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12095 | subId, enabled); |
| 12096 | } |
| 12097 | |
| 12098 | /** |
| 12099 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12100 | */ |
| 12101 | @Override |
| 12102 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12103 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12104 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12105 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12106 | |
| 12107 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12108 | * Overrides the ims feature validation result |
| 12109 | */ |
| 12110 | @Override |
| 12111 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12112 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12113 | "setImsFeatureValidationOverride"); |
| 12114 | |
| 12115 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12116 | : Boolean.parseBoolean(enabledStr); |
| 12117 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12118 | subId, enabled); |
| 12119 | } |
| 12120 | |
| 12121 | /** |
| 12122 | * Gets the ims feature validation override value |
| 12123 | */ |
| 12124 | @Override |
| 12125 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12126 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12127 | "getImsFeatureValidationOverride"); |
| 12128 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12129 | } |
| 12130 | |
| 12131 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12132 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12133 | * their mobile plan. |
| 12134 | */ |
| 12135 | @Override |
| 12136 | public String getMobileProvisioningUrl() { |
| 12137 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12138 | final long identity = Binder.clearCallingIdentity(); |
| 12139 | try { |
| 12140 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12141 | } finally { |
| 12142 | Binder.restoreCallingIdentity(identity); |
| 12143 | } |
| 12144 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12145 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12146 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12147 | * Get the EAB contact from the EAB database. |
| 12148 | */ |
| 12149 | @Override |
| 12150 | public String getContactFromEab(String contact) { |
| 12151 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12152 | enforceModifyPermission(); |
| 12153 | final long identity = Binder.clearCallingIdentity(); |
| 12154 | try { |
| 12155 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12156 | } finally { |
| 12157 | Binder.restoreCallingIdentity(identity); |
| 12158 | } |
| 12159 | } |
| 12160 | |
| 12161 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12162 | * Get the EAB capability from the EAB database. |
| 12163 | */ |
| 12164 | @Override |
| 12165 | public String getCapabilityFromEab(String contact) { |
| 12166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12167 | enforceModifyPermission(); |
| 12168 | final long identity = Binder.clearCallingIdentity(); |
| 12169 | try { |
| 12170 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12171 | } finally { |
| 12172 | Binder.restoreCallingIdentity(identity); |
| 12173 | } |
| 12174 | } |
| 12175 | |
| 12176 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12177 | * Remove the EAB contacts from the EAB database. |
| 12178 | */ |
| 12179 | @Override |
| 12180 | public int removeContactFromEab(int subId, String contacts) { |
| 12181 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12182 | enforceModifyPermission(); |
| 12183 | final long identity = Binder.clearCallingIdentity(); |
| 12184 | try { |
| 12185 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12186 | } finally { |
| 12187 | Binder.restoreCallingIdentity(identity); |
| 12188 | } |
| 12189 | } |
| 12190 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12191 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12192 | public boolean getDeviceUceEnabled() { |
| 12193 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12194 | final long identity = Binder.clearCallingIdentity(); |
| 12195 | try { |
| 12196 | return mApp.getDeviceUceEnabled(); |
| 12197 | } finally { |
| 12198 | Binder.restoreCallingIdentity(identity); |
| 12199 | } |
| 12200 | } |
| 12201 | |
| 12202 | @Override |
| 12203 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12204 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12205 | final long identity = Binder.clearCallingIdentity(); |
| 12206 | try { |
| 12207 | mApp.setDeviceUceEnabled(isEnabled); |
| 12208 | } finally { |
| 12209 | Binder.restoreCallingIdentity(identity); |
| 12210 | } |
| 12211 | } |
| 12212 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12213 | /** |
| 12214 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12215 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12216 | */ |
| 12217 | // Used for SHELL command only right now. |
| 12218 | @Override |
| 12219 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12220 | List<String> featureTags) { |
| 12221 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12222 | "addUceRegistrationOverrideShell"); |
| 12223 | final long identity = Binder.clearCallingIdentity(); |
| 12224 | try { |
| 12225 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12226 | new ArraySet<>(featureTags)); |
| 12227 | } catch (ImsException e) { |
| 12228 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12229 | } finally { |
| 12230 | Binder.restoreCallingIdentity(identity); |
| 12231 | } |
| 12232 | } |
| 12233 | |
| 12234 | /** |
| 12235 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12236 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12237 | */ |
| 12238 | // Used for SHELL command only right now. |
| 12239 | @Override |
| 12240 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12241 | List<String> featureTags) { |
| 12242 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12243 | "removeUceRegistrationOverrideShell"); |
| 12244 | final long identity = Binder.clearCallingIdentity(); |
| 12245 | try { |
| 12246 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12247 | new ArraySet<>(featureTags)); |
| 12248 | } catch (ImsException e) { |
| 12249 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12250 | } finally { |
| 12251 | Binder.restoreCallingIdentity(identity); |
| 12252 | } |
| 12253 | } |
| 12254 | |
| 12255 | /** |
| 12256 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12257 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12258 | */ |
| 12259 | // Used for SHELL command only right now. |
| 12260 | @Override |
| 12261 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12262 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12263 | "clearUceRegistrationOverrideShell"); |
| 12264 | final long identity = Binder.clearCallingIdentity(); |
| 12265 | try { |
| 12266 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12267 | } catch (ImsException e) { |
| 12268 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12269 | } finally { |
| 12270 | Binder.restoreCallingIdentity(identity); |
| 12271 | } |
| 12272 | } |
| 12273 | |
| 12274 | /** |
| 12275 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12276 | */ |
| 12277 | // Used for SHELL command only right now. |
| 12278 | @Override |
| 12279 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12280 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12281 | "getLatestRcsContactUceCapabilityShell"); |
| 12282 | final long identity = Binder.clearCallingIdentity(); |
| 12283 | try { |
| 12284 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12285 | } catch (ImsException e) { |
| 12286 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12287 | } finally { |
| 12288 | Binder.restoreCallingIdentity(identity); |
| 12289 | } |
| 12290 | } |
| 12291 | |
| 12292 | /** |
| 12293 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12294 | * device does not have an active PUBLISH. |
| 12295 | */ |
| 12296 | // Used for SHELL command only right now. |
| 12297 | @Override |
| 12298 | public String getLastUcePidfXmlShell(int subId) { |
| 12299 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12300 | final long identity = Binder.clearCallingIdentity(); |
| 12301 | try { |
| 12302 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12303 | } catch (ImsException e) { |
| 12304 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12305 | } finally { |
| 12306 | Binder.restoreCallingIdentity(identity); |
| 12307 | } |
| 12308 | } |
| 12309 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12310 | /** |
| 12311 | * Remove UCE requests cannot be sent to the network status. |
| 12312 | */ |
| 12313 | // Used for SHELL command only right now. |
| 12314 | @Override |
| 12315 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12316 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12317 | final long identity = Binder.clearCallingIdentity(); |
| 12318 | try { |
| 12319 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12320 | } catch (ImsException e) { |
| 12321 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12322 | } finally { |
| 12323 | Binder.restoreCallingIdentity(identity); |
| 12324 | } |
| 12325 | } |
| 12326 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12327 | /** |
| 12328 | * Remove UCE requests cannot be sent to the network status. |
| 12329 | */ |
| 12330 | // Used for SHELL command only. |
| 12331 | @Override |
| 12332 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12333 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12334 | final long identity = Binder.clearCallingIdentity(); |
| 12335 | try { |
| 12336 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12337 | } catch (ImsException e) { |
| 12338 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12339 | } finally { |
| 12340 | Binder.restoreCallingIdentity(identity); |
| 12341 | } |
| 12342 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12343 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12344 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12345 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12346 | String callingPackage) { |
| 12347 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12348 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12349 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12350 | enforceTelephonyFeatureWithException(callingPackage, |
| 12351 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12352 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12353 | final int callingUid = Binder.getCallingUid(); |
| 12354 | // Verify that tha callingPackage belongs to the calling UID |
| 12355 | mApp.getSystemService(AppOpsManager.class) |
| 12356 | .checkPackage(callingUid, callingPackage); |
| 12357 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12358 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12359 | |
| 12360 | final long identity = Binder.clearCallingIdentity(); |
| 12361 | try { |
| 12362 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12363 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12364 | |
| 12365 | if (result instanceof IllegalStateException) { |
| 12366 | throw (IllegalStateException) result; |
| 12367 | } |
| 12368 | } finally { |
| 12369 | Binder.restoreCallingIdentity(identity); |
| 12370 | } |
| 12371 | } |
| 12372 | |
| 12373 | @Override |
| 12374 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12375 | String callingPackage) { |
| 12376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12377 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12378 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12379 | enforceTelephonyFeatureWithException(callingPackage, |
| 12380 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12381 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12382 | final int callingUid = Binder.getCallingUid(); |
| 12383 | // Verify that tha callingPackage belongs to the calling UID |
| 12384 | mApp.getSystemService(AppOpsManager.class) |
| 12385 | .checkPackage(callingUid, callingPackage); |
| 12386 | |
| 12387 | final long identity = Binder.clearCallingIdentity(); |
| 12388 | try { |
| 12389 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12390 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12391 | |
| 12392 | if (result instanceof IllegalStateException) { |
| 12393 | throw (IllegalStateException) result; |
| 12394 | } |
| 12395 | } finally { |
| 12396 | Binder.restoreCallingIdentity(identity); |
| 12397 | } |
| 12398 | } |
| 12399 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12400 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12401 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12402 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12403 | // phone/system process do not have further restriction on request |
| 12404 | return; |
| 12405 | } |
| 12406 | |
| 12407 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12408 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12409 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12410 | context.enforceCallingOrSelfPermission( |
| 12411 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12412 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12413 | } |
| 12414 | |
| 12415 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12416 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12417 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12418 | || info.isEnabled()) { |
| 12419 | throw new IllegalArgumentException( |
| 12420 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12421 | } |
| 12422 | |
| 12423 | // Thresholds length for each RAN need in range. This has been validated in |
| 12424 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12425 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12426 | final int[] thresholds = info.getThresholds(); |
| 12427 | Objects.requireNonNull(thresholds); |
| 12428 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12429 | || thresholds.length |
| 12430 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12431 | throw new IllegalArgumentException( |
| 12432 | "thresholds length is out of range: " + thresholds.length); |
| 12433 | } |
| 12434 | } |
| 12435 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12436 | |
| 12437 | /** |
| 12438 | * Gets the current phone capability. |
| 12439 | * |
| 12440 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12441 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12442 | * It's used to evaluate possible phone config change, for example from single |
| 12443 | * SIM device to multi-SIM device. |
| 12444 | */ |
| 12445 | @Override |
| 12446 | public PhoneCapability getPhoneCapability() { |
| 12447 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12448 | |
| 12449 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12450 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12451 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12452 | final long identity = Binder.clearCallingIdentity(); |
| 12453 | try { |
| 12454 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12455 | } finally { |
| 12456 | Binder.restoreCallingIdentity(identity); |
| 12457 | } |
| 12458 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12459 | |
| 12460 | /** |
| 12461 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12462 | * required to be done shortly after the API is invoked. |
| 12463 | */ |
| 12464 | @Override |
| 12465 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12466 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12467 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12468 | enforceRebootPermission(); |
| 12469 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12470 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12471 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12472 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12473 | final long identity = Binder.clearCallingIdentity(); |
| 12474 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12475 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12476 | } finally { |
| 12477 | Binder.restoreCallingIdentity(identity); |
| 12478 | } |
| 12479 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12480 | |
| 12481 | /** |
| 12482 | * Request to get the current slicing configuration including URSP rules and |
| 12483 | * NSSAIs (configured, allowed and rejected). |
| 12484 | * |
| 12485 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12486 | */ |
| 12487 | @Override |
| 12488 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12489 | TelephonyPermissions |
| 12490 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12491 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12492 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12493 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12494 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12495 | "getSlicingConfig"); |
| 12496 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12497 | final long identity = Binder.clearCallingIdentity(); |
| 12498 | try { |
| 12499 | Phone phone = getDefaultPhone(); |
| 12500 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12501 | } finally { |
| 12502 | Binder.restoreCallingIdentity(identity); |
| 12503 | } |
| 12504 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12505 | |
| 12506 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12507 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12508 | * |
| 12509 | * @param capability The premium capability to check. |
| 12510 | * @param subId The subId to check the premium capability for. |
| 12511 | * |
| 12512 | * @return Whether the given premium capability is available to purchase. |
| 12513 | */ |
| 12514 | @Override |
| 12515 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12516 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12517 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12518 | log("Premium capability " |
| 12519 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12520 | + " is not available for purchase due to missing permissions."); |
| 12521 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12522 | + "permission READ_BASIC_PHONE_STATE."); |
| 12523 | } |
| 12524 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12525 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12526 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12527 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12528 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12529 | if (phone == null) { |
| 12530 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12531 | return false; |
| 12532 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12533 | final long identity = Binder.clearCallingIdentity(); |
| 12534 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12535 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12536 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12537 | } finally { |
| 12538 | Binder.restoreCallingIdentity(identity); |
| 12539 | } |
| 12540 | } |
| 12541 | |
| 12542 | /** |
| 12543 | * Purchase the given premium capability from the carrier. |
| 12544 | * |
| 12545 | * @param capability The premium capability to purchase. |
| 12546 | * @param callback The result of the purchase request. |
| 12547 | * @param subId The subId to purchase the premium capability for. |
| 12548 | */ |
| 12549 | @Override |
| 12550 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12551 | log("purchasePremiumCapability: capability=" |
| 12552 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12553 | + getCurrentPackageName()); |
| 12554 | |
| 12555 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12556 | mApp, "purchasePremiumCapability")) { |
| 12557 | log("purchasePremiumCapability " |
| 12558 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12559 | + " failed due to missing permissions."); |
| 12560 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12561 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12562 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12563 | mApp, "purchasePremiumCapability")) { |
| 12564 | log("purchasePremiumCapability " |
| 12565 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12566 | + " failed due to missing permissions."); |
| 12567 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12568 | } |
| 12569 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12570 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12571 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12572 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12573 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12574 | if (phone == null) { |
| 12575 | try { |
| 12576 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12577 | callback.accept(result); |
| 12578 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12579 | } catch (RemoteException e) { |
| 12580 | String logStr = "Purchase premium capability " |
| 12581 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12582 | + " failed due to RemoteException handling null phone: " + e; |
| 12583 | if (DBG) log(logStr); |
| 12584 | AnomalyReporter.reportAnomaly( |
| 12585 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12586 | } |
| 12587 | return; |
| 12588 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12589 | |
| 12590 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12591 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12592 | if (mFeatureFlags.hsumPackageManager()) { |
| 12593 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12594 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12595 | } else { |
| 12596 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12597 | getCurrentPackageName(), 0).processName; |
| 12598 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12599 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12600 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12601 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12602 | |
| 12603 | boolean isVisible = false; |
| 12604 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12605 | if (am != null) { |
| 12606 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12607 | if (processes != null) { |
| 12608 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12609 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12610 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12611 | if (process.processName.equals(callingProcess) && process.importance |
| 12612 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12613 | isVisible = true; |
| 12614 | break; |
| 12615 | } |
| 12616 | } |
| 12617 | } |
| 12618 | } |
| 12619 | |
| 12620 | if (!isVisible) { |
| 12621 | try { |
| 12622 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12623 | callback.accept(result); |
| 12624 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12625 | } catch (RemoteException e) { |
| 12626 | String logStr = "Purchase premium capability " |
| 12627 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12628 | + " failed due to RemoteException handling background application: " + e; |
| 12629 | if (DBG) log(logStr); |
| 12630 | AnomalyReporter.reportAnomaly( |
| 12631 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12632 | } |
| 12633 | return; |
| 12634 | } |
| 12635 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12636 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12637 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12638 | } |
| 12639 | |
| 12640 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12641 | * Register an IMS connection state callback |
| 12642 | */ |
| 12643 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12644 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12645 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12646 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12647 | // ImsMmTelManager |
| 12648 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12649 | TelephonyPermissions |
| 12650 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12651 | mApp, subId, "registerImsStateCallback"); |
| 12652 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12653 | // ImsRcsManager or SipDelegateManager |
| 12654 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12655 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12656 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12657 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12658 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12659 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12660 | } |
| 12661 | |
| 12662 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12663 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12664 | "IMS not available on device."); |
| 12665 | } |
| 12666 | |
| 12667 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12668 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12669 | } |
| 12670 | |
| 12671 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12672 | if (controller == null) { |
| 12673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12674 | "IMS not available on device."); |
| 12675 | } |
| 12676 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12677 | if (callingPackage == null) { |
| 12678 | callingPackage = getCurrentPackageName(); |
| 12679 | } |
| 12680 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12681 | final long token = Binder.clearCallingIdentity(); |
| 12682 | try { |
| 12683 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12684 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12685 | } catch (ImsException e) { |
| 12686 | throw new ServiceSpecificException(e.getCode()); |
| 12687 | } finally { |
| 12688 | Binder.restoreCallingIdentity(token); |
| 12689 | } |
| 12690 | } |
| 12691 | |
| 12692 | /** |
| 12693 | * Unregister an IMS connection state callback |
| 12694 | */ |
| 12695 | @Override |
| 12696 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12697 | final long token = Binder.clearCallingIdentity(); |
| 12698 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12699 | if (controller == null) { |
| 12700 | return; |
| 12701 | } |
| 12702 | try { |
| 12703 | controller.unregisterImsStateCallback(cb); |
| 12704 | } finally { |
| 12705 | Binder.restoreCallingIdentity(token); |
| 12706 | } |
| 12707 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12708 | |
| 12709 | /** |
| 12710 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12711 | * |
| 12712 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12713 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12714 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12715 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12716 | * If there is current registered network this value will be same as the registered cell |
| 12717 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12718 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12719 | * it will be cleared and null will be returned. |
| 12720 | * |
| 12721 | */ |
| 12722 | @Override |
| 12723 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12724 | String callingFeatureId) { |
| 12725 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12726 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12727 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12728 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12729 | .setCallingPackage(callingPackage) |
| 12730 | .setCallingFeatureId(callingFeatureId) |
| 12731 | .setCallingPid(Binder.getCallingPid()) |
| 12732 | .setCallingUid(Binder.getCallingUid()) |
| 12733 | .setMethod("getLastKnownCellIdentity") |
| 12734 | .setLogAsInfo(true) |
| 12735 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12736 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12737 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12738 | .build()); |
| 12739 | |
| 12740 | boolean hasFinePermission = |
| 12741 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12742 | if (!hasFinePermission |
| 12743 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12744 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12745 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12746 | } |
| 12747 | |
| 12748 | final long identity = Binder.clearCallingIdentity(); |
| 12749 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12750 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12751 | if (sst == null) return null; |
| 12752 | return sst.getLastKnownCellIdentity(); |
| 12753 | } finally { |
| 12754 | Binder.restoreCallingIdentity(identity); |
| 12755 | } |
| 12756 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12757 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12758 | /** |
| 12759 | * Sets the modem service class Name that Telephony will bind to. |
| 12760 | * |
| 12761 | * @param serviceName The class name of the modem service. |
| 12762 | * @return true if the operation is succeed, otherwise false. |
| 12763 | */ |
| 12764 | public boolean setModemService(String serviceName) { |
| 12765 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12766 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12768 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12769 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12770 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12771 | } |
| 12772 | |
| 12773 | /** |
| 12774 | * Return the class name of the currently bounded modem service. |
| 12775 | * |
| 12776 | * @return the class name of the modem service. |
| 12777 | */ |
| 12778 | public String getModemService() { |
| 12779 | String result; |
| 12780 | Log.d(LOG_TAG, "getModemService"); |
| 12781 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12782 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12783 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12784 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12785 | "getModemService"); |
| 12786 | result = mPhoneConfigurationManager.getModemService(); |
| 12787 | Log.d(LOG_TAG, "result = " + result); |
| 12788 | return result; |
| 12789 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12790 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12791 | /** |
| 12792 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12793 | * including carrier config, entitlement server, and config update. |
| 12794 | * |
| 12795 | * @param subId subId The subscription ID of the carrier. |
| 12796 | * |
| 12797 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12798 | * be returned. |
| 12799 | * |
| 12800 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12801 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12802 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12803 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12804 | final long identity = Binder.clearCallingIdentity(); |
| 12805 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12806 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12807 | } finally { |
| 12808 | Binder.restoreCallingIdentity(identity); |
| 12809 | } |
| 12810 | } |
| 12811 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12812 | @Override |
| 12813 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12814 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12815 | mApp.enforceCallingOrSelfPermission( |
| 12816 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12817 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12818 | |
| 12819 | final long identity = Binder.clearCallingIdentity(); |
| 12820 | try { |
| 12821 | Phone phone = getPhone(subId); |
| 12822 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12823 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12824 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12825 | phone.setVoiceServiceStateOverride(hasService); |
| 12826 | } finally { |
| 12827 | Binder.restoreCallingIdentity(identity); |
| 12828 | } |
| 12829 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12830 | |
| 12831 | /** |
| 12832 | * set removable eSIM as default eUICC. |
| 12833 | * |
| 12834 | * @hide |
| 12835 | */ |
| 12836 | @Override |
| 12837 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12838 | enforceModifyPermission(); |
| 12839 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12840 | |
| 12841 | final long identity = Binder.clearCallingIdentity(); |
| 12842 | try { |
| 12843 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12844 | } finally { |
| 12845 | Binder.restoreCallingIdentity(identity); |
| 12846 | } |
| 12847 | } |
| 12848 | |
| 12849 | /** |
| 12850 | * Returns whether the removable eSIM is default eUICC or not. |
| 12851 | * |
| 12852 | * @hide |
| 12853 | */ |
| 12854 | @Override |
| 12855 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12856 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12857 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12858 | |
| 12859 | final long identity = Binder.clearCallingIdentity(); |
| 12860 | try { |
| 12861 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12862 | } finally { |
| 12863 | Binder.restoreCallingIdentity(identity); |
| 12864 | } |
| 12865 | } |
| 12866 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12867 | /** |
| 12868 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12869 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12870 | * application currently configured for this user. |
| 12871 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12872 | * {@code null} if the functionality is not supported. |
| 12873 | * @hide |
| 12874 | */ |
| 12875 | @Override |
| 12876 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12877 | boolean updateIfNeeded) { |
| 12878 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12879 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12880 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12881 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12882 | "getDefaultRespondViaMessageApplication"); |
| 12883 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12884 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12885 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12886 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12887 | UserHandle mainUser = null; |
| 12888 | Context userContext = null; |
| 12889 | final long identity = Binder.clearCallingIdentity(); |
| 12890 | try { |
| 12891 | mainUser = mUserManager.getMainUser(); |
| 12892 | userContext = context.createContextAsUser(mainUser, 0); |
| 12893 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12894 | } finally { |
| 12895 | Binder.restoreCallingIdentity(identity); |
| 12896 | } |
| 12897 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12898 | updateIfNeeded, mainUser); |
| 12899 | } else { |
| 12900 | UserHandle userHandle = null; |
| 12901 | final long identity = Binder.clearCallingIdentity(); |
| 12902 | try { |
| 12903 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12904 | } finally { |
| 12905 | Binder.restoreCallingIdentity(identity); |
| 12906 | } |
| 12907 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12908 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12909 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12910 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12911 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12912 | |
| 12913 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12914 | * Set whether the device is able to connect with null ciphering or integrity |
| 12915 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12916 | * and all new subscriptions after this. |
| 12917 | * |
| 12918 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12919 | * @hide |
| 12920 | */ |
| 12921 | @Override |
| 12922 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12923 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12924 | enforceModifyPermission(); |
| 12925 | checkForNullCipherAndIntegritySupport(); |
| 12926 | |
| 12927 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12928 | // for listening to these preference changes and applying them immediately. |
| 12929 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12930 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12931 | editor.apply(); |
| 12932 | |
| 12933 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12934 | phone.handleNullCipherEnabledChange(); |
| 12935 | } |
| 12936 | } |
| 12937 | |
| 12938 | |
| 12939 | /** |
| 12940 | * Get whether the device is able to connect with null ciphering or integrity |
| 12941 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12942 | * the state of the radio. |
| 12943 | * |
| 12944 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12945 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12946 | * version for this feature. |
| 12947 | * @hide |
| 12948 | */ |
| 12949 | @Override |
| 12950 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12951 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12952 | enforceReadPermission(); |
| 12953 | checkForNullCipherAndIntegritySupport(); |
| 12954 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12955 | } |
| 12956 | |
| 12957 | private void checkForNullCipherAndIntegritySupport() { |
| 12958 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12959 | throw new UnsupportedOperationException( |
| 12960 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12961 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12962 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12963 | throw new UnsupportedOperationException( |
| 12964 | "Null cipher and integrity operations unsupported by modem"); |
| 12965 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12966 | } |
| 12967 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12968 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12969 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12970 | throw new UnsupportedOperationException( |
| 12971 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12972 | + "above"); |
| 12973 | } |
| 12974 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12975 | throw new UnsupportedOperationException( |
| 12976 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12977 | } |
| 12978 | } |
| 12979 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12980 | private void checkForNullCipherNotificationSupport() { |
| 12981 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12982 | throw new UnsupportedOperationException( |
| 12983 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12984 | } |
| 12985 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12986 | throw new UnsupportedOperationException( |
| 12987 | "Null cipher notification operations unsupported by modem"); |
| 12988 | } |
| 12989 | } |
| 12990 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12991 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12992 | * Get the SIM state for the slot index. |
| 12993 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12994 | * |
| 12995 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12996 | */ |
| 12997 | @Override |
| 12998 | @SimState |
| 12999 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 13000 | if (!mApp.getResources().getBoolean( |
| 13001 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 13002 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13003 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13004 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13005 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13006 | IccCardConstants.State simState; |
| 13007 | if (slotIndex < 0) { |
| 13008 | simState = IccCardConstants.State.UNKNOWN; |
| 13009 | } else { |
| 13010 | Phone phone = null; |
| 13011 | try { |
| 13012 | phone = PhoneFactory.getPhone(slotIndex); |
| 13013 | } catch (IllegalStateException e) { |
| 13014 | // ignore |
| 13015 | } |
| 13016 | if (phone == null) { |
| 13017 | simState = IccCardConstants.State.UNKNOWN; |
| 13018 | } else { |
| 13019 | IccCard icc = phone.getIccCard(); |
| 13020 | if (icc == null) { |
| 13021 | simState = IccCardConstants.State.UNKNOWN; |
| 13022 | } else { |
| 13023 | simState = icc.getState(); |
| 13024 | } |
| 13025 | } |
| 13026 | } |
| 13027 | return simState.ordinal(); |
| 13028 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13029 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13030 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13031 | boolean enableLogcat, |
| 13032 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13033 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13034 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13035 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13036 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13037 | ecdDataBuilder |
| 13038 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13039 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13040 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13041 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13042 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13043 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13044 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13045 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13046 | Executors.newCachedThreadPool(), db, |
| 13047 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13048 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13049 | } |
| 13050 | |
| 13051 | /** |
| 13052 | * Request telephony to persist state for debugging emergency call failures. |
| 13053 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13054 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13055 | * @param enableLogcat whether to collect logcat output |
| 13056 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13057 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13058 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13059 | */ |
| 13060 | @Override |
| 13061 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13062 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13063 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13064 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13065 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13066 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13067 | && Flags.enableReadDropboxPermission()) { |
| 13068 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13069 | "persistEmergencyCallDiagnosticData"); |
| 13070 | } else { |
| 13071 | // Otherwise, enforce legacy permission. |
| 13072 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13073 | "persistEmergencyCallDiagnosticData"); |
| 13074 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13075 | final long identity = Binder.clearCallingIdentity(); |
| 13076 | try { |
| 13077 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13078 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13079 | |
| 13080 | } finally { |
| 13081 | Binder.restoreCallingIdentity(identity); |
| 13082 | } |
| 13083 | } |
| 13084 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13085 | /** |
| 13086 | * Get current cell broadcast ranges. |
| 13087 | */ |
| 13088 | @Override |
| 13089 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13090 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13091 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13092 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13093 | |
| 13094 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13095 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13096 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13097 | final long identity = Binder.clearCallingIdentity(); |
| 13098 | try { |
| 13099 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13100 | } finally { |
| 13101 | Binder.restoreCallingIdentity(identity); |
| 13102 | } |
| 13103 | } |
| 13104 | |
| 13105 | /** |
| 13106 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13107 | * |
| 13108 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13109 | */ |
| 13110 | @Override |
| 13111 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13112 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13113 | @Nullable IIntegerConsumer callback) { |
| 13114 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13115 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13116 | |
| 13117 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13118 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13119 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13120 | final long identity = Binder.clearCallingIdentity(); |
| 13121 | try { |
| 13122 | Phone phone = getPhoneFromSubId(subId); |
| 13123 | if (DBG) { |
| 13124 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13125 | } |
| 13126 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13127 | if (callback != null) { |
| 13128 | try { |
| 13129 | callback.accept(result); |
| 13130 | } catch (RemoteException e) { |
| 13131 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13132 | } |
| 13133 | } |
| 13134 | }); |
| 13135 | } finally { |
| 13136 | Binder.restoreCallingIdentity(identity); |
| 13137 | } |
| 13138 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13139 | |
| 13140 | /** |
| 13141 | * Returns whether the device supports the domain selection service. |
| 13142 | * |
| 13143 | * @return {@code true} if the device supports the domain selection service. |
| 13144 | */ |
| 13145 | @Override |
| 13146 | public boolean isDomainSelectionSupported() { |
| 13147 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13148 | "isDomainSelectionSupported"); |
| 13149 | |
| 13150 | final long identity = Binder.clearCallingIdentity(); |
| 13151 | try { |
| 13152 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13153 | } finally { |
| 13154 | Binder.restoreCallingIdentity(identity); |
| 13155 | } |
| 13156 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13157 | |
| 13158 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13159 | * Returns whether the AOSP domain selection service is supported. |
| 13160 | * |
| 13161 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13162 | * {@code false} otherwise. |
| 13163 | */ |
| 13164 | @Override |
| 13165 | public boolean isAospDomainSelectionService() { |
| 13166 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13167 | "isAospDomainSelectionService"); |
| 13168 | |
| 13169 | final long identity = Binder.clearCallingIdentity(); |
| 13170 | try { |
| 13171 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13172 | String dssComponentName = mApp.getResources().getString( |
| 13173 | R.string.config_domain_selection_service_component_name); |
| 13174 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13175 | TelephonyDomainSelectionService.class.getName()); |
| 13176 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13177 | + ", aosp=" + componentName.flattenToString()); |
| 13178 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13179 | } |
| 13180 | } finally { |
| 13181 | Binder.restoreCallingIdentity(identity); |
| 13182 | } |
| 13183 | return false; |
| 13184 | } |
| 13185 | |
| 13186 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13187 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13188 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13189 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13190 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13191 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13192 | * {@code false} to disable. |
| 13193 | * @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] | 13194 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13195 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13196 | * |
| 13197 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13198 | */ |
| 13199 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13200 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13201 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13202 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13203 | final long identity = Binder.clearCallingIdentity(); |
| 13204 | try { |
| 13205 | if (enableSatellite) { |
| 13206 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13207 | @Override |
| 13208 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13209 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13210 | + ", resultData=" + resultData); |
| 13211 | boolean isAllowed = false; |
| 13212 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13213 | callback::accept); |
| 13214 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13215 | if (resultData != null |
| 13216 | && resultData.containsKey( |
| 13217 | KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13218 | isAllowed = resultData.getBoolean( |
| 13219 | KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13220 | } else { |
| 13221 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13222 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13223 | } else { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13224 | result.accept(resultCode); |
| 13225 | return; |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13226 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13227 | if (isAllowed) { |
| 13228 | mSatelliteController.requestSatelliteEnabled( |
| 13229 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13230 | } else { |
| 13231 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13232 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13233 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13234 | }; |
| 13235 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
| 13236 | resultReceiver, true); |
| 13237 | } else { |
| 13238 | // No need to check if satellite is allowed at current location when disabling |
| 13239 | // satellite |
| 13240 | mSatelliteController.requestSatelliteEnabled( |
| 13241 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13242 | } |
| 13243 | } finally { |
| 13244 | Binder.restoreCallingIdentity(identity); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13245 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13246 | } |
| 13247 | |
| 13248 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13249 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13250 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13251 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13252 | * 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] | 13253 | * |
| 13254 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13255 | */ |
| 13256 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13257 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13258 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13259 | final long identity = Binder.clearCallingIdentity(); |
| 13260 | try { |
| 13261 | mSatelliteController.requestIsSatelliteEnabled(result); |
| 13262 | } finally { |
| 13263 | Binder.restoreCallingIdentity(identity); |
| 13264 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13265 | } |
| 13266 | |
| 13267 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13268 | * Request to get whether the satellite service demo mode is enabled. |
| 13269 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13270 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13271 | * if the request is successful or an error code if the request failed. |
| 13272 | * |
| 13273 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13274 | */ |
| 13275 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13276 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13277 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13278 | final long identity = Binder.clearCallingIdentity(); |
| 13279 | try { |
| 13280 | mSatelliteController.requestIsDemoModeEnabled(result); |
| 13281 | } finally { |
| 13282 | Binder.restoreCallingIdentity(identity); |
| 13283 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13284 | } |
| 13285 | |
| 13286 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13287 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13288 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13289 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13290 | * enabled if the request is successful or an error code if the request failed. |
| 13291 | * |
| 13292 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13293 | */ |
| 13294 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13295 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13296 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13297 | final long identity = Binder.clearCallingIdentity(); |
| 13298 | try { |
| 13299 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
| 13300 | } finally { |
| 13301 | Binder.restoreCallingIdentity(identity); |
| 13302 | } |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13303 | } |
| 13304 | |
| 13305 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13306 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13307 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13308 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13309 | * 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^] | 13310 | * |
| 13311 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13312 | */ |
| 13313 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13314 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13315 | enforceSatelliteCommunicationPermission("requestIsSatelliteSupported"); |
| 13316 | final long identity = Binder.clearCallingIdentity(); |
| 13317 | try { |
| 13318 | mSatelliteController.requestIsSatelliteSupported(result); |
| 13319 | } finally { |
| 13320 | Binder.restoreCallingIdentity(identity); |
| 13321 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13322 | } |
| 13323 | |
| 13324 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13325 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13326 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13327 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13328 | * 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] | 13329 | * |
| 13330 | * @throws SecurityException if the caller doesn't have required permission. |
| 13331 | */ |
| 13332 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13333 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13334 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13335 | final long identity = Binder.clearCallingIdentity(); |
| 13336 | try { |
| 13337 | mSatelliteController.requestSatelliteCapabilities(result); |
| 13338 | } finally { |
| 13339 | Binder.restoreCallingIdentity(identity); |
| 13340 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13341 | } |
| 13342 | |
| 13343 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13344 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13345 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13346 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13347 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13348 | * @param resultCallback The callback to get the result of the request. |
| 13349 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13350 | * |
| 13351 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13352 | */ |
| 13353 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13354 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13355 | @NonNull IIntegerConsumer resultCallback, |
| 13356 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13357 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13358 | final long identity = Binder.clearCallingIdentity(); |
| 13359 | try { |
| 13360 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
| 13361 | } finally { |
| 13362 | Binder.restoreCallingIdentity(identity); |
| 13363 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13364 | } |
| 13365 | |
| 13366 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13367 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13368 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13369 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13370 | * @param resultCallback The callback to get the result of the request. |
| 13371 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13372 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13373 | * |
| 13374 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13375 | */ |
| 13376 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13377 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13378 | @NonNull IIntegerConsumer resultCallback, |
| 13379 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13380 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13381 | final long identity = Binder.clearCallingIdentity(); |
| 13382 | try { |
| 13383 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
| 13384 | } finally { |
| 13385 | Binder.restoreCallingIdentity(identity); |
| 13386 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13387 | } |
| 13388 | |
| 13389 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13390 | * Register the subscription with a satellite provider. |
| 13391 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13392 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13393 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13394 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13395 | * @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] | 13396 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13397 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13398 | * @return The signal transport used by the caller to cancel the provision request, |
| 13399 | * or {@code null} if the request failed. |
| 13400 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13401 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13402 | */ |
| 13403 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13404 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13405 | @NonNull String token, @NonNull byte[] provisionData, |
| 13406 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13407 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13408 | final long identity = Binder.clearCallingIdentity(); |
| 13409 | try { |
| 13410 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13411 | callback); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13412 | } finally { |
| 13413 | Binder.restoreCallingIdentity(identity); |
| 13414 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13415 | } |
| 13416 | |
| 13417 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13418 | * Unregister the device/subscription with the satellite provider. |
| 13419 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13420 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13421 | * should report as deprovisioned. |
| 13422 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13423 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13424 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13425 | * |
| 13426 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13427 | */ |
| 13428 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13429 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13430 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13431 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13432 | final long identity = Binder.clearCallingIdentity(); |
| 13433 | try { |
| 13434 | mSatelliteController.deprovisionSatelliteService(token, callback); |
| 13435 | } finally { |
| 13436 | Binder.restoreCallingIdentity(identity); |
| 13437 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13438 | } |
| 13439 | |
| 13440 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13441 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13442 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13443 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13444 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13445 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13446 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13447 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13448 | */ |
| 13449 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13450 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13451 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13452 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13453 | final long identity = Binder.clearCallingIdentity(); |
| 13454 | try { |
| 13455 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
| 13456 | } finally { |
| 13457 | Binder.restoreCallingIdentity(identity); |
| 13458 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13459 | } |
| 13460 | |
| 13461 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13462 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13463 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13464 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13465 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13466 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13467 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13468 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13469 | */ |
| 13470 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13471 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13472 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13473 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13474 | final long identity = Binder.clearCallingIdentity(); |
| 13475 | try { |
| 13476 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
| 13477 | } finally { |
| 13478 | Binder.restoreCallingIdentity(identity); |
| 13479 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13480 | } |
| 13481 | |
| 13482 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13483 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13484 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13485 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13486 | * satellite provider if the request is successful or an error code if the |
| 13487 | * request failed. |
| 13488 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13489 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13490 | */ |
| 13491 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13492 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13493 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13494 | final long identity = Binder.clearCallingIdentity(); |
| 13495 | try { |
| 13496 | mSatelliteController.requestIsSatelliteProvisioned(result); |
| 13497 | } finally { |
| 13498 | Binder.restoreCallingIdentity(identity); |
| 13499 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13500 | } |
| 13501 | |
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 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13504 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13505 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13506 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13507 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13508 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13509 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13510 | */ |
| 13511 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13512 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13513 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13514 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13515 | final long identity = Binder.clearCallingIdentity(); |
| 13516 | try { |
| 13517 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
| 13518 | } finally { |
| 13519 | Binder.restoreCallingIdentity(identity); |
| 13520 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13521 | } |
| 13522 | |
| 13523 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13524 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13525 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13526 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13527 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13528 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13529 | * |
| 13530 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13531 | */ |
| 13532 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13533 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13534 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13535 | final long identity = Binder.clearCallingIdentity(); |
| 13536 | try { |
| 13537 | mSatelliteController.unregisterForModemStateChanged(callback); |
| 13538 | } finally { |
| 13539 | Binder.restoreCallingIdentity(identity); |
| 13540 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13541 | } |
| 13542 | |
| 13543 | /** |
| 13544 | * Register to receive incoming datagrams over satellite. |
| 13545 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13546 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13547 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13548 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13549 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13550 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13551 | */ |
| 13552 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13553 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13554 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13555 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13556 | final long identity = Binder.clearCallingIdentity(); |
| 13557 | try { |
| 13558 | return mSatelliteController.registerForIncomingDatagram(callback); |
| 13559 | } finally { |
| 13560 | Binder.restoreCallingIdentity(identity); |
| 13561 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13562 | } |
| 13563 | |
| 13564 | /** |
| 13565 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13566 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13567 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13568 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13569 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13570 | * |
| 13571 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13572 | */ |
| 13573 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13574 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13575 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13576 | final long identity = Binder.clearCallingIdentity(); |
| 13577 | try { |
| 13578 | mSatelliteController.unregisterForIncomingDatagram(callback); |
| 13579 | } finally { |
| 13580 | Binder.restoreCallingIdentity(identity); |
| 13581 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13582 | } |
| 13583 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13584 | /** |
| 13585 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13586 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13587 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13588 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13589 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13590 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13591 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13592 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13593 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13594 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13595 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13596 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13597 | final long identity = Binder.clearCallingIdentity(); |
| 13598 | try { |
| 13599 | mSatelliteController.pollPendingDatagrams(callback); |
| 13600 | } finally { |
| 13601 | Binder.restoreCallingIdentity(identity); |
| 13602 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13603 | } |
| 13604 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13605 | /** |
| 13606 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13607 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13608 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13609 | * input to this method. Datagram received here will be passed down to modem without any |
| 13610 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13611 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13612 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13613 | * SOS_SMS or LOCATION_SHARING. |
| 13614 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13615 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13616 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13617 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13618 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13619 | * |
| 13620 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13621 | */ |
| 13622 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13623 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13624 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13625 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13626 | enforceSatelliteCommunicationPermission("sendDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13627 | final long identity = Binder.clearCallingIdentity(); |
| 13628 | try { |
| 13629 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
| 13630 | callback); |
| 13631 | } finally { |
| 13632 | Binder.restoreCallingIdentity(identity); |
| 13633 | } |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13634 | } |
| 13635 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13636 | /** |
| 13637 | * Request to get whether satellite communication is allowed for the current location. |
| 13638 | * |
| 13639 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13640 | * allowed for the current location for. |
| 13641 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13642 | * for the current location if the request is successful or an error code |
| 13643 | * if the request failed. |
| 13644 | * |
| 13645 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13646 | */ |
| 13647 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13648 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13649 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13650 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13651 | final long identity = Binder.clearCallingIdentity(); |
| 13652 | try { |
| 13653 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, |
| 13654 | false); |
| 13655 | } finally { |
| 13656 | Binder.restoreCallingIdentity(identity); |
| 13657 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13658 | } |
| 13659 | |
| 13660 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13661 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13662 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13663 | * @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] | 13664 | * be visible if the request is successful or an error code if the request failed. |
| 13665 | * |
| 13666 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13667 | */ |
| 13668 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13669 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13670 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13671 | final long identity = Binder.clearCallingIdentity(); |
| 13672 | try { |
| 13673 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
| 13674 | } finally { |
| 13675 | Binder.restoreCallingIdentity(identity); |
| 13676 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13677 | } |
| 13678 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13679 | /** |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13680 | * 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] | 13681 | * |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13682 | * @param isAligned {@code true} Device is aligned with the satellite. |
| 13683 | * {@code false} Device fails to align with the satellite. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13684 | * |
| 13685 | * @throws SecurityException if the caller doesn't have required permission. |
| 13686 | */ |
| 13687 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13688 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13689 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13690 | enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite"); |
| 13691 | final long identity = Binder.clearCallingIdentity(); |
| 13692 | try { |
| 13693 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
| 13694 | } finally { |
| 13695 | Binder.restoreCallingIdentity(identity); |
| 13696 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13697 | } |
| 13698 | |
| 13699 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13700 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13701 | * by modem. |
| 13702 | * |
| 13703 | * @param subId The subId of the subscription to request for. |
| 13704 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13705 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13706 | * operation. |
| 13707 | * |
| 13708 | * @throws SecurityException if the caller doesn't have required permission. |
| 13709 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13710 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13711 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13712 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13713 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13714 | final long identity = Binder.clearCallingIdentity(); |
| 13715 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13716 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13717 | } finally { |
| 13718 | Binder.restoreCallingIdentity(identity); |
| 13719 | } |
| 13720 | } |
| 13721 | |
| 13722 | /** |
| 13723 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13724 | * by modem. |
| 13725 | * |
| 13726 | * @param subId The subId of the subscription to request for. |
| 13727 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13728 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13729 | * operation. |
| 13730 | * |
| 13731 | * @throws SecurityException if the caller doesn't have required permission. |
| 13732 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13733 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13734 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13735 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13736 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13737 | final long identity = Binder.clearCallingIdentity(); |
| 13738 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13739 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13740 | } finally { |
| 13741 | Binder.restoreCallingIdentity(identity); |
| 13742 | } |
| 13743 | } |
| 13744 | |
| 13745 | /** |
| 13746 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13747 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13748 | * |
| 13749 | * @param subId The subId of the subscription to request for. |
| 13750 | * |
| 13751 | * @return Integer array of reasons for disallowing satellite communication. |
| 13752 | * |
| 13753 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13754 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13755 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13756 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13757 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13758 | final long identity = Binder.clearCallingIdentity(); |
| 13759 | try { |
| 13760 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13761 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13762 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13763 | } finally { |
| 13764 | Binder.restoreCallingIdentity(identity); |
| 13765 | } |
| 13766 | } |
| 13767 | |
| 13768 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13769 | * Request to get the signal strength of the satellite connection. |
| 13770 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13771 | * @param result Result receiver to get the error code of the request and the current signal |
| 13772 | * strength of the satellite connection. |
| 13773 | * |
| 13774 | * @throws SecurityException if the caller doesn't have required permission. |
| 13775 | */ |
| 13776 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13777 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13778 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13779 | final long identity = Binder.clearCallingIdentity(); |
| 13780 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13781 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13782 | } finally { |
| 13783 | Binder.restoreCallingIdentity(identity); |
| 13784 | } |
| 13785 | } |
| 13786 | |
| 13787 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13788 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13789 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13790 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13791 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13792 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13793 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13794 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13795 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13796 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13797 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13798 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13799 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13800 | */ |
| 13801 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13802 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13803 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13804 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13805 | final long identity = Binder.clearCallingIdentity(); |
| 13806 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13807 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13808 | } finally { |
| 13809 | Binder.restoreCallingIdentity(identity); |
| 13810 | } |
| 13811 | } |
| 13812 | |
| 13813 | /** |
| 13814 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13815 | * If callback was not registered before, the request will be ignored. |
| 13816 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13817 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13818 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13819 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13820 | * |
| 13821 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13822 | */ |
| 13823 | @Override |
| 13824 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13825 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13826 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13827 | final long identity = Binder.clearCallingIdentity(); |
| 13828 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13829 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13830 | } finally { |
| 13831 | Binder.restoreCallingIdentity(identity); |
| 13832 | } |
| 13833 | } |
| 13834 | |
| 13835 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13836 | * Registers for satellite capabilities change event from the satellite service. |
| 13837 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13838 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13839 | * |
| 13840 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13841 | * |
| 13842 | * @throws SecurityException if the caller doesn't have required permission. |
| 13843 | */ |
| 13844 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13845 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13846 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13847 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13848 | final long identity = Binder.clearCallingIdentity(); |
| 13849 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13850 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13851 | } finally { |
| 13852 | Binder.restoreCallingIdentity(identity); |
| 13853 | } |
| 13854 | } |
| 13855 | |
| 13856 | /** |
| 13857 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13858 | * If callback was not registered before, the request will be ignored. |
| 13859 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13860 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13861 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13862 | * |
| 13863 | * @throws SecurityException if the caller doesn't have required permission. |
| 13864 | */ |
| 13865 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13866 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13867 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13868 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13869 | final long identity = Binder.clearCallingIdentity(); |
| 13870 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13871 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13872 | } finally { |
| 13873 | Binder.restoreCallingIdentity(identity); |
| 13874 | } |
| 13875 | } |
| 13876 | |
| 13877 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13878 | * Registers for the satellite supported state changed. |
| 13879 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13880 | * @param callback The callback to handle the satellite supported state changed event. |
| 13881 | * |
| 13882 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13883 | * |
| 13884 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13885 | */ |
| 13886 | @Override |
| 13887 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13888 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13889 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13890 | final long identity = Binder.clearCallingIdentity(); |
| 13891 | try { |
| 13892 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
| 13893 | } finally { |
| 13894 | Binder.restoreCallingIdentity(identity); |
| 13895 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13896 | } |
| 13897 | |
| 13898 | /** |
| 13899 | * Unregisters for the satellite supported state changed. |
| 13900 | * If callback was not registered before, the request will be ignored. |
| 13901 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13902 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13903 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13904 | * |
| 13905 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13906 | */ |
| 13907 | @Override |
| 13908 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13909 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13910 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13911 | final long identity = Binder.clearCallingIdentity(); |
| 13912 | try { |
| 13913 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
| 13914 | } finally { |
| 13915 | Binder.restoreCallingIdentity(identity); |
| 13916 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13917 | } |
| 13918 | |
| 13919 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13920 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13921 | * |
| 13922 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13923 | * @param provisioned Whether satellite should be provisioned or not. |
| 13924 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13925 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13926 | * {@code false} otherwise. |
| 13927 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13928 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 13929 | String provisioned) { |
| 13930 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 13931 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13932 | TelephonyPermissions.enforceShellOnly( |
| 13933 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13935 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13936 | "setSatelliteServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13937 | final long identity = Binder.clearCallingIdentity(); |
| 13938 | try { |
| 13939 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 13940 | provisioned); |
| 13941 | } finally { |
| 13942 | Binder.restoreCallingIdentity(identity); |
| 13943 | } |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13944 | } |
| 13945 | |
| 13946 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13947 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13948 | * |
| 13949 | * @param servicePackageName The package name of the satellite gateway service. |
| 13950 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13951 | * {@code false} otherwise. |
| 13952 | */ |
| 13953 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13954 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13955 | TelephonyPermissions.enforceShellOnly( |
| 13956 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13958 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13959 | "setSatelliteGatewayServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13960 | final long identity = Binder.clearCallingIdentity(); |
| 13961 | try { |
| 13962 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13963 | } finally { |
| 13964 | Binder.restoreCallingIdentity(identity); |
| 13965 | } |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13966 | } |
| 13967 | |
| 13968 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13969 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13970 | * |
| 13971 | * @param packageName The package name of the satellite pointing UI app. |
| 13972 | * @param className The class name of the satellite pointing UI app. |
| 13973 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13974 | * {@code false} otherwise. |
| 13975 | */ |
| 13976 | public boolean setSatellitePointingUiClassName( |
| 13977 | @Nullable String packageName, @Nullable String className) { |
| 13978 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13979 | + ", className=" + className); |
| 13980 | TelephonyPermissions.enforceShellOnly( |
| 13981 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13983 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 13984 | "setSatellitePointingUiClassName"); |
| 13985 | final long identity = Binder.clearCallingIdentity(); |
| 13986 | try { |
| 13987 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13988 | } finally { |
| 13989 | Binder.restoreCallingIdentity(identity); |
| 13990 | } |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13991 | } |
| 13992 | |
| 13993 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13994 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13995 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13996 | * listening mode. |
| 13997 | * |
| 13998 | * @param timeoutMillis The timeout duration in millisecond. |
| 13999 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14000 | */ |
| 14001 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 14002 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 14003 | TelephonyPermissions.enforceShellOnly( |
| 14004 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 14005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14006 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14007 | "setSatelliteListeningTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14008 | final long identity = Binder.clearCallingIdentity(); |
| 14009 | try { |
| 14010 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 14011 | } finally { |
| 14012 | Binder.restoreCallingIdentity(identity); |
| 14013 | } |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14014 | } |
| 14015 | |
| 14016 | /** |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14017 | * This API can be used by only CTS to control ingoring cellular service state event. |
| 14018 | * |
| 14019 | * @param enabled Whether to enable boolean config. |
| 14020 | * @return {@code true} if the value is set successfully, {@code false} otherwise. |
| 14021 | */ |
| 14022 | public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14023 | Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14024 | TelephonyPermissions.enforceShellOnly( |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14025 | Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState"); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14027 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14028 | "setSatelliteIgnoreCellularServiceState"); |
| 14029 | final long identity = Binder.clearCallingIdentity(); |
| 14030 | try { |
| 14031 | return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled); |
| 14032 | } finally { |
| 14033 | Binder.restoreCallingIdentity(identity); |
| 14034 | } |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14035 | } |
| 14036 | |
| 14037 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14038 | * This API can be used by only CTS to override the timeout durations used by the |
| 14039 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14040 | * |
| 14041 | * @param timeoutMillis The timeout duration in millisecond. |
| 14042 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14043 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14044 | public boolean setDatagramControllerTimeoutDuration( |
| 14045 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14046 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14047 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14048 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14049 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14051 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14052 | "setDatagramControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14053 | final long identity = Binder.clearCallingIdentity(); |
| 14054 | try { |
| 14055 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 14056 | reset, timeoutType, timeoutMillis); |
| 14057 | } finally { |
| 14058 | Binder.restoreCallingIdentity(identity); |
| 14059 | } |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14060 | } |
| 14061 | |
| 14062 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14063 | * This API can be used by only CTS to override the boolean configs used by the |
| 14064 | * DatagramController module. |
| 14065 | * |
| 14066 | * @param enable Whether to enable or disable boolean config. |
| 14067 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 14068 | */ |
| 14069 | public boolean setDatagramControllerBooleanConfig( |
| 14070 | boolean reset, int booleanType, boolean enable) { |
| 14071 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 14072 | + ", reset=" + reset + ", enable=" + enable); |
| 14073 | TelephonyPermissions.enforceShellOnly( |
| 14074 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 14075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14076 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14077 | "ssetDatagramControllerBooleanConfig"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14078 | final long identity = Binder.clearCallingIdentity(); |
| 14079 | try { |
| 14080 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, |
| 14081 | enable); |
| 14082 | } finally { |
| 14083 | Binder.restoreCallingIdentity(identity); |
| 14084 | } |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14085 | } |
| 14086 | |
| 14087 | |
| 14088 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14089 | * This API can be used by only CTS to override the timeout durations used by the |
| 14090 | * SatelliteController module. |
| 14091 | * |
| 14092 | * @param timeoutMillis The timeout duration in millisecond. |
| 14093 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14094 | */ |
| 14095 | public boolean setSatelliteControllerTimeoutDuration( |
| 14096 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14097 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14098 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 14099 | TelephonyPermissions.enforceShellOnly( |
| 14100 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 14101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14102 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14103 | "setSatelliteControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14104 | final long identity = Binder.clearCallingIdentity(); |
| 14105 | try { |
| 14106 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 14107 | reset, timeoutType, timeoutMillis); |
| 14108 | } finally { |
| 14109 | Binder.restoreCallingIdentity(identity); |
| 14110 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14111 | } |
| 14112 | |
| 14113 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14114 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 14115 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 14116 | * |
| 14117 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 14118 | * of the following values to enable the override: |
| 14119 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 14120 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 14121 | * To disable the override, use -1 for handoverType. |
| 14122 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 14123 | * delaySeconds after the emergency call starts. |
| 14124 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 14125 | */ |
| 14126 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 14127 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 14128 | TelephonyPermissions.enforceShellOnly( |
| 14129 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 14130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14131 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14132 | "setEmergencyCallToSatelliteHandoverType"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14133 | final long identity = Binder.clearCallingIdentity(); |
| 14134 | try { |
| 14135 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 14136 | handoverType, delaySeconds); |
| 14137 | } finally { |
| 14138 | Binder.restoreCallingIdentity(identity); |
| 14139 | } |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14140 | } |
| 14141 | |
| 14142 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14143 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 14144 | * |
| 14145 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 14146 | * otherwise. |
| 14147 | * @param isProvisioned The overriding provision status. |
| 14148 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 14149 | */ |
| 14150 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 14151 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 14152 | + ", isProvisioned=" + isProvisioned); |
| 14153 | TelephonyPermissions.enforceShellOnly( |
| 14154 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 14155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14156 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14157 | "setOemEnabledSatelliteProvisionStatus"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14158 | final long identity = Binder.clearCallingIdentity(); |
| 14159 | try { |
| 14160 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 14161 | } finally { |
| 14162 | Binder.restoreCallingIdentity(identity); |
| 14163 | } |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14164 | } |
| 14165 | |
| 14166 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14167 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 14168 | * |
| 14169 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 14170 | */ |
| 14171 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 14172 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 14173 | long locationCountryCodeTimestampNanos) { |
| 14174 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 14175 | + String.join(", ", currentNetworkCountryCodes) |
| 14176 | + ", locationCountryCode=" + locationCountryCode |
| 14177 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 14178 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 14179 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14180 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14182 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes"); |
| 14183 | final long identity = Binder.clearCallingIdentity(); |
| 14184 | try { |
| 14185 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), |
| 14186 | mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes, |
| 14187 | cachedNetworkCountryCodes, locationCountryCode, |
| 14188 | locationCountryCodeTimestampNanos); |
| 14189 | } finally { |
| 14190 | Binder.restoreCallingIdentity(identity); |
| 14191 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14192 | } |
| 14193 | |
| 14194 | /** |
| 14195 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 14196 | * access controller. |
| 14197 | * |
| 14198 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 14199 | * otherwise. |
| 14200 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 14201 | */ |
| 14202 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14203 | String s2CellFile, long locationFreshDurationNanos, |
| 14204 | List<String> satelliteCountryCodes) { |
| 14205 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14206 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14207 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14208 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 14209 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 14210 | TelephonyPermissions.enforceShellOnly( |
| 14211 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14213 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14214 | "setSatelliteAccessControlOverlayConfigs"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14215 | final long identity = Binder.clearCallingIdentity(); |
| 14216 | try { |
| 14217 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, |
| 14218 | isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 14219 | } finally { |
| 14220 | Binder.restoreCallingIdentity(identity); |
| 14221 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14222 | } |
| 14223 | |
| 14224 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14225 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14226 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14227 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14228 | * |
| 14229 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14230 | * satellite modem or not. |
| 14231 | * |
| 14232 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14233 | */ |
| 14234 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14235 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14236 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14237 | + "disabled"); |
| 14238 | return false; |
| 14239 | } |
| 14240 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14241 | TelephonyPermissions.enforceShellOnly( |
| 14242 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14244 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14245 | "setShouldSendDatagramToModemInDemoMode"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14246 | final long identity = Binder.clearCallingIdentity(); |
| 14247 | try { |
| 14248 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14249 | shouldSendToModemInDemoMode); |
| 14250 | } finally { |
| 14251 | Binder.restoreCallingIdentity(identity); |
| 14252 | } |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14253 | } |
| 14254 | |
| 14255 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14256 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14257 | * |
| 14258 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14259 | * the allowed state. |
| 14260 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14261 | */ |
| 14262 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14263 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14264 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14265 | + "oemEnabledSatelliteFlag is disabled"); |
| 14266 | return false; |
| 14267 | } |
| 14268 | |
| 14269 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14270 | + "state=" + state); |
| 14271 | TelephonyPermissions.enforceShellOnly( |
| 14272 | Binder.getCallingUid(), |
| 14273 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14275 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14276 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14277 | final long identity = Binder.clearCallingIdentity(); |
| 14278 | try { |
| 14279 | return mSatelliteAccessController |
| 14280 | .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state); |
| 14281 | } finally { |
| 14282 | Binder.restoreCallingIdentity(identity); |
| 14283 | } |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14284 | } |
| 14285 | |
| 14286 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14287 | * Sets the service defined in ComponentName to be bound. |
| 14288 | * |
| 14289 | * This should only be used for testing. |
| 14290 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14291 | * {@code false} otherwise. |
| 14292 | */ |
| 14293 | @Override |
| 14294 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14295 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14296 | |
| 14297 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14298 | "setDomainSelectionServiceOverride"); |
| 14299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14300 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14301 | |
| 14302 | final long identity = Binder.clearCallingIdentity(); |
| 14303 | try { |
| 14304 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14305 | return DomainSelectionResolver.getInstance() |
| 14306 | .setDomainSelectionServiceOverride(componentName); |
| 14307 | } |
| 14308 | } finally { |
| 14309 | Binder.restoreCallingIdentity(identity); |
| 14310 | } |
| 14311 | return false; |
| 14312 | } |
| 14313 | |
| 14314 | /** |
| 14315 | * Clears the DomainSelectionService override. |
| 14316 | * |
| 14317 | * This should only be used for testing. |
| 14318 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14319 | * {@code false} otherwise. |
| 14320 | */ |
| 14321 | @Override |
| 14322 | public boolean clearDomainSelectionServiceOverride() { |
| 14323 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14324 | |
| 14325 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14326 | "clearDomainSelectionServiceOverride"); |
| 14327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14328 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14329 | |
| 14330 | final long identity = Binder.clearCallingIdentity(); |
| 14331 | try { |
| 14332 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14333 | return DomainSelectionResolver.getInstance() |
| 14334 | .clearDomainSelectionServiceOverride(); |
| 14335 | } |
| 14336 | } finally { |
| 14337 | Binder.restoreCallingIdentity(identity); |
| 14338 | } |
| 14339 | return false; |
| 14340 | } |
| 14341 | |
| 14342 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14343 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14344 | * |
| 14345 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14346 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14347 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14348 | * |
| 14349 | * @param enable if notifications about disclosure events should be enabled |
| 14350 | * @throws SecurityException if the caller does not have the required privileges |
| 14351 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14352 | */ |
| 14353 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14354 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14355 | enforceModifyPermission(); |
| 14356 | checkForIdentifierDisclosureNotificationSupport(); |
| 14357 | |
| 14358 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14359 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14360 | editor.apply(); |
| 14361 | |
| 14362 | // Each phone instance is responsible for updating its respective modem immediately |
| 14363 | // after we've made a preference change. |
| 14364 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14365 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14366 | } |
| 14367 | } |
| 14368 | |
| 14369 | /** |
| 14370 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14371 | * |
| 14372 | * @throws SecurityException if the caller does not have the required privileges |
| 14373 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14374 | */ |
| 14375 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14376 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14377 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14378 | checkForIdentifierDisclosureNotificationSupport(); |
| 14379 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14380 | } |
| 14381 | |
| 14382 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14383 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14384 | * are in use by the cellular modem. |
| 14385 | * |
| 14386 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14387 | * @throws SecurityException if the caller does not have the required privileges |
| 14388 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14389 | * and integrity algorithms in use |
| 14390 | * @hide |
| 14391 | */ |
| 14392 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14393 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14394 | enforceModifyPermission(); |
| 14395 | checkForNullCipherNotificationSupport(); |
| 14396 | |
| 14397 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14398 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14399 | editor.apply(); |
| 14400 | |
| 14401 | // Each phone instance is responsible for updating its respective modem immediately |
| 14402 | // after a preference change. |
| 14403 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14404 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14405 | } |
| 14406 | } |
| 14407 | |
| 14408 | /** |
| 14409 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14410 | * cellular modem. |
| 14411 | * |
| 14412 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14413 | * @throws SecurityException if the caller does not have the required privileges |
| 14414 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14415 | * and integrity algorithms in use |
| 14416 | * @hide |
| 14417 | */ |
| 14418 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14419 | public boolean isNullCipherNotificationsEnabled() { |
| 14420 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14421 | checkForNullCipherNotificationSupport(); |
| 14422 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14423 | } |
| 14424 | |
| 14425 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14426 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14427 | * |
| 14428 | * <p>This method behaves in one of the following ways: |
| 14429 | * <ul> |
| 14430 | * <li>return true : if the calling package has the appop permission {@link |
| 14431 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14432 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14433 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14434 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14435 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14436 | * </ul> |
| 14437 | */ |
| 14438 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14439 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14440 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14441 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14442 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14443 | return true; |
| 14444 | } |
| 14445 | } |
| 14446 | return false; |
| 14447 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14448 | |
| 14449 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14450 | * @return The subscription manager service instance. |
| 14451 | */ |
| 14452 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14453 | return SubscriptionManagerService.getInstance(); |
| 14454 | } |
| 14455 | |
| 14456 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14457 | * Class binds the consumer[callback] and carrierId. |
| 14458 | */ |
| 14459 | private static class CallerCallbackInfo { |
| 14460 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14461 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14462 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14463 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14464 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14465 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14466 | } |
| 14467 | |
| 14468 | public Consumer<Integer> getConsumer() { |
| 14469 | return mConsumer; |
| 14470 | } |
| 14471 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14472 | public Set<Integer> getCarrierIds() { |
| 14473 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14474 | } |
| 14475 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14476 | |
| 14477 | /* |
| 14478 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14479 | * But the context that is passed in is unused if the phone app is already alive. |
| 14480 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14481 | */ |
| 14482 | @VisibleForTesting |
| 14483 | public void setPackageManager(PackageManager packageManager) { |
| 14484 | mPackageManager = packageManager; |
| 14485 | } |
| 14486 | |
| 14487 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14488 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14489 | * But the context that is passed in is unused if the phone app is already alive. |
| 14490 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14491 | */ |
| 14492 | @VisibleForTesting |
| 14493 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14494 | mAppOps = appOps; |
| 14495 | } |
| 14496 | |
| 14497 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14498 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14499 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14500 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14501 | */ |
| 14502 | @VisibleForTesting |
| 14503 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14504 | mFeatureFlags = featureFlags; |
| 14505 | } |
| 14506 | |
| 14507 | /** |
| 14508 | * Make sure the device has required telephony feature |
| 14509 | * |
| 14510 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14511 | */ |
| 14512 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14513 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14514 | if (callingPackage == null || mPackageManager == null) { |
| 14515 | return; |
| 14516 | } |
| 14517 | |
| 14518 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14519 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14520 | Binder.getCallingUserHandle()) |
| 14521 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14522 | // Skip to check associated telephony feature, |
| 14523 | // if compatibility change is not enabled for the current process or |
| 14524 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14525 | return; |
| 14526 | } |
| 14527 | |
| 14528 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14529 | throw new UnsupportedOperationException( |
| 14530 | methodName + " is unsupported without " + telephonyFeature); |
| 14531 | } |
| 14532 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14533 | |
| 14534 | /** |
| 14535 | * Registers for the satellite communication allowed state changed. |
| 14536 | * |
| 14537 | * @param subId The subId of the subscription to register for the satellite communication |
| 14538 | * allowed state changed. |
| 14539 | * @param callback The callback to handle the satellite communication allowed |
| 14540 | * state changed event. |
| 14541 | * |
| 14542 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14543 | * |
| 14544 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14545 | */ |
| 14546 | @Override |
| 14547 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14548 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14549 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14550 | final long identity = Binder.clearCallingIdentity(); |
| 14551 | try { |
| 14552 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14553 | subId, callback); |
| 14554 | } finally { |
| 14555 | Binder.restoreCallingIdentity(identity); |
| 14556 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14557 | } |
| 14558 | |
| 14559 | /** |
| 14560 | * Unregisters for the satellite communication allowed state changed. |
| 14561 | * If callback was not registered before, the request will be ignored. |
| 14562 | * |
| 14563 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14564 | * allowed state changed. |
| 14565 | * @param callback The callback that was passed to |
| 14566 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14567 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14568 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14569 | */ |
| 14570 | @Override |
| 14571 | public void unregisterForCommunicationAllowedStateChanged( |
| 14572 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14573 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14574 | final long identity = Binder.clearCallingIdentity(); |
| 14575 | try { |
| 14576 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14577 | callback); |
| 14578 | } finally { |
| 14579 | Binder.restoreCallingIdentity(identity); |
| 14580 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14581 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14582 | |
| 14583 | /** |
| 14584 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14585 | * |
| 14586 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14587 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14588 | * if the request is successful or an error code if the request failed. |
| 14589 | * |
| 14590 | * @throws SecurityException if the caller doesn't have required permission. |
| 14591 | */ |
| 14592 | @Override |
| 14593 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14594 | enforceModifyPermission(); |
| 14595 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14596 | final long identity = Binder.clearCallingIdentity(); |
| 14597 | try { |
| 14598 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14599 | } finally { |
| 14600 | Binder.restoreCallingIdentity(identity); |
| 14601 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14602 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14603 | |
| 14604 | /** |
| 14605 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14606 | * |
| 14607 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14608 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14609 | * |
| 14610 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14611 | */ |
| 14612 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14613 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14614 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14615 | final long identity = Binder.clearCallingIdentity(); |
| 14616 | try { |
| 14617 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14618 | } finally { |
| 14619 | Binder.restoreCallingIdentity(identity); |
| 14620 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14621 | } |
| 14622 | |
| 14623 | /** |
| 14624 | * Deliver the list of provisioned satellite subscriber ids. |
| 14625 | * |
| 14626 | * @param list List of provisioned satellite subscriber ids. |
| 14627 | * @param result The result receiver that returns whether deliver success or fail. |
| 14628 | * |
| 14629 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14630 | */ |
| 14631 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14632 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14633 | @NonNull ResultReceiver result) { |
| 14634 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14635 | final long identity = Binder.clearCallingIdentity(); |
| 14636 | try { |
| 14637 | mSatelliteController.provisionSatellite(list, result); |
| 14638 | } finally { |
| 14639 | Binder.restoreCallingIdentity(identity); |
| 14640 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14641 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14642 | |
| 14643 | /** |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14644 | * Deliver the list of deprovisioned satellite subscriber ids. |
| 14645 | * |
| 14646 | * @param list List of deprovisioned satellite subscriber ids. |
| 14647 | * @param result The result receiver that returns whether deliver success or fail. |
| 14648 | * |
| 14649 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14650 | */ |
| 14651 | @Override |
| 14652 | public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
| 14653 | @NonNull ResultReceiver result) { |
| 14654 | enforceSatelliteCommunicationPermission("deprovisionSatellite"); |
| 14655 | final long identity = Binder.clearCallingIdentity(); |
| 14656 | try { |
| 14657 | mSatelliteController.deprovisionSatellite(list, result); |
| 14658 | } finally { |
| 14659 | Binder.restoreCallingIdentity(identity); |
| 14660 | } |
| 14661 | } |
| 14662 | |
| 14663 | /** |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14664 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14665 | * value : |
| 14666 | * config_satellite_gateway_service_package and |
| 14667 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14668 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14669 | * subscriber informations. |
| 14670 | * |
| 14671 | * @param name the name is one of the following that constitute an intent. |
| 14672 | * Component package name, or component class name. |
| 14673 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14674 | */ |
| 14675 | @Override |
| 14676 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14677 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14678 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14679 | + " carrierRoamingNbIotNtn is disabled"); |
| 14680 | return false; |
| 14681 | } |
| 14682 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14683 | TelephonyPermissions.enforceShellOnly( |
| 14684 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14686 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14687 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14688 | final long identity = Binder.clearCallingIdentity(); |
| 14689 | try { |
| 14690 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14691 | } finally { |
| 14692 | Binder.restoreCallingIdentity(identity); |
| 14693 | } |
| 14694 | } |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 14695 | |
| 14696 | /** |
| 14697 | * This API can be used by only CTS to override the Euicc UI component. |
| 14698 | * |
| 14699 | * @param componentName ui component to be launched for testing. {@code null} to reset. |
| 14700 | * |
| 14701 | * @hide |
| 14702 | */ |
| 14703 | @Override |
| 14704 | public void setTestEuiccUiComponent(@Nullable ComponentName componentName) { |
| 14705 | enforceModifyPermission(); |
| 14706 | log("setTestEuiccUiComponent: " + componentName); |
| 14707 | mTestEuiccUiComponent = componentName; |
| 14708 | } |
| 14709 | |
| 14710 | /** |
| 14711 | * This API can be used by only CTS to retrieve the Euicc UI component. |
| 14712 | * |
| 14713 | * @return Euicc UI component. {@code null} if not available. |
| 14714 | * @hide |
| 14715 | */ |
| 14716 | @Override |
| 14717 | @Nullable |
| 14718 | public ComponentName getTestEuiccUiComponent() { |
| 14719 | enforceReadPrivilegedPermission("getTestEuiccUiComponent"); |
| 14720 | return mTestEuiccUiComponent; |
| 14721 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14722 | |
| 14723 | /** |
| 14724 | * This API can be used only for test purpose to override the carrier roaming Ntn eligibility |
| 14725 | * |
| 14726 | * @param state to update Ntn Eligibility. |
| 14727 | * @param resetRequired to reset the overridden flag in satellite controller. |
| 14728 | * @return {@code true} if the shell command is successful, {@code false} otherwise. |
| 14729 | */ |
| 14730 | public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state, |
| 14731 | boolean resetRequired) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame^] | 14732 | final long identity = Binder.clearCallingIdentity(); |
| 14733 | try { |
| 14734 | return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state, |
| 14735 | resetRequired); |
| 14736 | } finally { |
| 14737 | Binder.restoreCallingIdentity(identity); |
| 14738 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14739 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14740 | } |