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; |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteDisallowedReasonsCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 165 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 166 | import android.telephony.satellite.NtnSignalStrength; |
| 167 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 173 | import android.telephony.satellite.SatelliteSubscriberInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 176 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 178 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 180 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 181 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 182 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 183 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 198 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 215 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 222 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 229 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 230 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 231 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 235 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 236 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.IccIoResult; |
| 239 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 247 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 248 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 249 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 250 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 251 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 252 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 253 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 254 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 255 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 256 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 257 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 258 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 259 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 260 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 261 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 262 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 263 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 264 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 265 | import com.android.services.telephony.TelecomAccountRegistry; |
| 266 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 267 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 268 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 269 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 270 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 271 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.io.IOException; |
| 273 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 274 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 276 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 277 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 278 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 279 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 280 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 281 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 282 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 284 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 285 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 286 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 287 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 288 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 289 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 290 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Implementation of the ITelephony interface. |
| 294 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 295 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 297 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 298 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 299 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | |
| 301 | // Message codes used with mMainThreadHandler |
| 302 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 303 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 304 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 305 | private static final int CMD_OPEN_CHANNEL = 9; |
| 306 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 307 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 308 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 309 | private static final int CMD_NV_READ_ITEM = 13; |
| 310 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 311 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 312 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 313 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 314 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 315 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 316 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 317 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 318 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 319 | private static final int CMD_SEND_ENVELOPE = 25; |
| 320 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 321 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 322 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 323 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 324 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 326 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 327 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 328 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 329 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 330 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 331 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 332 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 333 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 334 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 335 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 336 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 337 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 338 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 339 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 341 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 342 | private static final int CMD_SWITCH_SLOTS = 50; |
| 343 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 345 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 346 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 347 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 348 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 349 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 350 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 351 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 352 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 353 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 354 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 355 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 356 | private static final int CMD_MODEM_REBOOT = 64; |
| 357 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 358 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 359 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 360 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 361 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 362 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 363 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 364 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 365 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 366 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 367 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 368 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 369 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 370 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 371 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 372 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 373 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 374 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 375 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 376 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 377 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 378 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 379 | private static final int CMD_GET_CALL_WAITING = 87; |
| 380 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 381 | private static final int CMD_SET_CALL_WAITING = 89; |
| 382 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 383 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 384 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 385 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 386 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 387 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 388 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 389 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 390 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 391 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 392 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 393 | private static final int CMD_SET_SIM_POWER = 101; |
| 394 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 395 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 396 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 397 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 398 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 399 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 400 | 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] | 401 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 402 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 403 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 404 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 405 | private static final int CMD_ENABLE_VONR = 113; |
| 406 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 407 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 408 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 409 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 410 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 411 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 412 | // Parameters of select command. |
| 413 | private static final int SELECT_COMMAND = 0xA4; |
| 414 | private static final int SELECT_P1 = 0x04; |
| 415 | private static final int SELECT_P2 = 0; |
| 416 | private static final int SELECT_P3 = 0x10; |
| 417 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 418 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 419 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 420 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 421 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 422 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 423 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 424 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | /** The singleton instance. */ |
| 426 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 427 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 430 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 431 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 432 | private final CallManager mCM; |
| 433 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 434 | |
| 435 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 436 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 438 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 439 | private final SharedPreferences mTelephonySharedPreferences; |
| 440 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 441 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 442 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 443 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 444 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 446 | @Nullable |
| 447 | private ComponentName mTestEuiccUiComponent; |
| 448 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 449 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 450 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 451 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 452 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 453 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 454 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 455 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 456 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 457 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 458 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 459 | // String to store multi SIM allowed |
| 460 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 461 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 462 | // The AID of ISD-R. |
| 463 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 464 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 465 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 466 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 467 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 468 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 469 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 470 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 471 | 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] | 472 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 473 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 474 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 475 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 476 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 477 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 478 | */ |
| 479 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 480 | "reset_network_erase_modem_config_enabled"; |
| 481 | |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 482 | private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 483 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 484 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 485 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 486 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 487 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 488 | /** |
| 489 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 490 | * one ICCID active at the same time. |
| 491 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 492 | * |
| 493 | * @hide |
| 494 | */ |
| 495 | @ChangeId |
| 496 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 497 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 498 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 499 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 500 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 501 | * operation fails. |
| 502 | */ |
| 503 | @ChangeId |
| 504 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 505 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 506 | |
| 507 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | * A request object to use for transmitting data to an ICC. |
| 509 | */ |
| 510 | private static final class IccAPDUArgument { |
| 511 | public int channel, cla, command, p1, p2, p3; |
| 512 | public String data; |
| 513 | |
| 514 | public IccAPDUArgument(int channel, int cla, int command, |
| 515 | int p1, int p2, int p3, String data) { |
| 516 | this.channel = channel; |
| 517 | this.cla = cla; |
| 518 | this.command = command; |
| 519 | this.p1 = p1; |
| 520 | this.p2 = p2; |
| 521 | this.p3 = p3; |
| 522 | this.data = data; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 527 | * A request object to use for transmitting data to an ICC. |
| 528 | */ |
| 529 | private static final class ManualNetworkSelectionArgument { |
| 530 | public OperatorInfo operatorInfo; |
| 531 | public boolean persistSelection; |
| 532 | |
| 533 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 534 | this.operatorInfo = operatorInfo; |
| 535 | this.persistSelection = persistSelection; |
| 536 | } |
| 537 | } |
| 538 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 539 | private static final class PurchasePremiumCapabilityArgument { |
| 540 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 541 | public @NonNull IIntegerConsumer callback; |
| 542 | |
| 543 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 544 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 545 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 546 | this.callback = callback; |
| 547 | } |
| 548 | } |
| 549 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 550 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 551 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 552 | * request after sending. The main thread will notify the request when it is complete. |
| 553 | */ |
| 554 | private static final class MainThreadRequest { |
| 555 | /** The argument to use for the request */ |
| 556 | public Object argument; |
| 557 | /** The result of the request that is run on the main thread */ |
| 558 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 559 | // The subscriber id that this request applies to. Defaults to |
| 560 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 561 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 562 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 563 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 564 | public Phone phone; |
| 565 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 566 | public WorkSource workSource; |
| 567 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 568 | public MainThreadRequest(Object argument) { |
| 569 | this.argument = argument; |
| 570 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 571 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 572 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 573 | this.argument = argument; |
| 574 | if (phone != null) { |
| 575 | this.phone = phone; |
| 576 | } |
| 577 | this.workSource = workSource; |
| 578 | } |
| 579 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 580 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 581 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 582 | if (subId != null) { |
| 583 | this.subId = subId; |
| 584 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 585 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 589 | private static final class IncomingThirdPartyCallArgs { |
| 590 | public final ComponentName component; |
| 591 | public final String callId; |
| 592 | public final String callerDisplayName; |
| 593 | |
| 594 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 595 | String callerDisplayName) { |
| 596 | this.component = component; |
| 597 | this.callId = callId; |
| 598 | this.callerDisplayName = callerDisplayName; |
| 599 | } |
| 600 | } |
| 601 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 602 | /** |
| 603 | * A handler that processes messages on the main thread in the phone process. Since many |
| 604 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 605 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 606 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 607 | * on, which will be notified when the operation completes and will contain the result of the |
| 608 | * request. |
| 609 | * |
| 610 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 611 | * note that request.result must be set to something non-null for the calling thread to |
| 612 | * unblock. |
| 613 | */ |
| 614 | private final class MainThreadHandler extends Handler { |
| 615 | @Override |
| 616 | public void handleMessage(Message msg) { |
| 617 | MainThreadRequest request; |
| 618 | Message onCompleted; |
| 619 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 620 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 622 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 623 | |
| 624 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | case CMD_HANDLE_USSD_REQUEST: { |
| 626 | request = (MainThreadRequest) msg.obj; |
| 627 | final Phone phone = getPhoneFromRequest(request); |
| 628 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 629 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 631 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | if (!isUssdApiAllowed(request.subId)) { |
| 633 | // Carrier does not support use of this API, return failure. |
| 634 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 635 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 636 | Bundle returnData = new Bundle(); |
| 637 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 638 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 639 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | request.result = true; |
| 641 | notifyRequester(request); |
| 642 | return; |
| 643 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 644 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | try { |
| 646 | request.result = phone != null |
| 647 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 648 | } catch (CallStateException cse) { |
| 649 | request.result = false; |
| 650 | } |
| 651 | // Wake up the requesting thread |
| 652 | notifyRequester(request); |
| 653 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 656 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 657 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 658 | final Phone phone = getPhoneFromRequest(request); |
| 659 | request.result = phone != null ? |
| 660 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 661 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 662 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 664 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 665 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 666 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 670 | uiccPort = getUiccPortFromRequest(request); |
| 671 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 673 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 674 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 675 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 677 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 678 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 679 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 680 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 681 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | break; |
| 684 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | ar = (AsyncResult) msg.obj; |
| 687 | request = (MainThreadRequest) ar.userObj; |
| 688 | if (ar.exception == null && ar.result != null) { |
| 689 | request.result = ar.result; |
| 690 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 691 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | if (ar.result == null) { |
| 693 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 696 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | } else { |
| 698 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 699 | } |
| 700 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 701 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | break; |
| 703 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 705 | request = (MainThreadRequest) msg.obj; |
| 706 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 707 | uiccPort = getUiccPortFromRequest(request); |
| 708 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 710 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 711 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 712 | } else { |
| 713 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 714 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 715 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 717 | iccArgument.p2, |
| 718 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | } |
| 720 | break; |
| 721 | |
| 722 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 723 | ar = (AsyncResult) msg.obj; |
| 724 | request = (MainThreadRequest) ar.userObj; |
| 725 | if (ar.exception == null && ar.result != null) { |
| 726 | request.result = ar.result; |
| 727 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 728 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | if (ar.result == null) { |
| 730 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 731 | } else if (ar.exception instanceof CommandException) { |
| 732 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 733 | ar.exception); |
| 734 | } else { |
| 735 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 736 | } |
| 737 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 738 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case CMD_EXCHANGE_SIM_IO: |
| 742 | request = (MainThreadRequest) msg.obj; |
| 743 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 744 | uiccPort = getUiccPortFromRequest(request); |
| 745 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 746 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 747 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 748 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 749 | } else { |
| 750 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 751 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 752 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 753 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 754 | iccArgument.data, onCompleted); |
| 755 | } |
| 756 | break; |
| 757 | |
| 758 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 759 | ar = (AsyncResult) msg.obj; |
| 760 | request = (MainThreadRequest) ar.userObj; |
| 761 | if (ar.exception == null && ar.result != null) { |
| 762 | request.result = ar.result; |
| 763 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 764 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 767 | break; |
| 768 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 769 | case CMD_SEND_ENVELOPE: |
| 770 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 771 | uiccPort = getUiccPortFromRequest(request); |
| 772 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 774 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 775 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 776 | } else { |
| 777 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 778 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 779 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case EVENT_SEND_ENVELOPE_DONE: |
| 783 | ar = (AsyncResult) msg.obj; |
| 784 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 785 | if (ar.exception == null && ar.result != null) { |
| 786 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 787 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 788 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 789 | if (ar.result == null) { |
| 790 | loge("sendEnvelopeWithStatus: Empty response"); |
| 791 | } else if (ar.exception instanceof CommandException) { |
| 792 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 793 | ar.exception); |
| 794 | } else { |
| 795 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 796 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 797 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 798 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 799 | break; |
| 800 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 801 | case CMD_OPEN_CHANNEL: |
| 802 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 803 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 804 | IccLogicalChannelRequest openChannelRequest = |
| 805 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 806 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 807 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 808 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 809 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 810 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 811 | } else { |
| 812 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 813 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 814 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 815 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | break; |
| 817 | |
| 818 | case EVENT_OPEN_CHANNEL_DONE: |
| 819 | ar = (AsyncResult) msg.obj; |
| 820 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 821 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 822 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 823 | int[] result = (int[]) ar.result; |
| 824 | int channelId = result[0]; |
| 825 | byte[] selectResponse = null; |
| 826 | if (result.length > 1) { |
| 827 | selectResponse = new byte[result.length - 1]; |
| 828 | for (int i = 1; i < result.length; ++i) { |
| 829 | selectResponse[i - 1] = (byte) result[i]; |
| 830 | } |
| 831 | } |
| 832 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 833 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 834 | |
| 835 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 836 | if (uiccPort == null) { |
| 837 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 838 | } else { |
| 839 | IccLogicalChannelRequest channelRequest = |
| 840 | (IccLogicalChannelRequest) request.argument; |
| 841 | channelRequest.channel = channelId; |
| 842 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 843 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 844 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 845 | if (ar.result == null) { |
| 846 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 847 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 848 | if (ar.exception != null) { |
| 849 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 850 | } |
| 851 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 852 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 853 | if (ar.exception instanceof CommandException) { |
| 854 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 855 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 856 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 857 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 858 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 859 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 863 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 864 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 865 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 866 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case CMD_CLOSE_CHANNEL: |
| 870 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 871 | uiccPort = getUiccPortFromRequest(request); |
| 872 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 873 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 874 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 875 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 876 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 877 | } else { |
| 878 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 879 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 880 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 884 | ar = (AsyncResult) msg.obj; |
| 885 | request = (MainThreadRequest) ar.userObj; |
| 886 | if (ar.exception == null) { |
| 887 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 888 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 889 | if (uiccPort == null) { |
| 890 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 891 | } else { |
| 892 | final int channelId = (Integer) request.argument; |
| 893 | uiccPort.onLogicalChannelClosed(channelId); |
| 894 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 895 | } else { |
| 896 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 897 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 898 | if (ar.exception instanceof CommandException) { |
| 899 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 900 | CommandException.Error error = |
| 901 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 902 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 903 | // should only throw exceptions from the binder threads. |
| 904 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 905 | "iccCloseLogicalChannel: invalid argument "); |
| 906 | } |
| 907 | } else { |
| 908 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 909 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 910 | request.result = (exception != null) ? exception : |
| 911 | new IllegalStateException( |
| 912 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 913 | } |
| 914 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 915 | break; |
| 916 | |
| 917 | case CMD_NV_READ_ITEM: |
| 918 | request = (MainThreadRequest) msg.obj; |
| 919 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 920 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 921 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 925 | ar = (AsyncResult) msg.obj; |
| 926 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | if (ar.exception == null && ar.result != null) { |
| 928 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 929 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 930 | request.result = ""; |
| 931 | if (ar.result == null) { |
| 932 | loge("nvReadItem: Empty response"); |
| 933 | } else if (ar.exception instanceof CommandException) { |
| 934 | loge("nvReadItem: CommandException: " + |
| 935 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 936 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 937 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 940 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 941 | break; |
| 942 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 943 | case CMD_NV_WRITE_ITEM: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 946 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 947 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 948 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case EVENT_NV_WRITE_ITEM_DONE: |
| 952 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 953 | break; |
| 954 | |
| 955 | case CMD_NV_WRITE_CDMA_PRL: |
| 956 | request = (MainThreadRequest) msg.obj; |
| 957 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 958 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 962 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 963 | break; |
| 964 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 965 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 966 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 967 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 968 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 969 | break; |
| 970 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 971 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 972 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 973 | break; |
| 974 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 975 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 976 | request = (MainThreadRequest) msg.obj; |
| 977 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 978 | request); |
| 979 | Phone phone = getPhoneFromRequest(request); |
| 980 | if (phone != null) { |
| 981 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 982 | } else { |
| 983 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 984 | request.result = false; |
| 985 | notifyRequester(request); |
| 986 | } |
| 987 | break; |
| 988 | } |
| 989 | |
| 990 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 991 | ar = (AsyncResult) msg.obj; |
| 992 | request = (MainThreadRequest) ar.userObj; |
| 993 | if (ar.exception == null && ar.result != null) { |
| 994 | request.result = ar.result; |
| 995 | } else { |
| 996 | // request.result must be set to something non-null |
| 997 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 998 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 999 | request.result = ar.result; |
| 1000 | } else { |
| 1001 | request.result = false; |
| 1002 | } |
| 1003 | if (ar.result == null) { |
| 1004 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1005 | } else if (ar.exception instanceof CommandException) { |
| 1006 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1007 | + ar.exception); |
| 1008 | } else { |
| 1009 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1010 | } |
| 1011 | } |
| 1012 | notifyRequester(request); |
| 1013 | break; |
| 1014 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1015 | case CMD_IS_VONR_ENABLED: { |
| 1016 | request = (MainThreadRequest) msg.obj; |
| 1017 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1018 | request); |
| 1019 | Phone phone = getPhoneFromRequest(request); |
| 1020 | if (phone != null) { |
| 1021 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1022 | } else { |
| 1023 | loge("isVoNrEnabled: No phone object"); |
| 1024 | request.result = false; |
| 1025 | notifyRequester(request); |
| 1026 | } |
| 1027 | break; |
| 1028 | } |
| 1029 | |
| 1030 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1031 | ar = (AsyncResult) msg.obj; |
| 1032 | request = (MainThreadRequest) ar.userObj; |
| 1033 | if (ar.exception == null && ar.result != null) { |
| 1034 | request.result = ar.result; |
| 1035 | } else { |
| 1036 | // request.result must be set to something non-null |
| 1037 | // for the calling thread to unblock |
| 1038 | if (ar.result != null) { |
| 1039 | request.result = ar.result; |
| 1040 | } else { |
| 1041 | request.result = false; |
| 1042 | } |
| 1043 | if (ar.result == null) { |
| 1044 | loge("isVoNrEnabled: Empty response"); |
| 1045 | } else if (ar.exception instanceof CommandException) { |
| 1046 | loge("isVoNrEnabled: CommandException: " |
| 1047 | + ar.exception); |
| 1048 | } else { |
| 1049 | loge("isVoNrEnabled: Unknown exception"); |
| 1050 | } |
| 1051 | } |
| 1052 | notifyRequester(request); |
| 1053 | break; |
| 1054 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1055 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1056 | request = (MainThreadRequest) msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1058 | Phone phone = getPhoneFromRequest(request); |
| 1059 | if (phone != null) { |
| 1060 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1061 | request.workSource); |
| 1062 | } else { |
| 1063 | loge("enableNrDualConnectivity: No phone object"); |
| 1064 | request.result = |
| 1065 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1066 | notifyRequester(request); |
| 1067 | } |
| 1068 | break; |
| 1069 | } |
| 1070 | |
| 1071 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | if (ar.exception == null) { |
| 1075 | request.result = |
| 1076 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1077 | } else { |
| 1078 | request.result = |
| 1079 | TelephonyManager |
| 1080 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1081 | if (ar.exception instanceof CommandException) { |
| 1082 | CommandException.Error error = |
| 1083 | ((CommandException) (ar.exception)).getCommandError(); |
| 1084 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1085 | request.result = |
| 1086 | TelephonyManager |
| 1087 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1088 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1089 | request.result = |
| 1090 | TelephonyManager |
| 1091 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1092 | } |
| 1093 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1094 | + ar.exception); |
| 1095 | } else { |
| 1096 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1097 | } |
| 1098 | } |
| 1099 | notifyRequester(request); |
| 1100 | break; |
| 1101 | } |
| 1102 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1103 | case CMD_ENABLE_VONR: { |
| 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1106 | Phone phone = getPhoneFromRequest(request); |
| 1107 | if (phone != null) { |
| 1108 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1109 | request.workSource); |
| 1110 | } else { |
| 1111 | loge("setVoNrEnabled: No phone object"); |
| 1112 | request.result = |
| 1113 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1114 | notifyRequester(request); |
| 1115 | } |
| 1116 | break; |
| 1117 | } |
| 1118 | |
| 1119 | case EVENT_ENABLE_VONR_DONE: { |
| 1120 | ar = (AsyncResult) msg.obj; |
| 1121 | request = (MainThreadRequest) ar.userObj; |
| 1122 | if (ar.exception == null) { |
| 1123 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1124 | } else { |
| 1125 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1126 | if (ar.exception instanceof CommandException) { |
| 1127 | CommandException.Error error = |
| 1128 | ((CommandException) (ar.exception)).getCommandError(); |
| 1129 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1130 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1131 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1132 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1133 | } else { |
| 1134 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1135 | } |
| 1136 | loge("setVoNrEnabled" + ": CommandException: " |
| 1137 | + ar.exception); |
| 1138 | } else { |
| 1139 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1140 | } |
| 1141 | } |
| 1142 | notifyRequester(request); |
| 1143 | break; |
| 1144 | } |
| 1145 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1146 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1147 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1148 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1149 | request); |
| 1150 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1151 | break; |
| 1152 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1153 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1154 | ar = (AsyncResult) msg.obj; |
| 1155 | request = (MainThreadRequest) ar.userObj; |
| 1156 | if (ar.exception == null && ar.result != null) { |
| 1157 | request.result = ar.result; // Integer |
| 1158 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1159 | // request.result must be set to something non-null |
| 1160 | // for the calling thread to unblock |
| 1161 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1162 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1163 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1164 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1165 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1166 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1167 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1168 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1171 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1172 | break; |
| 1173 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1174 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1175 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1176 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1177 | request); |
| 1178 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1179 | (Pair<Integer, Long>) request.argument; |
| 1180 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1181 | reasonWithNetworkTypes.first, |
| 1182 | reasonWithNetworkTypes.second, |
| 1183 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1184 | break; |
| 1185 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1186 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1187 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1188 | break; |
| 1189 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1190 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1191 | request = (MainThreadRequest) msg.obj; |
| 1192 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1193 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1194 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1195 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1196 | break; |
| 1197 | |
| 1198 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1199 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1200 | break; |
| 1201 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1202 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1203 | request = (MainThreadRequest) msg.obj; |
| 1204 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1205 | request); |
| 1206 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1207 | break; |
| 1208 | |
| 1209 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1210 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1211 | break; |
| 1212 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1213 | case CMD_PERFORM_NETWORK_SCAN: |
| 1214 | request = (MainThreadRequest) msg.obj; |
| 1215 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1216 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1217 | break; |
| 1218 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1220 | request = (MainThreadRequest) msg.obj; |
| 1221 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1223 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1224 | request.argument; |
| 1225 | int callForwardingReason = args.first; |
| 1226 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1227 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | } |
| 1229 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | ar = (AsyncResult) msg.obj; |
| 1231 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1232 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1233 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1234 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1238 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1239 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1240 | // any service for voice call. |
| 1241 | if ((callForwardInfo.serviceClass |
| 1242 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1243 | callForwardingInfo = new CallForwardingInfo( |
| 1244 | callForwardInfo.status |
| 1245 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | callForwardInfo.reason, |
| 1247 | callForwardInfo.number, |
| 1248 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | break; |
| 1250 | } |
| 1251 | } |
| 1252 | // Didn't find a call forward info for voice call. |
| 1253 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1255 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | } else { |
| 1259 | if (ar.result == null) { |
| 1260 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1261 | } |
| 1262 | if (ar.exception != null) { |
| 1263 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1264 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1265 | int errorCode = TelephonyManager |
| 1266 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | if (ar.exception instanceof CommandException) { |
| 1268 | CommandException.Error error = |
| 1269 | ((CommandException) (ar.exception)).getCommandError(); |
| 1270 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1271 | errorCode = TelephonyManager |
| 1272 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1274 | errorCode = TelephonyManager |
| 1275 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | } |
| 1277 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | request = (MainThreadRequest) msg.obj; |
| 1285 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1287 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1289 | request.argument).first; |
| 1290 | request.phone.setCallForwardingOption( |
| 1291 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1292 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | callForwardingInfoToSet.getReason(), |
| 1295 | callForwardingInfoToSet.getNumber(), |
| 1296 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1297 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | ar = (AsyncResult) msg.obj; |
| 1302 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | Consumer<Integer> callback = |
| 1304 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1305 | request.argument).second; |
| 1306 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1308 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1309 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | if (ar.exception instanceof CommandException) { |
| 1311 | CommandException.Error error = |
| 1312 | ((CommandException) (ar.exception)).getCommandError(); |
| 1313 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1314 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1315 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1317 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1318 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | callback.accept(errorCode); |
| 1322 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1323 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1326 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | request = (MainThreadRequest) msg.obj; |
| 1330 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1331 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1332 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1333 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1335 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | ar = (AsyncResult) msg.obj; |
| 1337 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1338 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1339 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1341 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | // Service Class is a bit mask per 3gpp 27.007. |
| 1343 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1344 | if (callForwardResults.length > 1 |
| 1345 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1346 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1347 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1348 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1349 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1351 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | } |
| 1353 | } else { |
| 1354 | if (ar.result == null) { |
| 1355 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1356 | } |
| 1357 | if (ar.exception != null) { |
| 1358 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1359 | } |
| 1360 | if (ar.exception instanceof CommandException) { |
| 1361 | CommandException.Error error = |
| 1362 | ((CommandException) (ar.exception)).getCommandError(); |
| 1363 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1364 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1366 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1367 | callWaitingStatus = |
| 1368 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1372 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1373 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1374 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | request = (MainThreadRequest) msg.obj; |
| 1378 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1380 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1382 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1383 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1384 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1387 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1388 | Consumer<Integer> callback = |
| 1389 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1390 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1392 | if (ar.exception instanceof CommandException) { |
| 1393 | CommandException.Error error = |
| 1394 | ((CommandException) (ar.exception)).getCommandError(); |
| 1395 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1396 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1397 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1398 | callback.accept( |
| 1399 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1400 | } else { |
| 1401 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1402 | } |
| 1403 | } else { |
| 1404 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1405 | } |
| 1406 | } else { |
| 1407 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1408 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1409 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1410 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1411 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1413 | ar = (AsyncResult) msg.obj; |
| 1414 | request = (MainThreadRequest) ar.userObj; |
| 1415 | CellNetworkScanResult cellScanResult; |
| 1416 | if (ar.exception == null && ar.result != null) { |
| 1417 | cellScanResult = new CellNetworkScanResult( |
| 1418 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1419 | (List<OperatorInfo>) ar.result); |
| 1420 | } else { |
| 1421 | if (ar.result == null) { |
| 1422 | loge("getCellNetworkScanResults: Empty response"); |
| 1423 | } |
| 1424 | if (ar.exception != null) { |
| 1425 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1426 | } |
| 1427 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1428 | if (ar.exception instanceof CommandException) { |
| 1429 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1430 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1431 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1432 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1433 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1434 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1435 | } |
| 1436 | } |
| 1437 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1438 | } |
| 1439 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1440 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1444 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1445 | ManualNetworkSelectionArgument selArg = |
| 1446 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1447 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1448 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1449 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1450 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | |
| 1453 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
| 1456 | if (ar.exception == null) { |
| 1457 | request.result = true; |
| 1458 | } else { |
| 1459 | request.result = false; |
| 1460 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1461 | } |
| 1462 | notifyRequester(request); |
| 1463 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1464 | break; |
| 1465 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1467 | request = (MainThreadRequest) msg.obj; |
| 1468 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1469 | if (defaultPhone != null) { |
| 1470 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1471 | } else { |
| 1472 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1473 | Bundle bundle = new Bundle(); |
| 1474 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1475 | new ModemActivityInfo(0, 0, 0, |
| 1476 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1477 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1478 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | break; |
| 1480 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1481 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1482 | ar = (AsyncResult) msg.obj; |
| 1483 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1484 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1485 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1486 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1487 | if (mLastModemActivityInfo == null) { |
| 1488 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1489 | mLastModemActivitySpecificInfo[0] = |
| 1490 | new ActivityStatsTechSpecificInfo( |
| 1491 | 0, |
| 1492 | 0, |
| 1493 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1494 | 0); |
| 1495 | mLastModemActivityInfo = |
| 1496 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1497 | } |
| 1498 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1499 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1500 | // Update the last modem activity info and the result of the request. |
| 1501 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1502 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1503 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1504 | } else { |
| 1505 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1506 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1507 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1508 | // We don't want to return mLastModemActivityInfo which is updated |
| 1509 | // inside mergeModemActivityInfo() |
| 1510 | ret = new ModemActivityInfo( |
| 1511 | mLastModemActivityInfo.getTimestampMillis(), |
| 1512 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1513 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1514 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1515 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1516 | } else { |
| 1517 | if (ar.result == null) { |
| 1518 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1519 | error = TelephonyManager.ModemActivityInfoException |
| 1520 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1521 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1522 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | error = TelephonyManager.ModemActivityInfoException |
| 1524 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1525 | } else { |
| 1526 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1527 | error = TelephonyManager.ModemActivityInfoException |
| 1528 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1529 | } |
| 1530 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1531 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1532 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1533 | bundle.putParcelable( |
| 1534 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1535 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1536 | } else { |
| 1537 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1538 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1539 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1540 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1541 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1542 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1543 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1544 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1546 | CarrierRestrictionRules argument = |
| 1547 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1548 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1549 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1550 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1551 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1552 | |
| 1553 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1554 | ar = (AsyncResult) msg.obj; |
| 1555 | request = (MainThreadRequest) ar.userObj; |
| 1556 | if (ar.exception == null && ar.result != null) { |
| 1557 | request.result = ar.result; |
| 1558 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1559 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1560 | if (ar.exception instanceof CommandException) { |
| 1561 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1562 | CommandException.Error error = |
| 1563 | ((CommandException) (ar.exception)).getCommandError(); |
| 1564 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1565 | request.result = |
| 1566 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1567 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1568 | } else { |
| 1569 | loge("setAllowedCarriers: Unknown exception"); |
| 1570 | } |
| 1571 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1572 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | case CMD_GET_ALLOWED_CARRIERS: |
| 1576 | request = (MainThreadRequest) msg.obj; |
| 1577 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1578 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1579 | break; |
| 1580 | |
| 1581 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1582 | ar = (AsyncResult) msg.obj; |
| 1583 | request = (MainThreadRequest) ar.userObj; |
| 1584 | if (ar.exception == null && ar.result != null) { |
| 1585 | request.result = ar.result; |
| 1586 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1587 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1588 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1589 | if (ar.result == null) { |
| 1590 | loge("getAllowedCarriers: Empty response"); |
| 1591 | } else if (ar.exception instanceof CommandException) { |
| 1592 | loge("getAllowedCarriers: CommandException: " + |
| 1593 | ar.exception); |
| 1594 | } else { |
| 1595 | loge("getAllowedCarriers: Unknown exception"); |
| 1596 | } |
| 1597 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1598 | if (request.argument != null) { |
| 1599 | // This is for the implementation of carrierRestrictionStatus. |
| 1600 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1601 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1602 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1603 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1604 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1605 | CarrierRestrictionRules carrierRestrictionRules = |
| 1606 | (CarrierRestrictionRules) ar.result; |
| 1607 | int carrierId = -1; |
| 1608 | try { |
| 1609 | CarrierIdentifier carrierIdentifier = |
| 1610 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1611 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1612 | carrierIdentifier); |
| 1613 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1614 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1615 | } |
| 1616 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1617 | int restrictedStatus = |
| 1618 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1619 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1620 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1621 | lockStatus = TelephonyManager |
| 1622 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1623 | } |
| 1624 | } else { |
| 1625 | Rlog.e(LOG_TAG, |
| 1626 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1627 | } |
| 1628 | callback.accept(lockStatus); |
| 1629 | } else { |
| 1630 | // This is for the implementation of getAllowedCarriers. |
| 1631 | notifyRequester(request); |
| 1632 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1633 | break; |
| 1634 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1635 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1636 | ar = (AsyncResult) msg.obj; |
| 1637 | request = (MainThreadRequest) ar.userObj; |
| 1638 | if (ar.exception == null && ar.result != null) { |
| 1639 | request.result = ar.result; |
| 1640 | } else { |
| 1641 | request.result = new IllegalArgumentException( |
| 1642 | "Failed to retrieve Forbidden Plmns"); |
| 1643 | if (ar.result == null) { |
| 1644 | loge("getForbiddenPlmns: Empty response"); |
| 1645 | } else { |
| 1646 | loge("getForbiddenPlmns: Unknown exception"); |
| 1647 | } |
| 1648 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1649 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1650 | break; |
| 1651 | |
| 1652 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1653 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1654 | uiccPort = getUiccPortFromRequest(request); |
| 1655 | if (uiccPort == null) { |
| 1656 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1657 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1658 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1659 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1660 | break; |
| 1661 | } |
| 1662 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1663 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1664 | if (uiccApp == null) { |
| 1665 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1666 | + appType); |
| 1667 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1668 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1669 | break; |
| 1670 | } else { |
| 1671 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1672 | + " specified type -- " + appType); |
| 1673 | } |
| 1674 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1675 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1676 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1677 | break; |
| 1678 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1679 | case CMD_SWITCH_SLOTS: |
| 1680 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1681 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1682 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1683 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1684 | break; |
| 1685 | |
| 1686 | case EVENT_SWITCH_SLOTS_DONE: |
| 1687 | ar = (AsyncResult) msg.obj; |
| 1688 | request = (MainThreadRequest) ar.userObj; |
| 1689 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1690 | notifyRequester(request); |
| 1691 | break; |
| 1692 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1695 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1696 | break; |
| 1697 | |
| 1698 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1699 | ar = (AsyncResult) msg.obj; |
| 1700 | request = (MainThreadRequest) ar.userObj; |
| 1701 | if (ar.exception != null) { |
| 1702 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1703 | } else { |
| 1704 | int mode = ((int[]) ar.result)[0]; |
| 1705 | if (mode == 0) { |
| 1706 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1707 | } else { |
| 1708 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1709 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1710 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1711 | notifyRequester(request); |
| 1712 | break; |
| 1713 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1714 | request = (MainThreadRequest) msg.obj; |
| 1715 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1716 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1717 | break; |
| 1718 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1719 | ar = (AsyncResult) msg.obj; |
| 1720 | request = (MainThreadRequest) ar.userObj; |
| 1721 | if (ar.exception != null) { |
| 1722 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1723 | } else { |
| 1724 | request.result = ((int[]) ar.result)[0]; |
| 1725 | } |
| 1726 | notifyRequester(request); |
| 1727 | break; |
| 1728 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1729 | request = (MainThreadRequest) msg.obj; |
| 1730 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1731 | int mode = (int) request.argument; |
| 1732 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1733 | break; |
| 1734 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1735 | ar = (AsyncResult) msg.obj; |
| 1736 | request = (MainThreadRequest) ar.userObj; |
| 1737 | request.result = ar.exception == null; |
| 1738 | notifyRequester(request); |
| 1739 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1740 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1741 | request = (MainThreadRequest) msg.obj; |
| 1742 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1743 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1744 | break; |
| 1745 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1746 | ar = (AsyncResult) msg.obj; |
| 1747 | request = (MainThreadRequest) ar.userObj; |
| 1748 | if (ar.exception != null) { |
| 1749 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1750 | } else { |
| 1751 | request.result = ((int[]) ar.result)[0]; |
| 1752 | } |
| 1753 | notifyRequester(request); |
| 1754 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1755 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1758 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1759 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1760 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1761 | break; |
| 1762 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1763 | ar = (AsyncResult) msg.obj; |
| 1764 | request = (MainThreadRequest) ar.userObj; |
| 1765 | request.result = ar.exception == null; |
| 1766 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1767 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1768 | case CMD_GET_ALL_CELL_INFO: |
| 1769 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1770 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1771 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1772 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1773 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1774 | ar = (AsyncResult) msg.obj; |
| 1775 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1776 | // If a timeout occurs, the response will be null |
| 1777 | request.result = (ar.exception == null && ar.result != null) |
| 1778 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1779 | synchronized (request) { |
| 1780 | request.notifyAll(); |
| 1781 | } |
| 1782 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1783 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1784 | request = (MainThreadRequest) msg.obj; |
| 1785 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1786 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1787 | break; |
| 1788 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1789 | ar = (AsyncResult) msg.obj; |
| 1790 | request = (MainThreadRequest) ar.userObj; |
| 1791 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1792 | try { |
| 1793 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1794 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1795 | cb.onError( |
| 1796 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1797 | ar.exception.getClass().getName(), |
| 1798 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1799 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1800 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1801 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1802 | } else { |
| 1803 | // use the result as returned |
| 1804 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1805 | } |
| 1806 | } catch (RemoteException re) { |
| 1807 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1808 | } |
| 1809 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1810 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1811 | request = (MainThreadRequest) msg.obj; |
| 1812 | WorkSource ws = (WorkSource) request.argument; |
| 1813 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1814 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1815 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1816 | } |
| 1817 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1818 | ar = (AsyncResult) msg.obj; |
| 1819 | request = (MainThreadRequest) ar.userObj; |
| 1820 | if (ar.exception == null) { |
| 1821 | request.result = ar.result; |
| 1822 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1823 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1824 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1825 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | synchronized (request) { |
| 1829 | request.notifyAll(); |
| 1830 | } |
| 1831 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1832 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1833 | case CMD_MODEM_REBOOT: |
| 1834 | request = (MainThreadRequest) msg.obj; |
| 1835 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1836 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1837 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1838 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1839 | handleNullReturnEvent(msg, "rebootModem"); |
| 1840 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1841 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1842 | request = (MainThreadRequest) msg.obj; |
| 1843 | boolean enable = (boolean) request.argument; |
| 1844 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1845 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1846 | PhoneConfigurationManager.getInstance() |
| 1847 | .enablePhone(request.phone, enable, onCompleted); |
| 1848 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1849 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1850 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1851 | ar = (AsyncResult) msg.obj; |
| 1852 | request = (MainThreadRequest) ar.userObj; |
| 1853 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1854 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1855 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1856 | if ((boolean) request.result) { |
| 1857 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1858 | updateModemStateMetrics(); |
| 1859 | } else { |
| 1860 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1861 | + ar.exception); |
| 1862 | } |
| 1863 | notifyRequester(request); |
| 1864 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1865 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1866 | case CMD_GET_MODEM_STATUS: |
| 1867 | request = (MainThreadRequest) msg.obj; |
| 1868 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1869 | PhoneConfigurationManager.getInstance() |
| 1870 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1871 | break; |
| 1872 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1873 | ar = (AsyncResult) msg.obj; |
| 1874 | request = (MainThreadRequest) ar.userObj; |
| 1875 | int id = request.phone.getPhoneId(); |
| 1876 | if (ar.exception == null && ar.result != null) { |
| 1877 | request.result = ar.result; |
| 1878 | //update the cache as modem status has changed |
| 1879 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1880 | (boolean) request.result); |
| 1881 | } else { |
| 1882 | // Return true if modem status cannot be retrieved. For most cases, |
| 1883 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1884 | // and disable modem are not supported. Modem is always on. |
| 1885 | // TODO: this should be fixed in R to support a third |
| 1886 | // status UNKNOWN b/131631629 |
| 1887 | request.result = true; |
| 1888 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1889 | + ar.exception); |
| 1890 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1891 | notifyRequester(request); |
| 1892 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1893 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1894 | request = (MainThreadRequest) msg.obj; |
| 1895 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1896 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1897 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1898 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1899 | break; |
| 1900 | } |
| 1901 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1902 | ar = (AsyncResult) msg.obj; |
| 1903 | request = (MainThreadRequest) ar.userObj; |
| 1904 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1905 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1906 | args.second.accept(ar.exception == null); |
| 1907 | notifyRequester(request); |
| 1908 | break; |
| 1909 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1910 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1911 | request = (MainThreadRequest) msg.obj; |
| 1912 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1913 | Phone phone = getPhoneFromRequest(request); |
| 1914 | if (phone != null) { |
| 1915 | phone.getSystemSelectionChannels(onCompleted); |
| 1916 | } else { |
| 1917 | loge("getSystemSelectionChannels: No phone object"); |
| 1918 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1919 | notifyRequester(request); |
| 1920 | } |
| 1921 | break; |
| 1922 | } |
| 1923 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1924 | ar = (AsyncResult) msg.obj; |
| 1925 | request = (MainThreadRequest) ar.userObj; |
| 1926 | if (ar.exception == null && ar.result != null) { |
| 1927 | request.result = ar.result; |
| 1928 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1929 | request.result = new IllegalStateException( |
| 1930 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1931 | if (ar.result == null) { |
| 1932 | loge("getSystemSelectionChannels: Empty response"); |
| 1933 | } else { |
| 1934 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1935 | } |
| 1936 | } |
| 1937 | notifyRequester(request); |
| 1938 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1939 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1940 | ar = (AsyncResult) msg.obj; |
| 1941 | request = (MainThreadRequest) ar.userObj; |
| 1942 | if (ar.exception == null && ar.result != null) { |
| 1943 | request.result = ar.result; |
| 1944 | } else { |
| 1945 | request.result = -1; |
| 1946 | loge("Failed to set Forbidden Plmns"); |
| 1947 | if (ar.result == null) { |
| 1948 | loge("setForbidenPlmns: Empty response"); |
| 1949 | } else if (ar.exception != null) { |
| 1950 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1951 | request.result = -1; |
| 1952 | } else { |
| 1953 | loge("setForbiddenPlmns: Unknown exception"); |
| 1954 | } |
| 1955 | } |
| 1956 | notifyRequester(request); |
| 1957 | break; |
| 1958 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1959 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1960 | uiccPort = getUiccPortFromRequest(request); |
| 1961 | if (uiccPort == null) { |
| 1962 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1963 | request.result = -1; |
| 1964 | notifyRequester(request); |
| 1965 | break; |
| 1966 | } |
| 1967 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1968 | (Pair<Integer, List<String>>) request.argument; |
| 1969 | appType = setFplmnsArgs.first; |
| 1970 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1971 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1972 | if (uiccApp == null) { |
| 1973 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1974 | request.result = -1; |
| 1975 | loge("Failed to get UICC App"); |
| 1976 | notifyRequester(request); |
| 1977 | } else { |
| 1978 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1979 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1980 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1981 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1982 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1983 | case CMD_ERASE_MODEM_CONFIG: |
| 1984 | request = (MainThreadRequest) msg.obj; |
| 1985 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1986 | defaultPhone.eraseModemConfig(onCompleted); |
| 1987 | break; |
| 1988 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1989 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1990 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1991 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1992 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1993 | request = (MainThreadRequest) msg.obj; |
| 1994 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1995 | notifyRequester(request); |
| 1996 | break; |
| 1997 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1998 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1999 | request = (MainThreadRequest) msg.obj; |
| 2000 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2001 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2002 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2003 | changed.first, changed.second, onCompleted); |
| 2004 | break; |
| 2005 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2006 | ar = (AsyncResult) msg.obj; |
| 2007 | request = (MainThreadRequest) ar.userObj; |
| 2008 | if (ar.exception == null) { |
| 2009 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2010 | // If the operation is successful, update the PIN storage |
| 2011 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2012 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2013 | UiccController.getInstance().getPinStorage() |
| 2014 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2015 | } else { |
| 2016 | request.result = msg.arg1; |
| 2017 | } |
| 2018 | notifyRequester(request); |
| 2019 | break; |
| 2020 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2021 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2022 | request = (MainThreadRequest) msg.obj; |
| 2023 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2024 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2025 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2026 | enabled.first, enabled.second, onCompleted); |
| 2027 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2028 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2029 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2030 | ar = (AsyncResult) msg.obj; |
| 2031 | request = (MainThreadRequest) ar.userObj; |
| 2032 | if (ar.exception == null) { |
| 2033 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2034 | // If the operation is successful, update the PIN storage |
| 2035 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2036 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2037 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2038 | UiccController.getInstance().getPinStorage() |
| 2039 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2040 | } else { |
| 2041 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2042 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2043 | } else { |
| 2044 | request.result = msg.arg1; |
| 2045 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2046 | |
| 2047 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2048 | notifyRequester(request); |
| 2049 | break; |
| 2050 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2051 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2052 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2053 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2054 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2055 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2056 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2057 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2058 | |
| 2059 | case CMD_SET_DATA_THROTTLING: { |
| 2060 | request = (MainThreadRequest) msg.obj; |
| 2061 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2062 | DataThrottlingRequest dataThrottlingRequest = |
| 2063 | (DataThrottlingRequest) request.argument; |
| 2064 | Phone phone = getPhoneFromRequest(request); |
| 2065 | if (phone != null) { |
| 2066 | phone.setDataThrottling(onCompleted, |
| 2067 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2068 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2069 | } else { |
| 2070 | loge("setDataThrottling: No phone object"); |
| 2071 | request.result = |
| 2072 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2073 | notifyRequester(request); |
| 2074 | } |
| 2075 | |
| 2076 | break; |
| 2077 | } |
| 2078 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2079 | ar = (AsyncResult) msg.obj; |
| 2080 | request = (MainThreadRequest) ar.userObj; |
| 2081 | |
| 2082 | if (ar.exception == null) { |
| 2083 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2084 | } else if (ar.exception instanceof CommandException) { |
| 2085 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2086 | CommandException.Error error = |
| 2087 | ((CommandException) (ar.exception)).getCommandError(); |
| 2088 | |
| 2089 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2090 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2091 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2092 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2093 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2094 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2095 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2096 | } else { |
| 2097 | request.result = |
| 2098 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2099 | } |
| 2100 | } else { |
| 2101 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2102 | } |
| 2103 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2104 | notifyRequester(request); |
| 2105 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2106 | |
| 2107 | case CMD_SET_SIM_POWER: { |
| 2108 | request = (MainThreadRequest) msg.obj; |
| 2109 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2110 | request = (MainThreadRequest) msg.obj; |
| 2111 | int stateToSet = |
| 2112 | ((Pair<Integer, IIntegerConsumer>) |
| 2113 | request.argument).first; |
| 2114 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2115 | break; |
| 2116 | } |
| 2117 | case EVENT_SET_SIM_POWER_DONE: { |
| 2118 | ar = (AsyncResult) msg.obj; |
| 2119 | request = (MainThreadRequest) ar.userObj; |
| 2120 | IIntegerConsumer callback = |
| 2121 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2122 | if (ar.exception != null) { |
| 2123 | loge("setSimPower exception: " + ar.exception); |
| 2124 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2125 | .RESULT_ERROR_UNKNOWN; |
| 2126 | if (ar.exception instanceof CommandException) { |
| 2127 | CommandException.Error error = |
| 2128 | ((CommandException) (ar.exception)).getCommandError(); |
| 2129 | if (error == CommandException.Error.SIM_ERR) { |
| 2130 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2131 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2132 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2133 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2134 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2135 | } else { |
| 2136 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2137 | } |
| 2138 | } |
| 2139 | try { |
| 2140 | callback.accept(errorCode); |
| 2141 | } catch (RemoteException e) { |
| 2142 | // Ignore if the remote process is no longer available to call back. |
| 2143 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2144 | } |
| 2145 | } else { |
| 2146 | try { |
| 2147 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2148 | } catch (RemoteException e) { |
| 2149 | // Ignore if the remote process is no longer available to call back. |
| 2150 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2151 | } |
| 2152 | } |
| 2153 | break; |
| 2154 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2155 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2156 | request = (MainThreadRequest) msg.obj; |
| 2157 | |
| 2158 | final Phone phone = getPhoneFromRequest(request); |
| 2159 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2160 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2161 | notifyRequester(request); |
| 2162 | break; |
| 2163 | } |
| 2164 | |
| 2165 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2166 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2167 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2168 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2169 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2170 | request.subId, pair.first /*callingUid*/, |
| 2171 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2175 | ar = (AsyncResult) msg.obj; |
| 2176 | request = (MainThreadRequest) ar.userObj; |
| 2177 | // request.result will be the exception of ar if present, true otherwise. |
| 2178 | // Be cautious not to leave result null which will wait() forever |
| 2179 | request.result = ar.exception != null ? ar.exception : true; |
| 2180 | notifyRequester(request); |
| 2181 | break; |
| 2182 | } |
| 2183 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2184 | request = (MainThreadRequest) msg.obj; |
| 2185 | |
| 2186 | Phone phone = getPhoneFromRequest(request); |
| 2187 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2188 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2189 | notifyRequester(request); |
| 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2194 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2195 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2196 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2197 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2198 | request.subId, pair.first /*callingUid*/, |
| 2199 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2200 | break; |
| 2201 | } |
| 2202 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2203 | ar = (AsyncResult) msg.obj; |
| 2204 | request = (MainThreadRequest) ar.userObj; |
| 2205 | request.result = ar.exception != null ? ar.exception : true; |
| 2206 | notifyRequester(request); |
| 2207 | break; |
| 2208 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2209 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2210 | case CMD_GET_SLICING_CONFIG: { |
| 2211 | request = (MainThreadRequest) msg.obj; |
| 2212 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2213 | request.phone.getSlicingConfig(onCompleted); |
| 2214 | break; |
| 2215 | } |
| 2216 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2217 | ar = (AsyncResult) msg.obj; |
| 2218 | request = (MainThreadRequest) ar.userObj; |
| 2219 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2220 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2221 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2222 | Bundle bundle = new Bundle(); |
| 2223 | int resultCode = 0; |
| 2224 | if (ar.exception != null) { |
| 2225 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2226 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2227 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2228 | } else if (ar.result == null) { |
| 2229 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2230 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2231 | } else { |
| 2232 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2233 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2234 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2238 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2239 | } |
| 2240 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2241 | result.send(resultCode, bundle); |
| 2242 | notifyRequester(request); |
| 2243 | break; |
| 2244 | } |
| 2245 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2246 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2247 | request = (MainThreadRequest) msg.obj; |
| 2248 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | PurchasePremiumCapabilityArgument arg = |
| 2250 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2251 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2252 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2253 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2254 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2255 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 | ar = (AsyncResult) msg.obj; |
| 2258 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2259 | PurchasePremiumCapabilityArgument arg = |
| 2260 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | try { |
| 2262 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2263 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2264 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2265 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2266 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2267 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2268 | } catch (RemoteException e) { |
| 2269 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2270 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2271 | + " failed: " + e; |
| 2272 | if (DBG) log(logStr); |
| 2273 | AnomalyReporter.reportAnomaly( |
| 2274 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2275 | } |
| 2276 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2277 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2278 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2279 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2280 | request = (MainThreadRequest) msg.obj; |
| 2281 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2282 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2283 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2284 | notifyRequester(request); |
| 2285 | break; |
| 2286 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | default: |
| 2288 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2289 | break; |
| 2290 | } |
| 2291 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2292 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2293 | private void notifyRequester(MainThreadRequest request) { |
| 2294 | synchronized (request) { |
| 2295 | request.notifyAll(); |
| 2296 | } |
| 2297 | } |
| 2298 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2299 | private void handleNullReturnEvent(Message msg, String command) { |
| 2300 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2301 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2302 | if (ar.exception == null) { |
| 2303 | request.result = true; |
| 2304 | } else { |
| 2305 | request.result = false; |
| 2306 | if (ar.exception instanceof CommandException) { |
| 2307 | loge(command + ": CommandException: " + ar.exception); |
| 2308 | } else { |
| 2309 | loge(command + ": Unknown exception"); |
| 2310 | } |
| 2311 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2312 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2313 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * Posts the specified command to be executed on the main thread, |
| 2318 | * waits for the request to complete, and returns the result. |
| 2319 | * @see #sendRequestAsync |
| 2320 | */ |
| 2321 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2322 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2323 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * Posts the specified command to be executed on the main thread, |
| 2328 | * waits for the request to complete, and returns the result. |
| 2329 | * @see #sendRequestAsync |
| 2330 | */ |
| 2331 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2332 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2333 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * Posts the specified command to be executed on the main thread, |
| 2338 | * waits for the request to complete, and returns the result. |
| 2339 | * @see #sendRequestAsync |
| 2340 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2341 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2342 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2343 | } |
| 2344 | |
| 2345 | /** |
| 2346 | * Posts the specified command to be executed on the main thread, |
| 2347 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2348 | * if not timeout or null otherwise. |
| 2349 | * @see #sendRequestAsync |
| 2350 | */ |
| 2351 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2352 | long timeoutInMs) { |
| 2353 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /** |
| 2357 | * Posts the specified command to be executed on the main thread, |
| 2358 | * waits for the request to complete, and returns the result. |
| 2359 | * @see #sendRequestAsync |
| 2360 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2361 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2362 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * Posts the specified command to be executed on the main thread, |
| 2367 | * waits for the request to complete, and returns the result. |
| 2368 | * @see #sendRequestAsync |
| 2369 | */ |
| 2370 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2371 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2372 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2377 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2378 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2379 | * @see #sendRequestAsync |
| 2380 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2381 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2382 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2384 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2385 | } |
| 2386 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2387 | MainThreadRequest request = null; |
| 2388 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2389 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2390 | } else if (phone != null) { |
| 2391 | request = new MainThreadRequest(argument, phone, workSource); |
| 2392 | } else { |
| 2393 | request = new MainThreadRequest(argument, subId, workSource); |
| 2394 | } |
| 2395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2397 | msg.sendToTarget(); |
| 2398 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2401 | if (timeoutInMs >= 0) { |
| 2402 | // Wait for at least timeoutInMs before returning null request result |
| 2403 | long now = SystemClock.elapsedRealtime(); |
| 2404 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2405 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2406 | try { |
| 2407 | request.wait(deadline - now); |
| 2408 | } catch (InterruptedException e) { |
| 2409 | // Do nothing, go back and check if request is completed or timeout |
| 2410 | } finally { |
| 2411 | now = SystemClock.elapsedRealtime(); |
| 2412 | } |
| 2413 | } |
| 2414 | } else { |
| 2415 | // Wait for the request to complete |
| 2416 | while (request.result == null) { |
| 2417 | try { |
| 2418 | request.wait(); |
| 2419 | } catch (InterruptedException e) { |
| 2420 | // Do nothing, go back and wait until the request is complete |
| 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2425 | if (request.result == null) { |
| 2426 | Log.wtf(LOG_TAG, |
| 2427 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | return request.result; |
| 2430 | } |
| 2431 | |
| 2432 | /** |
| 2433 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2434 | * Posts the specified command to be executed on the main thread, and |
| 2435 | * returns immediately. |
| 2436 | * @see #sendRequest |
| 2437 | */ |
| 2438 | private void sendRequestAsync(int command) { |
| 2439 | mMainThreadHandler.sendEmptyMessage(command); |
| 2440 | } |
| 2441 | |
| 2442 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2443 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2444 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2445 | */ |
| 2446 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2447 | sendRequestAsync(command, argument, null, null); |
| 2448 | } |
| 2449 | |
| 2450 | /** |
| 2451 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2452 | * @see {@link #sendRequest(int,Object)} |
| 2453 | */ |
| 2454 | private void sendRequestAsync( |
| 2455 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2456 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2457 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2458 | msg.sendToTarget(); |
| 2459 | } |
| 2460 | |
| 2461 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2463 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2464 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2465 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | synchronized (PhoneInterfaceManager.class) { |
| 2467 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2468 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | } else { |
| 2470 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2471 | } |
| 2472 | return sInstance; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2477 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2479 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2480 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2482 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2483 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2484 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2486 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2487 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2488 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2489 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2490 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2491 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2492 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2493 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2494 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2495 | mVendorApiLevel = SystemProperties.getInt( |
| 2496 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2497 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2498 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2500 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2501 | |
| 2502 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2503 | // entitlementStatus for satellite service. |
| 2504 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2507 | @VisibleForTesting |
| 2508 | public SharedPreferences getSharedPreferences() { |
| 2509 | return mTelephonySharedPreferences; |
| 2510 | } |
| 2511 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2512 | /** |
| 2513 | * Get the default phone for this device. |
| 2514 | */ |
| 2515 | @VisibleForTesting |
| 2516 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2517 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2518 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2519 | } |
| 2520 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | private void publish() { |
| 2522 | if (DBG) log("publish: " + this); |
| 2523 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2524 | TelephonyFrameworkInitializer |
| 2525 | .getTelephonyServiceManager() |
| 2526 | .getTelephonyServiceRegisterer() |
| 2527 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2530 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2531 | if (request.phone != null) { |
| 2532 | return request.phone; |
| 2533 | } else { |
| 2534 | return getPhoneFromSubId(request.subId); |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | private Phone getPhoneFromSubId(int subId) { |
| 2539 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2540 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2543 | /** |
| 2544 | * Get phone object associated with a subscription. |
| 2545 | * Return default phone if phone object associated with subscription is null |
| 2546 | * @param subId - subscriptionId |
| 2547 | * @return phone object associated with a subscription or default phone if null. |
| 2548 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2549 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2550 | Phone phone = getPhoneFromSubId(subId); |
| 2551 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2552 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2553 | phone = getDefaultPhone(); |
| 2554 | } |
| 2555 | return phone; |
| 2556 | } |
| 2557 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2558 | @Nullable |
| 2559 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2560 | Phone phone = getPhoneFromRequest(request); |
| 2561 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2562 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2563 | } |
| 2564 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2565 | /** |
| 2566 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2567 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2568 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2569 | * @return The Phone associated the sub Id |
| 2570 | */ |
| 2571 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2572 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2574 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2575 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2576 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2577 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2578 | } |
| 2579 | |
| 2580 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2581 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2582 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2585 | private boolean isImsAvailableOnDevice() { |
| 2586 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2587 | if (pm == null) { |
| 2588 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2589 | // so do not throw error and allow. |
| 2590 | return true; |
| 2591 | } |
| 2592 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2593 | } |
| 2594 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2596 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2597 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2598 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2599 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2602 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | if (DBG) log("dial: " + number); |
| 2604 | // No permission check needed here: This is just a wrapper around the |
| 2605 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2606 | // the UI before it does anything. |
| 2607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | String url = createTelUrl(number); |
| 2611 | if (url == null) { |
| 2612 | return; |
| 2613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2616 | PhoneConstants.State state = mCM.getState(subId); |
| 2617 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2618 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2619 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2620 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | } |
| 2622 | } finally { |
| 2623 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2628 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2631 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | if (DBG) log("call: " + number); |
| 2633 | |
| 2634 | // 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] | 2635 | // need to do a permission check since we're calling startActivityAsUser() |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | // from the context of the phone app. |
| 2637 | enforceCallPermission(); |
| 2638 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2639 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2640 | != AppOpsManager.MODE_ALLOWED) { |
| 2641 | return; |
| 2642 | } |
| 2643 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2644 | enforceTelephonyFeatureWithException(callingPackage, |
| 2645 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | final long identity = Binder.clearCallingIdentity(); |
| 2648 | try { |
| 2649 | String url = createTelUrl(number); |
| 2650 | if (url == null) { |
| 2651 | return; |
| 2652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | boolean isValid = false; |
| 2655 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2656 | if (slist != null) { |
| 2657 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2658 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2659 | isValid = true; |
| 2660 | break; |
| 2661 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2662 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | if (!isValid) { |
| 2665 | return; |
| 2666 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2667 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2669 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2670 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2671 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
| 2674 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2677 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2678 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2679 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2680 | } |
| 2681 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2682 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2683 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2684 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2685 | } |
| 2686 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2687 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2689 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2690 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2691 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2692 | "supplyPinReportResultForSubscriber"); |
| 2693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | final long identity = Binder.clearCallingIdentity(); |
| 2695 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2696 | Phone phone = getPhone(subId); |
| 2697 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | checkSimPin.start(); |
| 2699 | return checkSimPin.unlockSim(null, pin); |
| 2700 | } finally { |
| 2701 | Binder.restoreCallingIdentity(identity); |
| 2702 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2705 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2706 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2708 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2709 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2711 | final long identity = Binder.clearCallingIdentity(); |
| 2712 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2713 | Phone phone = getPhone(subId); |
| 2714 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | checkSimPuk.start(); |
| 2716 | return checkSimPuk.unlockSim(puk, pin); |
| 2717 | } finally { |
| 2718 | Binder.restoreCallingIdentity(identity); |
| 2719 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2723 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | * a synchronous one. |
| 2725 | */ |
| 2726 | private static class UnlockSim extends Thread { |
| 2727 | |
| 2728 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2729 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | |
| 2731 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2732 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2733 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | |
| 2735 | // For replies from SimCard interface |
| 2736 | private Handler mHandler; |
| 2737 | |
| 2738 | // For async handler to identify request type |
| 2739 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2740 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2741 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2742 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2743 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2745 | UnlockSim(int phoneId, IccCard simCard) { |
| 2746 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | mSimCard = simCard; |
| 2748 | } |
| 2749 | |
| 2750 | @Override |
| 2751 | public void run() { |
| 2752 | Looper.prepare(); |
| 2753 | synchronized (UnlockSim.this) { |
| 2754 | mHandler = new Handler() { |
| 2755 | @Override |
| 2756 | public void handleMessage(Message msg) { |
| 2757 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2758 | switch (msg.what) { |
| 2759 | case SUPPLY_PIN_COMPLETE: |
| 2760 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2761 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2762 | mRetryCount = msg.arg1; |
| 2763 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2764 | CommandException.Error error = null; |
| 2765 | if (ar.exception instanceof CommandException) { |
| 2766 | error = ((CommandException) (ar.exception)) |
| 2767 | .getCommandError(); |
| 2768 | } |
| 2769 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2770 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2771 | } else if (error == CommandException.Error.ABORTED) { |
| 2772 | /* When UiccCardApp dispose, handle message and return |
| 2773 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2774 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2775 | } else { |
| 2776 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2777 | } |
| 2778 | } else { |
| 2779 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2780 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2781 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2782 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | UnlockSim.this.notifyAll(); |
| 2784 | } |
| 2785 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2786 | case SUPPLY_PIN_DELAYED: |
| 2787 | if(!mDone) { |
| 2788 | String logStr = "Delay in receiving SIM PIN response "; |
| 2789 | if (DBG) log(logStr); |
| 2790 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2791 | } |
| 2792 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2793 | } |
| 2794 | } |
| 2795 | }; |
| 2796 | UnlockSim.this.notifyAll(); |
| 2797 | } |
| 2798 | Looper.loop(); |
| 2799 | } |
| 2800 | |
| 2801 | /* |
| 2802 | * Use PIN or PUK to unlock SIM card |
| 2803 | * |
| 2804 | * If PUK is null, unlock SIM card with PIN |
| 2805 | * |
| 2806 | * 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] | 2807 | * |
| 2808 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2809 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2810 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2811 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | |
| 2813 | while (mHandler == null) { |
| 2814 | try { |
| 2815 | wait(); |
| 2816 | } catch (InterruptedException e) { |
| 2817 | Thread.currentThread().interrupt(); |
| 2818 | } |
| 2819 | } |
| 2820 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2821 | |
| 2822 | if (puk == null) { |
| 2823 | mSimCard.supplyPin(pin, callback); |
| 2824 | } else { |
| 2825 | mSimCard.supplyPuk(puk, pin, callback); |
| 2826 | } |
| 2827 | |
| 2828 | while (!mDone) { |
| 2829 | try { |
| 2830 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2831 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2832 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | wait(); |
| 2834 | } catch (InterruptedException e) { |
| 2835 | // Restore the interrupted status |
| 2836 | Thread.currentThread().interrupt(); |
| 2837 | } |
| 2838 | } |
| 2839 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2840 | int[] resultArray = new int[2]; |
| 2841 | resultArray[0] = mResult; |
| 2842 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2843 | |
| 2844 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2845 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2846 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2847 | // This instance is no longer reused, so quit its thread's looper. |
| 2848 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2849 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2850 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } |
| 2852 | } |
| 2853 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2854 | /** |
| 2855 | * This method has been removed due to privacy and stability concerns. |
| 2856 | */ |
| 2857 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2859 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2860 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2863 | @Override |
| 2864 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2865 | mApp.getSystemService(AppOpsManager.class) |
| 2866 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2867 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2868 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2869 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2870 | // Callers targeting S have no business invoking this method. |
| 2871 | return; |
| 2872 | } |
| 2873 | |
| 2874 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2875 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2876 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2877 | .setCallingPackage(callingPackage) |
| 2878 | .setCallingFeatureId(null) |
| 2879 | .setCallingPid(Binder.getCallingPid()) |
| 2880 | .setCallingUid(Binder.getCallingUid()) |
| 2881 | .setMethod("updateServiceLocation") |
| 2882 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2883 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2884 | .build()); |
| 2885 | // Apps that lack location permission have no business calling this method; |
| 2886 | // however, because no permission was declared in the public API, denials must |
| 2887 | // all be "soft". |
| 2888 | switch (locationResult) { |
| 2889 | case DENIED_HARD: /* fall through */ |
| 2890 | case DENIED_SOFT: |
| 2891 | return; |
| 2892 | } |
| 2893 | |
| 2894 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | final long identity = Binder.clearCallingIdentity(); |
| 2896 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2897 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2898 | } finally { |
| 2899 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2900 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2903 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2904 | @Override |
| 2905 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2906 | return isRadioOnWithFeature(callingPackage, null); |
| 2907 | } |
| 2908 | |
| 2909 | |
| 2910 | @Override |
| 2911 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2912 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2913 | callingFeatureId); |
| 2914 | } |
| 2915 | |
| 2916 | @Deprecated |
| 2917 | @Override |
| 2918 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2919 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2922 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2923 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2924 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2926 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2927 | return false; |
| 2928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2930 | enforceTelephonyFeatureWithException(callingPackage, |
| 2931 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
| 2935 | return isRadioOnForSubscriber(subId); |
| 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(identity); |
| 2938 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | final long identity = Binder.clearCallingIdentity(); |
| 2943 | try { |
| 2944 | final Phone phone = getPhone(subId); |
| 2945 | if (phone != null) { |
| 2946 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2947 | } else { |
| 2948 | return false; |
| 2949 | } |
| 2950 | } finally { |
| 2951 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2956 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2958 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2959 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2960 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2961 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2962 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2963 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2964 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | final Phone phone = getPhone(subId); |
| 2968 | if (phone != null) { |
| 2969 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2970 | } |
| 2971 | } finally { |
| 2972 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2973 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2977 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2980 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2981 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | final Phone phone = getPhone(subId); |
| 2986 | if (phone == null) { |
| 2987 | return false; |
| 2988 | } |
| 2989 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2990 | toggleRadioOnOffForSubscriber(subId); |
| 2991 | } |
| 2992 | return true; |
| 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2995 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2996 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2997 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2998 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2999 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3000 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 3001 | if (!mApp.getResources().getBoolean( |
| 3002 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3003 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3004 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3005 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3006 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3007 | /* |
| 3008 | * If any of the Radios are available, it will need to be |
| 3009 | * shutdown. So return true if any Radio is available. |
| 3010 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3011 | final long identity = Binder.clearCallingIdentity(); |
| 3012 | try { |
| 3013 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3014 | Phone phone = PhoneFactory.getPhone(i); |
| 3015 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3016 | } |
| 3017 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3018 | return false; |
| 3019 | } finally { |
| 3020 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3021 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3025 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | enforceModifyPermission(); |
| 3027 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3028 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3029 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3030 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
| 3033 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3034 | logv("Shutting down Phone " + i); |
| 3035 | shutdownRadioUsingPhoneId(i); |
| 3036 | } |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3043 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3044 | if (phone != null && phone.isRadioAvailable()) { |
| 3045 | phone.shutdownRadio(); |
| 3046 | } |
| 3047 | } |
| 3048 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3049 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3050 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3052 | if (!turnOn) { |
| 3053 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3054 | } |
| 3055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3059 | if (defaultPhone != null) { |
| 3060 | defaultPhone.setRadioPower(turnOn); |
| 3061 | return true; |
| 3062 | } else { |
| 3063 | loge("There's no default phone."); |
| 3064 | return false; |
| 3065 | } |
| 3066 | } finally { |
| 3067 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3068 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3071 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3072 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3073 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3074 | if (!turnOn) { |
| 3075 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3076 | + ",callingPackage=" + getCurrentPackageName()); |
| 3077 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | final long identity = Binder.clearCallingIdentity(); |
| 3079 | try { |
| 3080 | final Phone phone = getPhone(subId); |
| 3081 | if (phone != null) { |
| 3082 | phone.setRadioPower(turnOn); |
| 3083 | return true; |
| 3084 | } else { |
| 3085 | return false; |
| 3086 | } |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3089 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3092 | /** |
| 3093 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3094 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3095 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3096 | * powering it off, and these radio off votes will be cleared. |
| 3097 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3098 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3099 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3100 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3101 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3102 | * check its vote. |
| 3103 | * |
| 3104 | * @param subId The subscription ID. |
| 3105 | * @param reason The reason for powering off radio. |
| 3106 | * @return true on success and false on failure. |
| 3107 | */ |
| 3108 | public boolean requestRadioPowerOffForReason(int subId, |
| 3109 | @TelephonyManager.RadioPowerReason int reason) { |
| 3110 | enforceModifyPermission(); |
| 3111 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3112 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3113 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3114 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3115 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3116 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3117 | final long identity = Binder.clearCallingIdentity(); |
| 3118 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3119 | boolean result = false; |
| 3120 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3121 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3122 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3123 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3124 | if (!result) { |
| 3125 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3126 | } |
| 3127 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | /** |
| 3134 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3135 | * {@link requestRadioPowerOffForReason}. |
| 3136 | * |
| 3137 | * @param subId The subscription ID. |
| 3138 | * @param reason The reason for powering off radio. |
| 3139 | * @return true on success and false on failure. |
| 3140 | */ |
| 3141 | public boolean clearRadioPowerOffForReason(int subId, |
| 3142 | @TelephonyManager.RadioPowerReason int reason) { |
| 3143 | enforceModifyPermission(); |
| 3144 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3145 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3146 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3147 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3150 | boolean result = false; |
| 3151 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3152 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3153 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3154 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3155 | if (!result) { |
| 3156 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3157 | } |
| 3158 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3159 | } finally { |
| 3160 | Binder.restoreCallingIdentity(identity); |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3166 | * |
| 3167 | * @param subId The subscription ID. |
| 3168 | * @param callingPackage The package making the call. |
| 3169 | * @param callingFeatureId The feature in the package. |
| 3170 | * @return List of reasons for powering off radio. |
| 3171 | */ |
| 3172 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3173 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3174 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3175 | enforceTelephonyFeatureWithException(callingPackage, |
| 3176 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3177 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3178 | final long identity = Binder.clearCallingIdentity(); |
| 3179 | List result = new ArrayList(); |
| 3180 | try { |
| 3181 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3182 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3183 | return result; |
| 3184 | } |
| 3185 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3186 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3187 | if (phone != null) { |
| 3188 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3189 | } else { |
| 3190 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3191 | } |
| 3192 | } finally { |
| 3193 | Binder.restoreCallingIdentity(identity); |
| 3194 | } |
| 3195 | return result; |
| 3196 | } |
| 3197 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3198 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3199 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3200 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3203 | enforceTelephonyFeatureWithException(callingPackage, |
| 3204 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3205 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | final long identity = Binder.clearCallingIdentity(); |
| 3207 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3208 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3210 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3211 | phone.getDataSettingsManager().setDataEnabled( |
| 3212 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | return true; |
| 3214 | } else { |
| 3215 | return false; |
| 3216 | } |
| 3217 | } finally { |
| 3218 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3222 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3223 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3224 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3225 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3227 | enforceTelephonyFeatureWithException(callingPackage, |
| 3228 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3232 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3234 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3235 | phone.getDataSettingsManager().setDataEnabled( |
| 3236 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | return true; |
| 3238 | } else { |
| 3239 | return false; |
| 3240 | } |
| 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3246 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3247 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3248 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3249 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | final long identity = Binder.clearCallingIdentity(); |
| 3252 | try { |
| 3253 | final Phone phone = getPhone(subId); |
| 3254 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3255 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3256 | } else { |
| 3257 | return false; |
| 3258 | } |
| 3259 | } finally { |
| 3260 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3265 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3268 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | enforceCallPermission(); |
| 3270 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3272 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
| 3276 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3277 | return; |
| 3278 | } |
| 3279 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3280 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
| 3283 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3284 | }; |
| 3285 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3286 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3287 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3289 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3290 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3291 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | final long identity = Binder.clearCallingIdentity(); |
| 3293 | try { |
| 3294 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3295 | return false; |
| 3296 | } |
| 3297 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3300 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3303 | /** |
| 3304 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3305 | * tag on getCallState Binder call. |
| 3306 | */ |
| 3307 | @Deprecated |
| 3308 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3309 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3310 | if (CompatChanges.isChangeEnabled( |
| 3311 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3312 | Binder.getCallingUid())) { |
| 3313 | // Do not allow this API to be called on API version 31+, it should only be |
| 3314 | // called on old apps using this Binder call directly. |
| 3315 | throw new SecurityException("This method can only be used for applications " |
| 3316 | + "targeting API version 30 or less."); |
| 3317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3318 | final long identity = Binder.clearCallingIdentity(); |
| 3319 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3320 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3321 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | @Override |
| 3328 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3329 | if (CompatChanges.isChangeEnabled( |
| 3330 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3331 | Binder.getCallingUid())) { |
| 3332 | // Check READ_PHONE_STATE for API version 31+ |
| 3333 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3334 | featureId, "getCallStateForSubscription")) { |
| 3335 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3336 | + "targeting API level 31+."); |
| 3337 | } |
| 3338 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3339 | |
| 3340 | enforceTelephonyFeatureWithException(callingPackage, |
| 3341 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3342 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3346 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3347 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(identity); |
| 3350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3353 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3354 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3355 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | @Override |
| 3359 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3360 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3361 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3365 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3366 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3367 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | } else { |
| 3369 | return PhoneConstantConversions.convertDataState( |
| 3370 | PhoneConstants.DataState.DISCONNECTED); |
| 3371 | } |
| 3372 | } finally { |
| 3373 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3377 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3378 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3379 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3383 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3384 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3385 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3386 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3389 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3390 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3391 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | } else { |
| 3393 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3394 | } |
| 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3397 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3401 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3402 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3403 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3404 | |
| 3405 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3406 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3407 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3408 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3409 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3410 | .setCallingPid(Binder.getCallingPid()) |
| 3411 | .setCallingUid(Binder.getCallingUid()) |
| 3412 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3413 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3414 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3415 | .build()); |
| 3416 | switch (locationResult) { |
| 3417 | case DENIED_HARD: |
| 3418 | throw new SecurityException("Not allowed to access cell location"); |
| 3419 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3420 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3421 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3424 | enforceTelephonyFeatureWithException(callingPackage, |
| 3425 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3426 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3427 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | final long identity = Binder.clearCallingIdentity(); |
| 3429 | try { |
| 3430 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3431 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3432 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3433 | } finally { |
| 3434 | Binder.restoreCallingIdentity(identity); |
| 3435 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3438 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3439 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3440 | if (!mApp.getResources().getBoolean( |
| 3441 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3442 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3443 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3444 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3445 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3446 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3447 | // registered cell info, so return a NULL country instead. |
| 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3450 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3451 | // Get default phone in this case. |
| 3452 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3453 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3454 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3455 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3456 | if (phone == null) return ""; |
| 3457 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3458 | if (sst == null) return ""; |
| 3459 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3460 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3461 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3462 | } finally { |
| 3463 | Binder.restoreCallingIdentity(identity); |
| 3464 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3467 | /** |
| 3468 | * This method was removed due to potential issues caused by performing partial |
| 3469 | * updates of service state, and lack of a credible use case. |
| 3470 | * |
| 3471 | * This has the ability to break the telephony implementation by disabling notification of |
| 3472 | * changes in device connectivity. DO NOT USE THIS! |
| 3473 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3474 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3475 | public void enableLocationUpdates() { |
| 3476 | mApp.enforceCallingOrSelfPermission( |
| 3477 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3480 | /** |
| 3481 | * This method was removed due to potential issues caused by performing partial |
| 3482 | * updates of service state, and lack of a credible use case. |
| 3483 | * |
| 3484 | * This has the ability to break the telephony implementation by disabling notification of |
| 3485 | * changes in device connectivity. DO NOT USE THIS! |
| 3486 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3487 | @Override |
| 3488 | public void disableLocationUpdates() { |
| 3489 | mApp.enforceCallingOrSelfPermission( |
| 3490 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | @Override |
| 3494 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3495 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3496 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3497 | try { |
| 3498 | mApp.getSystemService(AppOpsManager.class) |
| 3499 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3500 | } catch (SecurityException e) { |
| 3501 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3502 | throw e; |
| 3503 | } |
| 3504 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3505 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3506 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3507 | throw new SecurityException( |
| 3508 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3509 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3510 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3511 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3512 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3513 | return null; |
| 3514 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3515 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3516 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3517 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3518 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3519 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3521 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3522 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3523 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3524 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3525 | for (CellInfo ci : info) { |
| 3526 | if (ci instanceof CellInfoGsm) { |
| 3527 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3528 | } else if (ci instanceof CellInfoWcdma) { |
| 3529 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3531 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3532 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3535 | private List<CellInfo> getCachedCellInfo() { |
| 3536 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3537 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3538 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3539 | if (info != null) cellInfos.addAll(info); |
| 3540 | } |
| 3541 | return cellInfos; |
| 3542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3543 | |
| 3544 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3545 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3546 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3547 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3548 | |
| 3549 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3550 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3551 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3552 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3553 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3554 | .setCallingPid(Binder.getCallingPid()) |
| 3555 | .setCallingUid(Binder.getCallingUid()) |
| 3556 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3557 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3558 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3559 | .build()); |
| 3560 | switch (locationResult) { |
| 3561 | case DENIED_HARD: |
| 3562 | throw new SecurityException("Not allowed to access cell info"); |
| 3563 | case DENIED_SOFT: |
| 3564 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3567 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3568 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3569 | return getCachedCellInfo(); |
| 3570 | } |
| 3571 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3572 | enforceTelephonyFeatureWithException(callingPackage, |
| 3573 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3574 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3575 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3576 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3577 | final long identity = Binder.clearCallingIdentity(); |
| 3578 | try { |
| 3579 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3580 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3581 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3582 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3583 | if (info != null) cellInfos.addAll(info); |
| 3584 | } |
| 3585 | return cellInfos; |
| 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3591 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3592 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3593 | String callingFeatureId) { |
| 3594 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3595 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3599 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3600 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3601 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3602 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3605 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3606 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3607 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3608 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3609 | |
| 3610 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3611 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3612 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3613 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3614 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3615 | .setCallingPid(Binder.getCallingPid()) |
| 3616 | .setCallingUid(Binder.getCallingUid()) |
| 3617 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3618 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3619 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3620 | .build()); |
| 3621 | switch (locationResult) { |
| 3622 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3623 | if (TelephonyPermissions |
| 3624 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3625 | // Safetynet logging for b/154934934 |
| 3626 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3627 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3628 | throw new SecurityException("Not allowed to access cell info"); |
| 3629 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3630 | if (TelephonyPermissions |
| 3631 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3632 | // Safetynet logging for b/154934934 |
| 3633 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3634 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3635 | try { |
| 3636 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3637 | } catch (RemoteException re) { |
| 3638 | // Drop without consequences |
| 3639 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3640 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3643 | enforceTelephonyFeatureWithException(callingPackage, |
| 3644 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3645 | |
| 3646 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3647 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3648 | |
| 3649 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3650 | } |
| 3651 | |
| 3652 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3653 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3654 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3655 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | |
| 3657 | final long identity = Binder.clearCallingIdentity(); |
| 3658 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3659 | Phone phone = getPhone(subId); |
| 3660 | if (phone == null) { |
| 3661 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3662 | } else { |
| 3663 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3664 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
| 3667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3670 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3671 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3672 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3673 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3674 | return null; |
| 3675 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3676 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3677 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3678 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3679 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3680 | return null; |
| 3681 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | |
| 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | return phone.getImei(); |
| 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(identity); |
| 3688 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3692 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3693 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3694 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3695 | callingFeatureId, "getPrimaryImei")) { |
| 3696 | throw new SecurityException("Caller does not have permission"); |
| 3697 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3698 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3702 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3703 | return phone.getImei(); |
| 3704 | } |
| 3705 | } |
| 3706 | throw new UnsupportedOperationException("Operation not supported"); |
| 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(identity); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3713 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3714 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3715 | String tac = null; |
| 3716 | if (phone != null) { |
| 3717 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3718 | try { |
| 3719 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3720 | } catch (IndexOutOfBoundsException e) { |
| 3721 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3722 | return null; |
| 3723 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3724 | } |
| 3725 | return tac; |
| 3726 | } |
| 3727 | |
| 3728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3729 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3730 | try { |
| 3731 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3732 | } catch (SecurityException se) { |
| 3733 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3734 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3735 | + Binder.getCallingUid()); |
| 3736 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3737 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3738 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3739 | return null; |
| 3740 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3742 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3743 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3744 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3745 | return null; |
| 3746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3748 | enforceTelephonyFeatureWithException(callingPackage, |
| 3749 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | return phone.getMeid(); |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(identity); |
| 3756 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3760 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3761 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3762 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3763 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3764 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3765 | String manufacturerCode = null; |
| 3766 | if (phone != null) { |
| 3767 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3768 | try { |
| 3769 | manufacturerCode = |
| 3770 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3771 | } catch (IndexOutOfBoundsException e) { |
| 3772 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3773 | return null; |
| 3774 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3775 | } |
| 3776 | return manufacturerCode; |
| 3777 | } |
| 3778 | |
| 3779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3780 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3781 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3783 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3784 | return null; |
| 3785 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3786 | int subId = phone.getSubId(); |
| 3787 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3788 | mApp, subId, callingPackage, callingFeatureId, |
| 3789 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3790 | return null; |
| 3791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3793 | enforceTelephonyFeatureWithException(callingPackage, |
| 3794 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | return phone.getDeviceSvn(); |
| 3799 | } finally { |
| 3800 | Binder.restoreCallingIdentity(identity); |
| 3801 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3804 | @Override |
| 3805 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3806 | if (!mApp.getResources().getBoolean( |
| 3807 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3808 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3809 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3810 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | final Phone phone = getPhone(subId); |
| 3815 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3816 | } finally { |
| 3817 | Binder.restoreCallingIdentity(identity); |
| 3818 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | @Override |
| 3822 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3823 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3824 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3826 | final long identity = Binder.clearCallingIdentity(); |
| 3827 | try { |
| 3828 | final Phone phone = getPhone(subId); |
| 3829 | return phone == null ? null : phone.getCarrierName(); |
| 3830 | } finally { |
| 3831 | Binder.restoreCallingIdentity(identity); |
| 3832 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3833 | } |
| 3834 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3835 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3836 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3837 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3838 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3839 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3840 | final long identity = Binder.clearCallingIdentity(); |
| 3841 | try { |
| 3842 | final Phone phone = getPhone(subId); |
| 3843 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3844 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3851 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3852 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3853 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3854 | "getSubscriptionSpecificCarrierName"); |
| 3855 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3859 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(identity); |
| 3862 | } |
| 3863 | } |
| 3864 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3865 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3866 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3867 | if (!isSubscriptionMccMnc) { |
| 3868 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3869 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3870 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3871 | if (phone == null) { |
| 3872 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3873 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3874 | |
| 3875 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3876 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3877 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3878 | final long identity = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
| 3883 | } |
| 3884 | } |
| 3885 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3886 | // |
| 3887 | // Internal helper methods. |
| 3888 | // |
| 3889 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3890 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3891 | * Make sure the caller is the calling package itself |
| 3892 | * |
| 3893 | * @throws SecurityException if the caller is not the calling package |
| 3894 | */ |
| 3895 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3896 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3897 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3898 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3899 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3900 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3901 | } catch (PackageManager.NameNotFoundException e) { |
| 3902 | // packageUid is -1 |
| 3903 | } |
| 3904 | if (packageUid != callingUid) { |
| 3905 | throw new SecurityException(message + ": Package " + callingPackage |
| 3906 | + " does not belong to " + callingUid); |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3911 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3912 | * |
| 3913 | * @throws SecurityException if the caller does not have the required permission |
| 3914 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3915 | @VisibleForTesting |
| 3916 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3917 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3918 | } |
| 3919 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3920 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3921 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3922 | * |
| 3923 | * @throws SecurityException if the caller does not have the required permission |
| 3924 | */ |
| 3925 | @VisibleForTesting |
| 3926 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3927 | enforceReadPermission(null); |
| 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3932 | * |
| 3933 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3934 | */ |
| 3935 | @VisibleForTesting |
| 3936 | public void enforceReadPermission(String msg) { |
| 3937 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3940 | private void enforceActiveEmergencySessionPermission() { |
| 3941 | mApp.enforceCallingOrSelfPermission( |
| 3942 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3943 | } |
| 3944 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | /** |
| 3946 | * Make sure the caller has the CALL_PHONE permission. |
| 3947 | * |
| 3948 | * @throws SecurityException if the caller does not have the required permission |
| 3949 | */ |
| 3950 | private void enforceCallPermission() { |
| 3951 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3952 | } |
| 3953 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3954 | private void enforceSettingsPermission() { |
| 3955 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3956 | } |
| 3957 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3958 | private void enforceRebootPermission() { |
| 3959 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3960 | } |
| 3961 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3962 | /** |
| 3963 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3964 | * @param message - log message to print. |
| 3965 | * @throws SecurityException if the caller does not have the required permission |
| 3966 | */ |
| 3967 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3968 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3969 | } |
| 3970 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3971 | /** |
| 3972 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3973 | * @param message - log message to print. |
| 3974 | * @throws SecurityException if the caller does not have the required permission |
| 3975 | */ |
| 3976 | private void enforcePackageUsageStatsPermission(String message) { |
| 3977 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3978 | } |
| 3979 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3980 | private String createTelUrl(String number) { |
| 3981 | if (TextUtils.isEmpty(number)) { |
| 3982 | return null; |
| 3983 | } |
| 3984 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3985 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3988 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3989 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3992 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3993 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3996 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3997 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4000 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4001 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4002 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4005 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4006 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4007 | if (!mApp.getResources().getBoolean( |
| 4008 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4009 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4010 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4011 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
| 4015 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4016 | if (phone == null) { |
| 4017 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4018 | } else { |
| 4019 | return phone.getPhoneType(); |
| 4020 | } |
| 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4023 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Returns the CDMA ERI icon index to display |
| 4028 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4029 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4030 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4031 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4032 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4035 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4036 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4037 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4038 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4039 | mApp, subId, callingPackage, callingFeatureId, |
| 4040 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4041 | return -1; |
| 4042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4043 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4044 | enforceTelephonyFeatureWithException(callingPackage, |
| 4045 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4046 | "getCdmaEriIconIndexForSubscriber"); |
| 4047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | final long identity = Binder.clearCallingIdentity(); |
| 4049 | try { |
| 4050 | final Phone phone = getPhone(subId); |
| 4051 | if (phone != null) { |
| 4052 | return phone.getCdmaEriIconIndex(); |
| 4053 | } else { |
| 4054 | return -1; |
| 4055 | } |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4058 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
| 4062 | * Returns the CDMA ERI icon mode, |
| 4063 | * 0 - ON |
| 4064 | * 1 - FLASHING |
| 4065 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4066 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4067 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4068 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4069 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4072 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4073 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4074 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4075 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4076 | mApp, subId, callingPackage, callingFeatureId, |
| 4077 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4078 | return -1; |
| 4079 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | |
| 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | final Phone phone = getPhone(subId); |
| 4084 | if (phone != null) { |
| 4085 | return phone.getCdmaEriIconMode(); |
| 4086 | } else { |
| 4087 | return -1; |
| 4088 | } |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4091 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | /** |
| 4095 | * Returns the CDMA ERI text, |
| 4096 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4097 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4098 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4099 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4100 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4103 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4104 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4105 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4107 | mApp, subId, callingPackage, callingFeatureId, |
| 4108 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4109 | return null; |
| 4110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | |
| 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | final Phone phone = getPhone(subId); |
| 4115 | if (phone != null) { |
| 4116 | return phone.getCdmaEriText(); |
| 4117 | } else { |
| 4118 | return null; |
| 4119 | } |
| 4120 | } finally { |
| 4121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4126 | * Returns the CDMA MDN. |
| 4127 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4128 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4129 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4131 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4133 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4134 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
| 4138 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4139 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | return phone.getLine1Number(); |
| 4141 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4142 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4143 | return null; |
| 4144 | } |
| 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | /** |
| 4151 | * Returns the CDMA MIN. |
| 4152 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4153 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4154 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4156 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4157 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4159 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4160 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | final Phone phone = getPhone(subId); |
| 4164 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4165 | return phone.getCdmaMin(); |
| 4166 | } else { |
| 4167 | return null; |
| 4168 | } |
| 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4174 | @Override |
| 4175 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4176 | INumberVerificationCallback callback, String callingPackage) { |
| 4177 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4178 | != PERMISSION_GRANTED) { |
| 4179 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4180 | } |
| 4181 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4182 | |
| 4183 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4184 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4185 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4186 | + "calling package: " + callingPackage |
| 4187 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4190 | enforceTelephonyFeatureWithException(callingPackage, |
| 4191 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4192 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4193 | if (range == null) { |
| 4194 | throw new NullPointerException("Range must be non-null"); |
| 4195 | } |
| 4196 | |
| 4197 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4198 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4199 | |
| 4200 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4201 | } |
| 4202 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4203 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4204 | * Returns true if CDMA provisioning needs to run. |
| 4205 | */ |
| 4206 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4207 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4208 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4210 | final long identity = Binder.clearCallingIdentity(); |
| 4211 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4212 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
| 4215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4219 | * Sets the voice mail number of a given subId. |
| 4220 | */ |
| 4221 | @Override |
| 4222 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4223 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4224 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4225 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4226 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4227 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 4231 | Boolean success = (Boolean) sendRequest( |
| 4232 | CMD_SET_VOICEMAIL_NUMBER, |
| 4233 | new Pair<String, String>(alphaTag, number), |
| 4234 | new Integer(subId), |
| 4235 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
| 4236 | if (success == null) return false; // most likely due to a timeout |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4237 | return success; |
| 4238 | } finally { |
| 4239 | Binder.restoreCallingIdentity(identity); |
| 4240 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4241 | } |
| 4242 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4243 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4244 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4245 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4246 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4247 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4248 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4249 | throw new SecurityException("caller must be system dialer"); |
| 4250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4252 | enforceTelephonyFeatureWithException(callingPackage, |
| 4253 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | final long identity = Binder.clearCallingIdentity(); |
| 4256 | try { |
| 4257 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4258 | if (phoneAccountHandle == null) { |
| 4259 | return null; |
| 4260 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4261 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4264 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4268 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4269 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4270 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4272 | mApp, subId, callingPackage, callingFeatureId, |
| 4273 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4274 | return null; |
| 4275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4277 | enforceTelephonyFeatureWithException(callingPackage, |
| 4278 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4279 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4280 | final long identity = Binder.clearCallingIdentity(); |
| 4281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4282 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4289 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4290 | VisualVoicemailSmsFilterSettings settings) { |
| 4291 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4292 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4293 | enforceTelephonyFeatureWithException(callingPackage, |
| 4294 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | final long identity = Binder.clearCallingIdentity(); |
| 4296 | try { |
| 4297 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4298 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4305 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4306 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4307 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4308 | enforceTelephonyFeatureWithException(callingPackage, |
| 4309 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
| 4313 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4314 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
| 4317 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4321 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4322 | String callingPackage, int subId) { |
| 4323 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4324 | |
| 4325 | final long identity = Binder.clearCallingIdentity(); |
| 4326 | try { |
| 4327 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4328 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
| 4331 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4335 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4336 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4337 | |
| 4338 | final long identity = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4341 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4342 | } finally { |
| 4343 | Binder.restoreCallingIdentity(identity); |
| 4344 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4348 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4349 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4350 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4351 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4352 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4353 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4354 | |
| 4355 | enforceTelephonyFeatureWithException(callingPackage, |
| 4356 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4357 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4358 | SmsController smsController = PhoneFactory.getSmsController(); |
Nikhil Kumar | deebd75 | 2024-08-14 14:49:06 +0100 | [diff] [blame] | 4359 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, |
| 4360 | Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number, |
| 4361 | port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4362 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4363 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4364 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4365 | * Sets the voice activation state of a given subId. |
| 4366 | */ |
| 4367 | @Override |
| 4368 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4370 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4371 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4372 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4373 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4374 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | final Phone phone = getPhone(subId); |
| 4378 | if (phone != null) { |
| 4379 | phone.setVoiceActivationState(activationState); |
| 4380 | } else { |
| 4381 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4382 | } |
| 4383 | } finally { |
| 4384 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | /** |
| 4389 | * Sets the data activation state of a given subId. |
| 4390 | */ |
| 4391 | @Override |
| 4392 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4394 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4395 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4396 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4397 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4398 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | final long identity = Binder.clearCallingIdentity(); |
| 4400 | try { |
| 4401 | final Phone phone = getPhone(subId); |
| 4402 | if (phone != null) { |
| 4403 | phone.setDataActivationState(activationState); |
| 4404 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4405 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | } |
| 4407 | } finally { |
| 4408 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | /** |
| 4413 | * Returns the voice activation state of a given subId. |
| 4414 | */ |
| 4415 | @Override |
| 4416 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4417 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4418 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4419 | enforceTelephonyFeatureWithException(callingPackage, |
| 4420 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4421 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4422 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | final long identity = Binder.clearCallingIdentity(); |
| 4424 | try { |
| 4425 | if (phone != null) { |
| 4426 | return phone.getVoiceActivationState(); |
| 4427 | } else { |
| 4428 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4429 | } |
| 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4432 | } |
| 4433 | } |
| 4434 | |
| 4435 | /** |
| 4436 | * Returns the data activation state of a given subId. |
| 4437 | */ |
| 4438 | @Override |
| 4439 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4442 | enforceTelephonyFeatureWithException(callingPackage, |
| 4443 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4444 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4445 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | final long identity = Binder.clearCallingIdentity(); |
| 4447 | try { |
| 4448 | if (phone != null) { |
| 4449 | return phone.getDataActivationState(); |
| 4450 | } else { |
| 4451 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4452 | } |
| 4453 | } finally { |
| 4454 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4455 | } |
| 4456 | } |
| 4457 | |
| 4458 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4459 | * Returns the unread count of voicemails for a subId |
| 4460 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4461 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4462 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4463 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4464 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4465 | mApp, subId, callingPackage, callingFeatureId, |
| 4466 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4467 | return 0; |
| 4468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | final long identity = Binder.clearCallingIdentity(); |
| 4470 | try { |
| 4471 | final Phone phone = getPhone(subId); |
| 4472 | if (phone != null) { |
| 4473 | return phone.getVoiceMessageCount(); |
| 4474 | } else { |
| 4475 | return 0; |
| 4476 | } |
| 4477 | } finally { |
| 4478 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4483 | * returns true, if the device is in a state where both voice and data |
| 4484 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4485 | */ |
| 4486 | @Override |
| 4487 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4488 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4489 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4490 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | final long identity = Binder.clearCallingIdentity(); |
| 4492 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4493 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4494 | } finally { |
| 4495 | Binder.restoreCallingIdentity(identity); |
| 4496 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4500 | * Send the dialer code if called from the current default dialer or the caller has |
| 4501 | * carrier privilege. |
| 4502 | * @param inputCode The dialer code to send |
| 4503 | */ |
| 4504 | @Override |
| 4505 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4506 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4507 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4508 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4509 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4510 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4511 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4512 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4513 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4515 | enforceTelephonyFeatureWithException(callingPackage, |
| 4516 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | final long identity = Binder.clearCallingIdentity(); |
| 4519 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4520 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(identity); |
| 4523 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4526 | @Override |
| 4527 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4528 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4529 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4530 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4531 | |
| 4532 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4533 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4534 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4535 | final long identity = Binder.clearCallingIdentity(); |
| 4536 | try { |
| 4537 | if (!isActiveSubscription(subId)) { |
| 4538 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4539 | } |
| 4540 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4541 | } finally { |
| 4542 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4543 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4544 | } |
| 4545 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4547 | public boolean isInEmergencySmsMode() { |
| 4548 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4549 | |
| 4550 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4551 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4552 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
| 4555 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4556 | if (phone.isInEmergencySmsMode()) { |
| 4557 | return true; |
| 4558 | } |
| 4559 | } |
| 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(identity); |
| 4562 | } |
| 4563 | return false; |
| 4564 | } |
| 4565 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4566 | /** |
| 4567 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4568 | * @param subId The subscription to use to check the configuration. |
| 4569 | * @param c The callback that will be used to send the result. |
| 4570 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4571 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4572 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4573 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4575 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4576 | |
| 4577 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4578 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4579 | "IMS not available on device."); |
| 4580 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4581 | final long token = Binder.clearCallingIdentity(); |
| 4582 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4583 | int slotId = getSlotIndexOrException(subId); |
| 4584 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4585 | |
| 4586 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4587 | if (controller != null) { |
| 4588 | ImsManager imsManager = controller.getImsManager(subId); |
| 4589 | if (imsManager != null) { |
| 4590 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4591 | } else { |
| 4592 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4593 | } |
| 4594 | } else { |
| 4595 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4596 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4597 | } catch (ImsException e) { |
| 4598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(token); |
| 4601 | } |
| 4602 | } |
| 4603 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4604 | /** |
| 4605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4606 | * @param subId The subscription to use to check the configuration. |
| 4607 | * @param c The callback that will be used to send the result. |
| 4608 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4609 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4610 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4611 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4612 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4613 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4614 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4615 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4616 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4617 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4618 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4619 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4620 | if (controller != null) { |
| 4621 | ImsManager imsManager = controller.getImsManager(subId); |
| 4622 | if (imsManager != null) { |
| 4623 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4624 | } else { |
| 4625 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4626 | + "is inactive, ignoring unregister."); |
| 4627 | // If the ImsManager is not valid, just return, since the callback |
| 4628 | // will already have been removed internally. |
| 4629 | } |
| 4630 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(token); |
| 4633 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4636 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4637 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4638 | * @param subId The subscription to use to check the configuration. |
| 4639 | * @param c The callback that will be used to send the result. |
| 4640 | */ |
| 4641 | @Override |
| 4642 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4643 | throws RemoteException { |
| 4644 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4645 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4646 | |
| 4647 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4648 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4649 | "IMS not available on device."); |
| 4650 | } |
| 4651 | final long token = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | int slotId = getSlotIndexOrException(subId); |
| 4654 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4655 | |
| 4656 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4657 | if (controller != null) { |
| 4658 | ImsManager imsManager = controller.getImsManager(subId); |
| 4659 | if (imsManager != null) { |
| 4660 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4661 | } else { |
| 4662 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4663 | } |
| 4664 | } else { |
| 4665 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4666 | } |
| 4667 | } catch (ImsException e) { |
| 4668 | throw new ServiceSpecificException(e.getCode()); |
| 4669 | } finally { |
| 4670 | Binder.restoreCallingIdentity(token); |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | /** |
| 4675 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4676 | * @param subId The subscription to use to check the configuration. |
| 4677 | * @param c The callback that will be used to send the result. |
| 4678 | */ |
| 4679 | @Override |
| 4680 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4681 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4682 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4684 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4685 | } |
| 4686 | final long token = Binder.clearCallingIdentity(); |
| 4687 | |
| 4688 | try { |
| 4689 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4690 | if (controller != null) { |
| 4691 | ImsManager imsManager = controller.getImsManager(subId); |
| 4692 | if (imsManager != null) { |
| 4693 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4694 | } else { |
| 4695 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4696 | + "is inactive, ignoring unregister."); |
| 4697 | // If the ImsManager is not valid, just return, since the callback |
| 4698 | // will already have been removed internally. |
| 4699 | } |
| 4700 | } |
| 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(token); |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4707 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4708 | */ |
| 4709 | @Override |
| 4710 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4711 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4712 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4713 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4714 | "IMS not available on device."); |
| 4715 | } |
| 4716 | final long token = Binder.clearCallingIdentity(); |
| 4717 | try { |
| 4718 | Phone phone = getPhone(subId); |
| 4719 | if (phone == null) { |
| 4720 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4721 | + subId + "'"); |
| 4722 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4723 | } |
| 4724 | phone.getImsRegistrationState(regState -> { |
| 4725 | try { |
| 4726 | consumer.accept((regState == null) |
| 4727 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4728 | } catch (RemoteException e) { |
| 4729 | // Ignore if the remote process is no longer available to call back. |
| 4730 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4731 | } |
| 4732 | }); |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(token); |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | /** |
| 4739 | * Get the transport type for the IMS service registration state. |
| 4740 | */ |
| 4741 | @Override |
| 4742 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4743 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4744 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4745 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4746 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4747 | "IMS not available on device."); |
| 4748 | } |
| 4749 | final long token = Binder.clearCallingIdentity(); |
| 4750 | try { |
| 4751 | Phone phone = getPhone(subId); |
| 4752 | if (phone == null) { |
| 4753 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4754 | + subId + "'"); |
| 4755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4756 | } |
| 4757 | phone.getImsRegistrationTech(regTech -> { |
| 4758 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4759 | int regTechConverted = (regTech == null) |
| 4760 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4761 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4762 | regTechConverted); |
| 4763 | try { |
| 4764 | consumer.accept(regTechConverted); |
| 4765 | } catch (RemoteException e) { |
| 4766 | // Ignore if the remote process is no longer available to call back. |
| 4767 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4768 | } |
| 4769 | }); |
| 4770 | } finally { |
| 4771 | Binder.restoreCallingIdentity(token); |
| 4772 | } |
| 4773 | } |
| 4774 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4775 | /** |
| 4776 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4777 | * @param subId The subscription to use to check the configuration. |
| 4778 | * @param c The callback that will be used to send the result. |
| 4779 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4780 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4781 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4782 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4783 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4784 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4785 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4786 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4787 | "IMS not available on device."); |
| 4788 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4789 | final long token = Binder.clearCallingIdentity(); |
| 4790 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4791 | int slotId = getSlotIndexOrException(subId); |
| 4792 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4793 | |
| 4794 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4795 | if (controller != null) { |
| 4796 | ImsManager imsManager = controller.getImsManager(subId); |
| 4797 | if (imsManager != null) { |
| 4798 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4799 | } else { |
| 4800 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4801 | } |
| 4802 | } else { |
| 4803 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4804 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4805 | } catch (ImsException e) { |
| 4806 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4807 | } finally { |
| 4808 | Binder.restoreCallingIdentity(token); |
| 4809 | } |
| 4810 | } |
| 4811 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4812 | /** |
| 4813 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4814 | * @param subId The subscription to use to check the configuration. |
| 4815 | * @param c The callback that will be used to send the result. |
| 4816 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4817 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4818 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4819 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4820 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4821 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4822 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4823 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4824 | |
| 4825 | final long token = Binder.clearCallingIdentity(); |
| 4826 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4827 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4828 | if (controller != null) { |
| 4829 | ImsManager imsManager = controller.getImsManager(subId); |
| 4830 | if (imsManager != null) { |
| 4831 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4832 | } else { |
| 4833 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4834 | + " is inactive, ignoring unregister."); |
| 4835 | // If the ImsManager is not valid, just return, since the callback |
| 4836 | // will already have been removed internally. |
| 4837 | } |
| 4838 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(token); |
| 4841 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4845 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4846 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4847 | |
| 4848 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4849 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4850 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4851 | final long token = Binder.clearCallingIdentity(); |
| 4852 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4853 | int slotId = getSlotIndexOrException(subId); |
| 4854 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4855 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4856 | } catch (com.android.ims.ImsException e) { |
| 4857 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4858 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4859 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4860 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4861 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(token); |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4868 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4869 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4870 | |
| 4871 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4872 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4873 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4874 | final long token = Binder.clearCallingIdentity(); |
| 4875 | try { |
| 4876 | Phone phone = getPhone(subId); |
| 4877 | if (phone == null) return false; |
| 4878 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4879 | } catch (com.android.ims.ImsException e) { |
| 4880 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4881 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4882 | } finally { |
| 4883 | Binder.restoreCallingIdentity(token); |
| 4884 | } |
| 4885 | } |
| 4886 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4887 | /** |
| 4888 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4889 | * subscription. |
| 4890 | * @param subId The subscription to use to check the configuration. |
| 4891 | * @param callback The callback that will be used to send the result. |
| 4892 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4893 | * @param transportType The transport type of the MmTelFeature capability. |
| 4894 | */ |
| 4895 | @Override |
| 4896 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4897 | int transportType) { |
| 4898 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4899 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4900 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4901 | "IMS not available on device."); |
| 4902 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4903 | final long token = Binder.clearCallingIdentity(); |
| 4904 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4905 | int slotId = getSlotIndex(subId); |
| 4906 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4907 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4908 | + subId + "'"); |
| 4909 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4910 | } |
| 4911 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4912 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4913 | transportType, aBoolean -> { |
| 4914 | try { |
| 4915 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4916 | } catch (RemoteException e) { |
| 4917 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4918 | + "running. Ignore"); |
| 4919 | } |
| 4920 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4921 | } catch (ImsException e) { |
| 4922 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4923 | } finally { |
| 4924 | Binder.restoreCallingIdentity(token); |
| 4925 | } |
| 4926 | } |
| 4927 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4928 | /** |
| 4929 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4930 | * @param subId The subscription to use to check the configuration. |
| 4931 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4932 | @Override |
| 4933 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4934 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4935 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4936 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4937 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4938 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4939 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4940 | final long token = Binder.clearCallingIdentity(); |
| 4941 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4942 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4943 | // 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] | 4944 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4945 | } catch (ImsException e) { |
| 4946 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(token); |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4953 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4954 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4955 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4956 | |
| 4957 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4958 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4959 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4960 | final long identity = Binder.clearCallingIdentity(); |
| 4961 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4962 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4963 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4964 | // 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] | 4965 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4966 | } catch (ImsException e) { |
| 4967 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4968 | } finally { |
| 4969 | Binder.restoreCallingIdentity(identity); |
| 4970 | } |
| 4971 | } |
| 4972 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4973 | /** |
| 4974 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4975 | * @param subId The subscription to use to check the configuration. |
| 4976 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4977 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4978 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4979 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4980 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4981 | |
| 4982 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4983 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4984 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4987 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4988 | // 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] | 4989 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4990 | } catch (ImsException e) { |
| 4991 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4998 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5000 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5001 | |
| 5002 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5003 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5004 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5005 | final long identity = Binder.clearCallingIdentity(); |
| 5006 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5007 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5008 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5009 | // 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] | 5010 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5011 | } catch (ImsException e) { |
| 5012 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
| 5016 | } |
| 5017 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5018 | /** |
| 5019 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5020 | * @param subId The subscription to use to check the configuration. |
| 5021 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5022 | @Override |
| 5023 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5024 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5025 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5026 | |
| 5027 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5028 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5029 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5030 | final long identity = Binder.clearCallingIdentity(); |
| 5031 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5032 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5033 | // 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] | 5034 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5035 | } catch (ImsException e) { |
| 5036 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5037 | } finally { |
| 5038 | Binder.restoreCallingIdentity(identity); |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5043 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5045 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5046 | |
| 5047 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5048 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5049 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5050 | final long identity = Binder.clearCallingIdentity(); |
| 5051 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5052 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5053 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5054 | // 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] | 5055 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5056 | } catch (ImsException e) { |
| 5057 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5058 | } finally { |
| 5059 | Binder.restoreCallingIdentity(identity); |
| 5060 | } |
| 5061 | } |
| 5062 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5063 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5064 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5065 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5066 | * @param subId The subscription to use to check the configuration. |
| 5067 | */ |
| 5068 | @Override |
| 5069 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5070 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5071 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5072 | |
| 5073 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5074 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5075 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5076 | final long identity = Binder.clearCallingIdentity(); |
| 5077 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5078 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5079 | // 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] | 5080 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5081 | } catch (ImsException e) { |
| 5082 | throw new ServiceSpecificException(e.getCode()); |
| 5083 | } finally { |
| 5084 | Binder.restoreCallingIdentity(identity); |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | /** |
| 5089 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5090 | * Requires MODIFY_PHONE_STATE permission. |
| 5091 | * @param subId The subscription to use to check the configuration. |
| 5092 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5093 | * false otherwise |
| 5094 | */ |
| 5095 | @Override |
| 5096 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5098 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5099 | |
| 5100 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5101 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5102 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5103 | final long identity = Binder.clearCallingIdentity(); |
| 5104 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5105 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5106 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5107 | // 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] | 5108 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5109 | } catch (ImsException e) { |
| 5110 | throw new ServiceSpecificException(e.getCode()); |
| 5111 | } finally { |
| 5112 | Binder.restoreCallingIdentity(identity); |
| 5113 | } |
| 5114 | } |
| 5115 | |
| 5116 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5117 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5118 | * @param subId The subscription to use to check the configuration. |
| 5119 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5120 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5121 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5122 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5123 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5124 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5125 | |
| 5126 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5127 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5128 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5131 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5132 | // 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] | 5133 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5134 | } catch (ImsException e) { |
| 5135 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5136 | } finally { |
| 5137 | Binder.restoreCallingIdentity(identity); |
| 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5142 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5144 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5145 | |
| 5146 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5147 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5148 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5149 | final long identity = Binder.clearCallingIdentity(); |
| 5150 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5151 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5152 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5153 | // 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] | 5154 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5155 | } catch (ImsException e) { |
| 5156 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | @Override |
| 5163 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5165 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5166 | |
| 5167 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5168 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5169 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5170 | final long identity = Binder.clearCallingIdentity(); |
| 5171 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5172 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5173 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5174 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5175 | } catch (ImsException e) { |
| 5176 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5177 | } finally { |
| 5178 | Binder.restoreCallingIdentity(identity); |
| 5179 | } |
| 5180 | } |
| 5181 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5182 | /** |
| 5183 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5184 | * @param subId The subscription to use to check the configuration. |
| 5185 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5186 | @Override |
| 5187 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5188 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5189 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5190 | |
| 5191 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5192 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5193 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5194 | final long identity = Binder.clearCallingIdentity(); |
| 5195 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5196 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5197 | // 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] | 5198 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5199 | } catch (ImsException e) { |
| 5200 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5201 | } finally { |
| 5202 | Binder.restoreCallingIdentity(identity); |
| 5203 | } |
| 5204 | } |
| 5205 | |
| 5206 | @Override |
| 5207 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5209 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5210 | |
| 5211 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5212 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5213 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5214 | final long identity = Binder.clearCallingIdentity(); |
| 5215 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5216 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5217 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5218 | // 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] | 5219 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5220 | } catch (ImsException e) { |
| 5221 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | @Override |
| 5228 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5229 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5230 | |
| 5231 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5232 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5233 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5234 | final long identity = Binder.clearCallingIdentity(); |
| 5235 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5236 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5237 | // 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] | 5238 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5239 | } catch (ImsException e) { |
| 5240 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5241 | } finally { |
| 5242 | Binder.restoreCallingIdentity(identity); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | @Override |
| 5247 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5249 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5250 | |
| 5251 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5252 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5253 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5254 | final long identity = Binder.clearCallingIdentity(); |
| 5255 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5256 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5257 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5258 | // 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] | 5259 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5260 | } catch (ImsException e) { |
| 5261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5262 | } finally { |
| 5263 | Binder.restoreCallingIdentity(identity); |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | @Override |
| 5268 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5270 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5271 | |
| 5272 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5273 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5274 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5275 | final long identity = Binder.clearCallingIdentity(); |
| 5276 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5277 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5278 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5279 | // 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] | 5280 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5281 | } catch (ImsException e) { |
| 5282 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
| 5286 | } |
| 5287 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5288 | /** |
| 5289 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5290 | * @param subId The subscription to use to check the configuration. |
| 5291 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5292 | @Override |
| 5293 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5294 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5295 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5296 | |
| 5297 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5298 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5299 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5300 | final long identity = Binder.clearCallingIdentity(); |
| 5301 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5302 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5303 | // 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] | 5304 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5305 | } catch (ImsException e) { |
| 5306 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
| 5310 | } |
| 5311 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5312 | @Override |
| 5313 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5314 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5315 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5316 | final long identity = Binder.clearCallingIdentity(); |
| 5317 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5318 | if (!isImsAvailableOnDevice()) { |
| 5319 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5320 | "IMS not available on device."); |
| 5321 | } |
| 5322 | int slotId = getSlotIndexOrException(subId); |
| 5323 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5324 | |
| 5325 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5326 | if (controller != null) { |
| 5327 | ImsManager imsManager = controller.getImsManager(subId); |
| 5328 | if (imsManager != null) { |
| 5329 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5330 | } else { |
| 5331 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5332 | } |
| 5333 | } else { |
| 5334 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5335 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5336 | } catch (ImsException e) { |
| 5337 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5338 | } finally { |
| 5339 | Binder.restoreCallingIdentity(identity); |
| 5340 | } |
| 5341 | } |
| 5342 | |
| 5343 | @Override |
| 5344 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5345 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5346 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5347 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5348 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5349 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5350 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5351 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5352 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5353 | if (controller != null) { |
| 5354 | ImsManager imsManager = controller.getImsManager(subId); |
| 5355 | if (imsManager != null) { |
| 5356 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5357 | } else { |
| 5358 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5359 | + " is inactive, ignoring unregister."); |
| 5360 | // If the ImsManager is not valid, just return, since the callback will already |
| 5361 | // have been removed internally. |
| 5362 | } |
| 5363 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5364 | } finally { |
| 5365 | Binder.restoreCallingIdentity(identity); |
| 5366 | } |
| 5367 | } |
| 5368 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5369 | @Override |
| 5370 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5371 | IFeatureProvisioningCallback callback) { |
| 5372 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5373 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5374 | |
| 5375 | final long identity = Binder.clearCallingIdentity(); |
| 5376 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5377 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5378 | } |
| 5379 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5380 | try { |
| 5381 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5382 | if (controller == null) { |
| 5383 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5384 | "Device does not support IMS"); |
| 5385 | } |
| 5386 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5387 | } finally { |
| 5388 | Binder.restoreCallingIdentity(identity); |
| 5389 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | @Override |
| 5393 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5394 | IFeatureProvisioningCallback callback) { |
| 5395 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5396 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5397 | |
| 5398 | final long identity = Binder.clearCallingIdentity(); |
| 5399 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5400 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5401 | } |
| 5402 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5403 | try { |
| 5404 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5405 | if (controller == null) { |
| 5406 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5407 | return; |
| 5408 | } |
| 5409 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5410 | } finally { |
| 5411 | Binder.restoreCallingIdentity(identity); |
| 5412 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5413 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5414 | |
| 5415 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5417 | message); |
| 5418 | } |
| 5419 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5420 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5421 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5422 | boolean isProvisioned) { |
| 5423 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5424 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5425 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5426 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5427 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5428 | final long identity = Binder.clearCallingIdentity(); |
| 5429 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5430 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5431 | if (controller == null) { |
| 5432 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5433 | return; |
| 5434 | } |
| 5435 | controller.setRcsProvisioningStatusForCapability( |
| 5436 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5437 | } finally { |
| 5438 | Binder.restoreCallingIdentity(identity); |
| 5439 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | |
| 5443 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5444 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5445 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5446 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5447 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5448 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5449 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5450 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5451 | final long identity = Binder.clearCallingIdentity(); |
| 5452 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5453 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5454 | if (controller == null) { |
| 5455 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5456 | |
| 5457 | // device does not support IMS, this method will return true always. |
| 5458 | return true; |
| 5459 | } |
| 5460 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
| 5463 | } |
| 5464 | } |
| 5465 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5466 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5467 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5468 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5469 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5470 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5471 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5472 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5473 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5474 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5477 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5478 | if (controller == null) { |
| 5479 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5480 | return; |
| 5481 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5482 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5483 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5484 | } finally { |
| 5485 | Binder.restoreCallingIdentity(identity); |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | @Override |
| 5490 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5491 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5492 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5493 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5494 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5495 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5496 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5497 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5500 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5501 | if (controller == null) { |
| 5502 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5503 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5504 | // device does not support IMS, this method will return true always. |
| 5505 | return true; |
| 5506 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5507 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5508 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
| 5511 | } |
| 5512 | } |
| 5513 | |
| 5514 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5515 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5516 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5517 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5518 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5519 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5520 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5521 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5524 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5525 | if (controller == null) { |
| 5526 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5527 | |
| 5528 | // device does not support IMS, this method will return false |
| 5529 | return false; |
| 5530 | } |
| 5531 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5532 | } finally { |
| 5533 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5534 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5538 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5539 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5540 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5541 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5542 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5543 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5544 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5545 | final long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5547 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5548 | if (controller == null) { |
| 5549 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5550 | |
| 5551 | // device does not support IMS, this method will return false |
| 5552 | return false; |
| 5553 | } |
| 5554 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5555 | } finally { |
| 5556 | Binder.restoreCallingIdentity(identity); |
| 5557 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5558 | } |
| 5559 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5560 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5561 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5562 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5563 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5564 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5565 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5566 | mApp, subId, "getImsProvisioningInt"); |
| 5567 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5568 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5569 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5570 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5571 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5572 | final long identity = Binder.clearCallingIdentity(); |
| 5573 | try { |
| 5574 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5575 | int slotId = getSlotIndex(subId); |
| 5576 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5577 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5578 | + subId + "' for key:" + key); |
| 5579 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5580 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5581 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5582 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5583 | if (controller == null) { |
| 5584 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5585 | |
| 5586 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5587 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5588 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5589 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5590 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5591 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5592 | return retVal; |
| 5593 | } |
| 5594 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5595 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5596 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5597 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5598 | + subId + "' for key:" + key); |
| 5599 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5600 | } finally { |
| 5601 | Binder.restoreCallingIdentity(identity); |
| 5602 | } |
| 5603 | } |
| 5604 | |
| 5605 | @Override |
| 5606 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5607 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5608 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5609 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5610 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5611 | mApp, subId, "getImsProvisioningString"); |
| 5612 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5613 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5614 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5615 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
| 5618 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5619 | int slotId = getSlotIndex(subId); |
| 5620 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5621 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5622 | + subId + "' for key:" + key); |
| 5623 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5624 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5625 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5626 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5627 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5628 | + subId + "' for key:" + key); |
| 5629 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | @Override |
| 5636 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5637 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5638 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5639 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5641 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5642 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5643 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5644 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5645 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5646 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5647 | final long identity = Binder.clearCallingIdentity(); |
| 5648 | try { |
| 5649 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5650 | int slotId = getSlotIndex(subId); |
| 5651 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5652 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5653 | + subId + "' for key:" + key); |
| 5654 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5655 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5656 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5657 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5658 | if (controller == null) { |
| 5659 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5660 | |
| 5661 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5662 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5663 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5664 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5665 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5666 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5667 | return retVal; |
| 5668 | } |
| 5669 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5670 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5671 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5672 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5673 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5674 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5675 | } finally { |
| 5676 | Binder.restoreCallingIdentity(identity); |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | @Override |
| 5681 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5682 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5683 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5684 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5686 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5687 | |
| 5688 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5689 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5690 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5691 | final long identity = Binder.clearCallingIdentity(); |
| 5692 | try { |
| 5693 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5694 | int slotId = getSlotIndex(subId); |
| 5695 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5696 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5697 | + subId + "' for key:" + key); |
| 5698 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5699 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5700 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5701 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5702 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5703 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5704 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
| 5708 | } |
| 5709 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5710 | /** |
| 5711 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5712 | * for the given slot ID or no ImsResolver instance has been created. |
| 5713 | * @param slotId The slot ID that the IMS service is created for. |
| 5714 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5715 | */ |
| 5716 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5717 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5718 | ImsFeature.FEATURE_MMTEL)) { |
| 5719 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5720 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5721 | } |
| 5722 | } |
| 5723 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5724 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5725 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5726 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5727 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5728 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5729 | } |
| 5730 | return slotId; |
| 5731 | } |
| 5732 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5733 | private int getSlotIndex(int subId) { |
| 5734 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5735 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5736 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5737 | } |
| 5738 | return slotId; |
| 5739 | } |
| 5740 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5741 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5742 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5743 | */ |
| 5744 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5745 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5746 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5747 | try { |
| 5748 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5749 | } catch (SecurityException se) { |
| 5750 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5751 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5752 | + Binder.getCallingUid()); |
| 5753 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5754 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5755 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5756 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5757 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5758 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5759 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5760 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5761 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5762 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5763 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5764 | enforceTelephonyFeatureWithException(callingPackage, |
| 5765 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
| 5769 | final Phone phone = getPhone(subId); |
| 5770 | if (phone != null) { |
| 5771 | return phone.getServiceState().getDataNetworkType(); |
| 5772 | } else { |
| 5773 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5774 | } |
| 5775 | } finally { |
| 5776 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | /** |
| 5781 | * Returns the data network type |
| 5782 | */ |
| 5783 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5784 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5785 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5786 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | /** |
| 5790 | * Returns the data network type for a subId |
| 5791 | */ |
| 5792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5793 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5794 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5795 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5796 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5797 | mApp, functionName)) { |
| 5798 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5799 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5800 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5801 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5804 | enforceTelephonyFeatureWithException(callingPackage, |
| 5805 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5806 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | final long identity = Binder.clearCallingIdentity(); |
| 5808 | try { |
| 5809 | final Phone phone = getPhone(subId); |
| 5810 | if (phone != null) { |
| 5811 | return phone.getServiceState().getDataNetworkType(); |
| 5812 | } else { |
| 5813 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5814 | } |
| 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5818 | } |
| 5819 | |
| 5820 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5821 | * Returns the Voice network type for a subId |
| 5822 | */ |
| 5823 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5824 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5825 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5826 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5827 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5828 | mApp, functionName)) { |
| 5829 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5830 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5831 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5832 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5835 | enforceTelephonyFeatureWithException(callingPackage, |
| 5836 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5837 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
| 5840 | final Phone phone = getPhone(subId); |
| 5841 | if (phone != null) { |
| 5842 | return phone.getServiceState().getVoiceNetworkType(); |
| 5843 | } else { |
| 5844 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5845 | } |
| 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5848 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /** |
| 5852 | * @return true if a ICC card is present |
| 5853 | */ |
| 5854 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5855 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5856 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5857 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5861 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5862 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5863 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5864 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5865 | if (!mApp.getResources().getBoolean( |
| 5866 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5867 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5868 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5869 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5871 | final long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
| 5873 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5874 | if (phone != null) { |
| 5875 | return phone.getIccCard().hasIccCard(); |
| 5876 | } else { |
| 5877 | return false; |
| 5878 | } |
| 5879 | } finally { |
| 5880 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5881 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | /** |
| 5885 | * Return if the current radio is LTE on CDMA. This |
| 5886 | * is a tri-state return value as for a period of time |
| 5887 | * the mode may be unknown. |
| 5888 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5889 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5890 | * @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] | 5891 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5892 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5893 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5894 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5895 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5896 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5897 | } |
| 5898 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5899 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5900 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5901 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5902 | try { |
| 5903 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5904 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5905 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5906 | } |
| 5907 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5908 | enforceTelephonyFeatureWithException(callingPackage, |
| 5909 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5911 | final long identity = Binder.clearCallingIdentity(); |
| 5912 | try { |
| 5913 | final Phone phone = getPhone(subId); |
| 5914 | if (phone == null) { |
| 5915 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5916 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5917 | return TelephonyProperties.lte_on_cdma_device() |
| 5918 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | } |
| 5920 | } finally { |
| 5921 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5922 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5925 | /** |
| 5926 | * {@hide} |
| 5927 | * Returns Default subId, 0 in the case of single standby. |
| 5928 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5929 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5930 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5931 | } |
| 5932 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5933 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5934 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5937 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5938 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5939 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5940 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5941 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5942 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5943 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5944 | } |
| 5945 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5946 | /** |
| 5947 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5948 | */ |
| 5949 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | final long identity = Binder.clearCallingIdentity(); |
| 5951 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5952 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5954 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | /** |
| 5961 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5962 | */ |
| 5963 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5964 | final long identity = Binder.clearCallingIdentity(); |
| 5965 | try { |
| 5966 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5967 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5969 | } finally { |
| 5970 | Binder.restoreCallingIdentity(identity); |
| 5971 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5972 | } |
| 5973 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5974 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5975 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5976 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5977 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5978 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5979 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5980 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5981 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5982 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5983 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5984 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5985 | } |
| 5986 | return PhoneFactory.getPhone(phoneId); |
| 5987 | } |
| 5988 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5989 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5990 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5991 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5992 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5994 | /*message=*/ "iccOpenLogicalChannel"); |
| 5995 | |
| 5996 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5997 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5998 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5999 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6000 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6001 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 6002 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6003 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6004 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6005 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6006 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6007 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6008 | Phone phone; |
| 6009 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6011 | mApp, request.subId, message); |
| 6012 | phone = getPhoneFromSubId(request.subId); |
| 6013 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6014 | enforceModifyPermission(); |
| 6015 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6016 | } else { |
| 6017 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6018 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6019 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6023 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6024 | final long identity = Binder.clearCallingIdentity(); |
| 6025 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6026 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6028 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6029 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6030 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6031 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6032 | loge("The calling package is not allowed to access ISD-R."); |
| 6033 | throw new SecurityException( |
| 6034 | "The calling package is not allowed to access ISD-R."); |
| 6035 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6036 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6037 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6039 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6040 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | return response; |
| 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
| 6044 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6048 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6049 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6050 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6051 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6052 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6053 | /*message=*/"iccCloseLogicalChannel"); |
| 6054 | |
| 6055 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6056 | |
| 6057 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6058 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6059 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6060 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6061 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6062 | // before this feature is enabled, this API should only return false if |
| 6063 | // the operation fails instead of throwing runtime exception for |
| 6064 | // backward-compatibility. |
| 6065 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6066 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | final long identity = Binder.clearCallingIdentity(); |
| 6068 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6069 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6070 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6071 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6072 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6073 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6074 | Boolean success = false; |
| 6075 | if (result instanceof RuntimeException) { |
| 6076 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6077 | if (shouldThrowExceptionOnFailure) { |
| 6078 | throw (RuntimeException) result; |
| 6079 | } else { |
| 6080 | return false; |
| 6081 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6082 | } else if (result instanceof Boolean) { |
| 6083 | success = (Boolean) result; |
| 6084 | } else { |
| 6085 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6086 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6087 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | return success; |
| 6089 | } finally { |
| 6090 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6091 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6095 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6096 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6098 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6099 | |
| 6100 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6101 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6102 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6103 | if (DBG) { |
| 6104 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6105 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6106 | + p3 + " data=" + data); |
| 6107 | } |
| 6108 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6109 | command, p1, p2, p3, data); |
| 6110 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6111 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6112 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6113 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6114 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6115 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6116 | |
| 6117 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6118 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6119 | "iccTransmitApduLogicalChannelBySlot"); |
| 6120 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6121 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6122 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6123 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6124 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6125 | } |
| 6126 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6127 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6128 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6132 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | final long identity = Binder.clearCallingIdentity(); |
| 6134 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6135 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | return ""; |
| 6137 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6140 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6141 | null /* workSource */); |
| 6142 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6143 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6144 | // Append the returned status code to the end of the response payload. |
| 6145 | String s = Integer.toHexString( |
| 6146 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6147 | if (response.payload != null) { |
| 6148 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6149 | } |
| 6150 | return s; |
| 6151 | } finally { |
| 6152 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6153 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6154 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6155 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6156 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6157 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6158 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6160 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6161 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6162 | |
| 6163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6164 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6165 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6166 | if (DBG) { |
| 6167 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6168 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6169 | } |
| 6170 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6171 | cla, command, p1, p2, p3, data); |
| 6172 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6173 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6174 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6175 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6176 | 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] | 6177 | enforceModifyPermission(); |
| 6178 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6179 | |
| 6180 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6181 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6182 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6183 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6184 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6185 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6186 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6190 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6191 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6192 | } |
| 6193 | |
| 6194 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6195 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6196 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6197 | final long identity = Binder.clearCallingIdentity(); |
| 6198 | try { |
| 6199 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6200 | && TextUtils.equals(ISDR_AID, data)) { |
| 6201 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6202 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6203 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6204 | if (bestComponent == null |
| 6205 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6206 | loge("The calling package is not allowed to select ISD-R."); |
| 6207 | throw new SecurityException( |
| 6208 | "The calling package is not allowed to select ISD-R."); |
| 6209 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6210 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6211 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6212 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6213 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6214 | null /* workSource */); |
| 6215 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6217 | // Append the returned status code to the end of the response payload. |
| 6218 | String s = Integer.toHexString( |
| 6219 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6220 | if (response.payload != null) { |
| 6221 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6222 | } |
| 6223 | return s; |
| 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6226 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6230 | 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] | 6231 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6233 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6234 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6235 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6236 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6237 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | final long identity = Binder.clearCallingIdentity(); |
| 6239 | try { |
| 6240 | if (DBG) { |
| 6241 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6242 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6243 | } |
| 6244 | |
| 6245 | IccIoResult response = |
| 6246 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6247 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6248 | subId); |
| 6249 | |
| 6250 | if (DBG) { |
| 6251 | log("Exchange SIM_IO [R]" + response); |
| 6252 | } |
| 6253 | |
| 6254 | byte[] result = null; |
| 6255 | int length = 2; |
| 6256 | if (response.payload != null) { |
| 6257 | length = 2 + response.payload.length; |
| 6258 | result = new byte[length]; |
| 6259 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6260 | } else { |
| 6261 | result = new byte[length]; |
| 6262 | } |
| 6263 | |
| 6264 | result[length - 1] = (byte) response.sw2; |
| 6265 | result[length - 2] = (byte) response.sw1; |
| 6266 | return result; |
| 6267 | } finally { |
| 6268 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6269 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6270 | } |
| 6271 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6272 | /** |
| 6273 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6274 | * on a particular subscription |
| 6275 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6276 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6277 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6279 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6280 | return null; |
| 6281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6283 | enforceTelephonyFeatureWithException(callingPackage, |
| 6284 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | final long identity = Binder.clearCallingIdentity(); |
| 6287 | try { |
| 6288 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6289 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6290 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6291 | return null; |
| 6292 | } |
| 6293 | Object response = sendRequest( |
| 6294 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6295 | if (response instanceof String[]) { |
| 6296 | return (String[]) response; |
| 6297 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6298 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6300 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6301 | } finally { |
| 6302 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6303 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6304 | } |
| 6305 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6306 | /** |
| 6307 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6308 | * subscription. |
| 6309 | * |
| 6310 | * @param subId the id of the subscription. |
| 6311 | * @param appType the uicc app type, must be USIM or SIM. |
| 6312 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6313 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6314 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6315 | * @return number of fplmns that is successfully written to the SIM. |
| 6316 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6317 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6318 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6320 | mApp, subId, "setForbiddenPlmns"); |
| 6321 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6322 | enforceTelephonyFeatureWithException(callingPackage, |
| 6323 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6324 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6325 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6326 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6327 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6328 | } |
| 6329 | if (fplmns == null) { |
| 6330 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6331 | } |
| 6332 | for (String fplmn : fplmns) { |
| 6333 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6334 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6335 | } |
| 6336 | } |
| 6337 | final long identity = Binder.clearCallingIdentity(); |
| 6338 | try { |
| 6339 | Object response = sendRequest( |
| 6340 | CMD_SET_FORBIDDEN_PLMNS, |
| 6341 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6342 | subId); |
| 6343 | return (int) response; |
| 6344 | } finally { |
| 6345 | Binder.restoreCallingIdentity(identity); |
| 6346 | } |
| 6347 | } |
| 6348 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6349 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6350 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6352 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6354 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6355 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
| 6359 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6360 | if (response.payload == null) { |
| 6361 | return ""; |
| 6362 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6364 | // Append the returned status code to the end of the response payload. |
| 6365 | String s = Integer.toHexString( |
| 6366 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6367 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6368 | return s; |
| 6369 | } finally { |
| 6370 | Binder.restoreCallingIdentity(identity); |
| 6371 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6372 | } |
| 6373 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6374 | /** |
| 6375 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6376 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6377 | * |
| 6378 | * @param itemID the ID of the item to read |
| 6379 | * @return the NV item as a String, or null on error. |
| 6380 | */ |
| 6381 | @Override |
| 6382 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6383 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6385 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | |
| 6387 | final long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
| 6389 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6390 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6391 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6392 | return value; |
| 6393 | } finally { |
| 6394 | Binder.restoreCallingIdentity(identity); |
| 6395 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | /** |
| 6399 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6400 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6401 | * |
| 6402 | * @param itemID the ID of the item to read |
| 6403 | * @param itemValue the value to write, as a String |
| 6404 | * @return true on success; false on any failure |
| 6405 | */ |
| 6406 | @Override |
| 6407 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6408 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6409 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6410 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6411 | |
| 6412 | final long identity = Binder.clearCallingIdentity(); |
| 6413 | try { |
| 6414 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6415 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6416 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6418 | return success; |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | /** |
| 6425 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6426 | * Used for device configuration by some CDMA operators. |
| 6427 | * |
| 6428 | * @param preferredRoamingList byte array containing the new PRL |
| 6429 | * @return true on success; false on any failure |
| 6430 | */ |
| 6431 | @Override |
| 6432 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6433 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6434 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6435 | |
| 6436 | final long identity = Binder.clearCallingIdentity(); |
| 6437 | try { |
| 6438 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6439 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6440 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6441 | return success; |
| 6442 | } finally { |
| 6443 | Binder.restoreCallingIdentity(identity); |
| 6444 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6448 | * 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] | 6449 | * Used for device configuration by some CDMA operators. |
| 6450 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6451 | * @param slotIndex - device slot. |
| 6452 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6453 | * @return true on success; false on any failure |
| 6454 | */ |
| 6455 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6456 | public boolean resetModemConfig(int slotIndex) { |
| 6457 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6458 | if (phone != null) { |
| 6459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6460 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6461 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6462 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6463 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6464 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6465 | final long identity = Binder.clearCallingIdentity(); |
| 6466 | try { |
| 6467 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6468 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6469 | return success; |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6473 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6474 | return false; |
| 6475 | } |
| 6476 | |
| 6477 | /** |
| 6478 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6479 | * |
| 6480 | * @param slotIndex - device slot. |
| 6481 | * |
| 6482 | * @return true on success; false on any failure |
| 6483 | */ |
| 6484 | @Override |
| 6485 | public boolean rebootModem(int slotIndex) { |
| 6486 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6487 | if (phone != null) { |
| 6488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6489 | mApp, phone.getSubId(), "rebootModem"); |
| 6490 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6492 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6493 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6494 | final long identity = Binder.clearCallingIdentity(); |
| 6495 | try { |
| 6496 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6497 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6498 | return success; |
| 6499 | } finally { |
| 6500 | Binder.restoreCallingIdentity(identity); |
| 6501 | } |
| 6502 | } |
| 6503 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6504 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6505 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6506 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6507 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6508 | * {@link #disableIms(int)}. |
| 6509 | * @param slotIndex device slot. |
| 6510 | */ |
| 6511 | public void resetIms(int slotIndex) { |
| 6512 | enforceModifyPermission(); |
| 6513 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6514 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6515 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6516 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6517 | final long identity = Binder.clearCallingIdentity(); |
| 6518 | try { |
| 6519 | if (mImsResolver == null) { |
| 6520 | // may happen if the does not support IMS. |
| 6521 | return; |
| 6522 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6523 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6524 | } finally { |
| 6525 | Binder.restoreCallingIdentity(identity); |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6530 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6531 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6532 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6533 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6534 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | |
| 6536 | final long identity = Binder.clearCallingIdentity(); |
| 6537 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6538 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6539 | // may happen if the device does not support IMS. |
| 6540 | return; |
| 6541 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6542 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6543 | } finally { |
| 6544 | Binder.restoreCallingIdentity(identity); |
| 6545 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6549 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6550 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6551 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6552 | public void disableIms(int slotId) { |
| 6553 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6554 | |
| 6555 | final long identity = Binder.clearCallingIdentity(); |
| 6556 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6557 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6558 | // may happen if the device does not support IMS. |
| 6559 | return; |
| 6560 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6561 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6562 | } finally { |
| 6563 | Binder.restoreCallingIdentity(identity); |
| 6564 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6568 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6569 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6570 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6571 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6572 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | |
| 6575 | final long identity = Binder.clearCallingIdentity(); |
| 6576 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6577 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6578 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6579 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6580 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6581 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6582 | } finally { |
| 6583 | Binder.restoreCallingIdentity(identity); |
| 6584 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6585 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6586 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6587 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6588 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6589 | @Override |
| 6590 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6591 | enforceModifyPermission(); |
| 6592 | |
| 6593 | final long identity = Binder.clearCallingIdentity(); |
| 6594 | try { |
| 6595 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6596 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6597 | } finally { |
| 6598 | Binder.restoreCallingIdentity(identity); |
| 6599 | } |
| 6600 | } |
| 6601 | |
| 6602 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6603 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6604 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6605 | */ |
| 6606 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6607 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
| 6609 | final long identity = Binder.clearCallingIdentity(); |
| 6610 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6611 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6612 | // may happen if the device does not support IMS. |
| 6613 | return null; |
| 6614 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6615 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | } finally { |
| 6617 | Binder.restoreCallingIdentity(identity); |
| 6618 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6619 | } |
| 6620 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6621 | /** |
| 6622 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6623 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6624 | */ |
| 6625 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6626 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6627 | |
| 6628 | final long identity = Binder.clearCallingIdentity(); |
| 6629 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6630 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6631 | // may happen if the device does not support IMS. |
| 6632 | return null; |
| 6633 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6634 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
| 6637 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6638 | } |
| 6639 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6640 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6641 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6642 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6643 | * @param slotIndex the slot ID that the ImsService should bind for. |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6644 | * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL} |
| 6645 | * if there is no preference. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6646 | * @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] | 6647 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6648 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6649 | * @param packageName The name of the package that the current configuration will be replaced |
| 6650 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6651 | * @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] | 6652 | */ |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6653 | public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService, |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6655 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6657 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6658 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | final long identity = Binder.clearCallingIdentity(); |
| 6660 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6661 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6662 | // may happen if the device does not support IMS. |
| 6663 | return false; |
| 6664 | } |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6665 | return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId, |
| 6666 | isCarrierService, featureTypes); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
| 6669 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6673 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6674 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6675 | * |
| 6676 | * This should only be used for testing. |
| 6677 | * |
| 6678 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6679 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6680 | */ |
| 6681 | @Override |
| 6682 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6683 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6684 | "clearCarrierImsServiceOverride"); |
| 6685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6686 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6687 | |
| 6688 | final long identity = Binder.clearCallingIdentity(); |
| 6689 | try { |
| 6690 | if (mImsResolver == null) { |
| 6691 | // may happen if the device does not support IMS. |
| 6692 | return false; |
| 6693 | } |
| 6694 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6695 | } finally { |
| 6696 | Binder.restoreCallingIdentity(identity); |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6701 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6702 | * |
| 6703 | * @param slotId The slot that the ImsService is associated with. |
| 6704 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6705 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6706 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6707 | * @return the package name of the ImsService configuration. |
| 6708 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6709 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6710 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6711 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6712 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6713 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6714 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | final long identity = Binder.clearCallingIdentity(); |
| 6716 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6717 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6718 | // may happen if the device does not support IMS. |
| 6719 | return ""; |
| 6720 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6721 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6722 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6723 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
| 6726 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6729 | /** |
| 6730 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6731 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6732 | * @param callback A callback with an integer containing the |
| 6733 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6734 | */ |
| 6735 | @Override |
| 6736 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6737 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6738 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6739 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6740 | "IMS not available on device."); |
| 6741 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6742 | final long token = Binder.clearCallingIdentity(); |
| 6743 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6744 | int slotId = getSlotIndex(subId); |
| 6745 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6746 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6747 | + subId + "'"); |
| 6748 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6749 | } |
| 6750 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6751 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6752 | try { |
| 6753 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6754 | } catch (RemoteException e) { |
| 6755 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6756 | + "Ignore"); |
| 6757 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6758 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6759 | } catch (ImsException e) { |
| 6760 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(token); |
| 6763 | } |
| 6764 | } |
| 6765 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6766 | /** |
| 6767 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6768 | */ |
| 6769 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6770 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | |
| 6772 | final long identity = Binder.clearCallingIdentity(); |
| 6773 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6774 | // NOTE: Before S, this method only set the default phone. |
| 6775 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6776 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6777 | phone.setImsRegistrationState(registered); |
| 6778 | } |
| 6779 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | } finally { |
| 6781 | Binder.restoreCallingIdentity(identity); |
| 6782 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6783 | } |
| 6784 | |
| 6785 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6786 | * Set the network selection mode to automatic. |
| 6787 | * |
| 6788 | */ |
| 6789 | @Override |
| 6790 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6792 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6793 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6794 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6795 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6797 | final long identity = Binder.clearCallingIdentity(); |
| 6798 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6799 | if (!isActiveSubscription(subId)) { |
| 6800 | return; |
| 6801 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6803 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 6804 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | } finally { |
| 6806 | Binder.restoreCallingIdentity(identity); |
| 6807 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6808 | } |
| 6809 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6810 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6811 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6812 | * |
| 6813 | * @param subId the id of the subscription. |
| 6814 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6815 | * the operator to attach to. |
| 6816 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6817 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6818 | * normal network selection next time. |
| 6819 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6820 | */ |
| 6821 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6822 | public boolean setNetworkSelectionModeManual( |
| 6823 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6825 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6826 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6827 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6828 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6829 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6830 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6831 | if (!isActiveSubscription(subId)) { |
| 6832 | return false; |
| 6833 | } |
| 6834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6835 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6836 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6837 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6838 | if (DBG) { |
| 6839 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6840 | + " operator: " + operatorInfo); |
| 6841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6843 | } finally { |
| 6844 | Binder.restoreCallingIdentity(identity); |
| 6845 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6846 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6847 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6848 | * Get the manual network selection |
| 6849 | * |
| 6850 | * @param subId the id of the subscription. |
| 6851 | * |
| 6852 | * @return the previously saved user selected PLMN |
| 6853 | */ |
| 6854 | @Override |
| 6855 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6856 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6857 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6858 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6859 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6860 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6861 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6862 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6866 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6867 | } |
| 6868 | |
| 6869 | final Phone phone = getPhone(subId); |
| 6870 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6871 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6872 | } |
| 6873 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6874 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6875 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6876 | } finally { |
| 6877 | Binder.restoreCallingIdentity(identity); |
| 6878 | } |
| 6879 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6880 | |
| 6881 | /** |
| 6882 | * Scans for available networks. |
| 6883 | */ |
| 6884 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6885 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6886 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6888 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6889 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6890 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6891 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6892 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6893 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6894 | .setCallingPid(Binder.getCallingPid()) |
| 6895 | .setCallingUid(Binder.getCallingUid()) |
| 6896 | .setMethod("getCellNetworkScanResults") |
| 6897 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6898 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6899 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6900 | .build()); |
| 6901 | switch (locationResult) { |
| 6902 | case DENIED_HARD: |
| 6903 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6904 | case DENIED_SOFT: |
| 6905 | return null; |
| 6906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6908 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6909 | try { |
| 6910 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6911 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6912 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6913 | } finally { |
| 6914 | Binder.restoreCallingIdentity(identity); |
| 6915 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
| 6918 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6919 | * Get the call forwarding info, given the call forwarding reason. |
| 6920 | */ |
| 6921 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6922 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6923 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6924 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6925 | |
| 6926 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6927 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6928 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6929 | long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
| 6931 | if (DBG) { |
| 6932 | log("getCallForwarding: subId " + subId |
| 6933 | + " callForwardingReason" + callForwardingReason); |
| 6934 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6935 | |
| 6936 | Phone phone = getPhone(subId); |
| 6937 | if (phone == null) { |
| 6938 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6939 | callback.onError( |
| 6940 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6941 | } catch (RemoteException e) { |
| 6942 | // ignore |
| 6943 | } |
| 6944 | return; |
| 6945 | } |
| 6946 | |
| 6947 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6948 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6949 | @Override |
| 6950 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6951 | try { |
| 6952 | callback.onCallForwardingInfoAvailable(info); |
| 6953 | } catch (RemoteException e) { |
| 6954 | // ignore |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | @Override |
| 6959 | public void onError(int error) { |
| 6960 | try { |
| 6961 | callback.onError(error); |
| 6962 | } catch (RemoteException e) { |
| 6963 | // ignore |
| 6964 | } |
| 6965 | } |
| 6966 | }); |
| 6967 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
| 6971 | } |
| 6972 | |
| 6973 | /** |
| 6974 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6975 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6976 | */ |
| 6977 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6978 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6979 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6980 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6981 | |
| 6982 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6983 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6984 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6985 | long identity = Binder.clearCallingIdentity(); |
| 6986 | try { |
| 6987 | if (DBG) { |
| 6988 | log("setCallForwarding: subId " + subId |
| 6989 | + " callForwardingInfo" + callForwardingInfo); |
| 6990 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6991 | |
| 6992 | Phone phone = getPhone(subId); |
| 6993 | if (phone == null) { |
| 6994 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6995 | callback.accept( |
| 6996 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6997 | } catch (RemoteException e) { |
| 6998 | // ignore |
| 6999 | } |
| 7000 | return; |
| 7001 | } |
| 7002 | |
| 7003 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7004 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7005 | |
| 7006 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
| 7009 | } |
| 7010 | } |
| 7011 | |
| 7012 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7013 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7014 | */ |
| 7015 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7016 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7017 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7018 | |
| 7019 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7020 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7021 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7022 | long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7024 | Phone phone = getPhone(subId); |
| 7025 | if (phone == null) { |
| 7026 | try { |
| 7027 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7028 | } catch (RemoteException e) { |
| 7029 | // ignore |
| 7030 | } |
| 7031 | return; |
| 7032 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7033 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7034 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7035 | boolean requireUssd = c.getBoolean( |
| 7036 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7037 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7038 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7039 | if (requireUssd) { |
| 7040 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7041 | getSubscriptionCarrierId(subId)); |
| 7042 | String newUssdCommand = ""; |
| 7043 | try { |
| 7044 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7045 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7046 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7047 | } catch (NullPointerException e) { |
| 7048 | loge("Failed to generate USSD number" + e); |
| 7049 | } |
| 7050 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7051 | mMainThreadHandler, callback, carrierXmlParser, |
| 7052 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7053 | final String ussdCommand = newUssdCommand; |
| 7054 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7055 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7056 | }); |
| 7057 | } else { |
| 7058 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7059 | callback::accept); |
| 7060 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7061 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
| 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7068 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7069 | */ |
| 7070 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7071 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7072 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7073 | |
| 7074 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7075 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7076 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7077 | long identity = Binder.clearCallingIdentity(); |
| 7078 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7079 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7080 | |
| 7081 | Phone phone = getPhone(subId); |
| 7082 | if (phone == null) { |
| 7083 | try { |
| 7084 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7085 | } catch (RemoteException e) { |
| 7086 | // ignore |
| 7087 | } |
| 7088 | return; |
| 7089 | } |
| 7090 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7091 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7092 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7093 | boolean requireUssd = c.getBoolean( |
| 7094 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7095 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7096 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7097 | if (requireUssd) { |
| 7098 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7099 | getSubscriptionCarrierId(subId)); |
| 7100 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7101 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7102 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7103 | String newUssdCommand = ""; |
| 7104 | try { |
| 7105 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7106 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7107 | .makeCommand(ssAction, null); |
| 7108 | } catch (NullPointerException e) { |
| 7109 | loge("Failed to generate USSD number" + e); |
| 7110 | } |
| 7111 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7112 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7113 | final String ussdCommand = newUssdCommand; |
| 7114 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7115 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7116 | }); |
| 7117 | } else { |
| 7118 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7119 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7120 | |
| 7121 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7122 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7123 | } finally { |
| 7124 | Binder.restoreCallingIdentity(identity); |
| 7125 | } |
| 7126 | } |
| 7127 | |
| 7128 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7129 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7130 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7131 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7132 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7133 | * location related information which will be sent if the caller already possess |
| 7134 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7135 | * @param request contains the radio access networks with bands/channels to scan |
| 7136 | * @param messenger callback messenger for scan results or errors |
| 7137 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7138 | * @return the id of the requested scan which can be used to stop the scan. |
| 7139 | */ |
| 7140 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7141 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7142 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7143 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7145 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7146 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7147 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7148 | if (!renounceFineLocationAccess) { |
| 7149 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7150 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7151 | .setCallingPackage(callingPackage) |
| 7152 | .setCallingFeatureId(callingFeatureId) |
| 7153 | .setCallingPid(Binder.getCallingPid()) |
| 7154 | .setCallingUid(Binder.getCallingUid()) |
| 7155 | .setMethod("requestNetworkScan") |
| 7156 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7157 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7158 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7159 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7160 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7161 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7162 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7163 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7164 | if (e != null) { |
| 7165 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7166 | throw e; |
| 7167 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7168 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7169 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7170 | } |
| 7171 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7172 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7173 | |
| 7174 | enforceTelephonyFeatureWithException(callingPackage, |
| 7175 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7176 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7177 | int callingUid = Binder.getCallingUid(); |
| 7178 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7179 | final long identity = Binder.clearCallingIdentity(); |
| 7180 | try { |
| 7181 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7182 | renounceFineLocationAccess, request, messenger, binder, |
| 7183 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7184 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7185 | } finally { |
| 7186 | Binder.restoreCallingIdentity(identity); |
| 7187 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7188 | } |
| 7189 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7190 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7191 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7192 | boolean hasCarrierPriv; |
| 7193 | final long identity = Binder.clearCallingIdentity(); |
| 7194 | try { |
| 7195 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7196 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7197 | } finally { |
| 7198 | Binder.restoreCallingIdentity(identity); |
| 7199 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7200 | boolean hasNetworkScanPermission = |
| 7201 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7202 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7203 | |
| 7204 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7205 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7206 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7210 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7211 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7212 | return new SecurityException("Specific channels must not be" |
| 7213 | + " scanned without location access."); |
| 7214 | } |
| 7215 | } |
| 7216 | } |
| 7217 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7218 | return null; |
| 7219 | } |
| 7220 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7221 | /** |
| 7222 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7223 | * |
| 7224 | * @param subId id of the subscription |
| 7225 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7226 | */ |
| 7227 | @Override |
| 7228 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7230 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7231 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7232 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | final long identity = Binder.clearCallingIdentity(); |
| 7234 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7235 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
| 7238 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
| 7241 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7242 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7243 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7244 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7245 | */ |
| 7246 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7247 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7248 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7249 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7250 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7252 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7253 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | final long identity = Binder.clearCallingIdentity(); |
| 7256 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7257 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7258 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7259 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7260 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7261 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7262 | } finally { |
| 7263 | Binder.restoreCallingIdentity(identity); |
| 7264 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7265 | } |
| 7266 | |
| 7267 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7268 | * Get the allowed network types for certain reason. |
| 7269 | * |
| 7270 | * @param subId the id of the subscription. |
| 7271 | * @param reason the reason the allowed network type change is taking place |
| 7272 | * @return the allowed network types. |
| 7273 | */ |
| 7274 | @Override |
| 7275 | public long getAllowedNetworkTypesForReason(int subId, |
| 7276 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7277 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7278 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7279 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7280 | if (!mApp.getResources().getBoolean( |
| 7281 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7282 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7283 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7284 | "getAllowedNetworkTypesForReason"); |
| 7285 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7286 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7287 | final long identity = Binder.clearCallingIdentity(); |
| 7288 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7289 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7290 | } finally { |
| 7291 | Binder.restoreCallingIdentity(identity); |
| 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7296 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7297 | * @param subId subscription id of the sim card |
| 7298 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7299 | * This can be passed following states |
| 7300 | * <ol> |
| 7301 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7302 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7303 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7304 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7305 | * </ol> |
| 7306 | * @return operation result. |
| 7307 | */ |
| 7308 | @Override |
| 7309 | public int setNrDualConnectivityState(int subId, |
| 7310 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7311 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7312 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7313 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7314 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7315 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7316 | } |
| 7317 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7319 | final long identity = Binder.clearCallingIdentity(); |
| 7320 | try { |
| 7321 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7322 | nrDualConnectivityState, subId, |
| 7323 | workSource); |
| 7324 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7325 | return result; |
| 7326 | } finally { |
| 7327 | Binder.restoreCallingIdentity(identity); |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | /** |
| 7332 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7333 | * @return true if dual connectivity is enabled else false |
| 7334 | */ |
| 7335 | @Override |
| 7336 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7337 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7338 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7339 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7340 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7341 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7342 | return false; |
| 7343 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7344 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
| 7347 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7348 | null, subId, workSource); |
| 7349 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7350 | return isEnabled; |
| 7351 | } finally { |
| 7352 | Binder.restoreCallingIdentity(identity); |
| 7353 | } |
| 7354 | } |
| 7355 | |
| 7356 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7357 | * Set the allowed network types of the device and |
| 7358 | * provide the reason triggering the allowed network change. |
| 7359 | * |
| 7360 | * @param subId the id of the subscription. |
| 7361 | * @param reason the reason the allowed network type change is taking place |
| 7362 | * @param allowedNetworkTypes the allowed network types. |
| 7363 | * @return true on success; false on any failure. |
| 7364 | */ |
| 7365 | @Override |
| 7366 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7367 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7368 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7370 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7371 | // If the caller only has carrier privileges, then they should not be able to override |
| 7372 | // any network types which were set for security reasons. |
| 7373 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7374 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7375 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7376 | throw new SecurityException( |
| 7377 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7378 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7379 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7380 | |
| 7381 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7382 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7383 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7384 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7385 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7386 | return false; |
| 7387 | } |
| 7388 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7389 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7390 | return false; |
| 7391 | } |
| 7392 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7393 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7394 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7395 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7396 | Phone phone = getPhone(subId); |
| 7397 | if (phone == null) { |
| 7398 | return false; |
| 7399 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7400 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7401 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7402 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7403 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7404 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7405 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7406 | final long identity = Binder.clearCallingIdentity(); |
| 7407 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7408 | Boolean success = (Boolean) sendRequest( |
| 7409 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7410 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7411 | |
| 7412 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7413 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7414 | } finally { |
| 7415 | Binder.restoreCallingIdentity(identity); |
| 7416 | } |
| 7417 | } |
| 7418 | |
| 7419 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7420 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7421 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7422 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7423 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7424 | * @hide |
| 7425 | */ |
| 7426 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7427 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7428 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7429 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7430 | if (!mApp.getResources().getBoolean( |
| 7431 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7432 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7433 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7434 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7437 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7439 | if (phone != null) { |
| 7440 | return phone.hasMatchedTetherApnSetting(); |
| 7441 | } else { |
| 7442 | return false; |
| 7443 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | } finally { |
| 7445 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7446 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7447 | } |
| 7448 | |
| 7449 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7450 | * Get the user enabled state of Mobile Data. |
| 7451 | * |
| 7452 | * TODO: remove and use isUserDataEnabled. |
| 7453 | * This can't be removed now because some vendor codes |
| 7454 | * calls through ITelephony directly while they should |
| 7455 | * use TelephonyManager. |
| 7456 | * |
| 7457 | * @return true on enabled |
| 7458 | */ |
| 7459 | @Override |
| 7460 | public boolean getDataEnabled(int subId) { |
| 7461 | return isUserDataEnabled(subId); |
| 7462 | } |
| 7463 | |
| 7464 | /** |
| 7465 | * Get whether mobile data is enabled per user setting. |
| 7466 | * |
| 7467 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7468 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7469 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7470 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7471 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7472 | * |
| 7473 | * @return {@code true} if data is enabled else {@code false} |
| 7474 | */ |
| 7475 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7476 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7477 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7478 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7479 | try { |
| 7480 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7481 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7482 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7483 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7484 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7485 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7487 | mApp, subId, functionName); |
| 7488 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | |
| 7491 | final long identity = Binder.clearCallingIdentity(); |
| 7492 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7493 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7495 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7496 | if (phone != null) { |
| 7497 | boolean retVal = phone.isUserDataEnabled(); |
| 7498 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7499 | return retVal; |
| 7500 | } else { |
| 7501 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7502 | return false; |
| 7503 | } |
| 7504 | } finally { |
| 7505 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7506 | } |
| 7507 | } |
| 7508 | |
| 7509 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7510 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7511 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7512 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7513 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7514 | * @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] | 7515 | */ |
| 7516 | @Override |
| 7517 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7518 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7519 | try { |
| 7520 | try { |
| 7521 | mApp.enforceCallingOrSelfPermission( |
| 7522 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7523 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7524 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7525 | try { |
| 7526 | mApp.enforceCallingOrSelfPermission( |
| 7527 | android.Manifest.permission.READ_PHONE_STATE, |
| 7528 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7529 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7530 | mApp.enforceCallingOrSelfPermission( |
| 7531 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7532 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7533 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7534 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7535 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7538 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7539 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7540 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | final long identity = Binder.clearCallingIdentity(); |
| 7542 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7543 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7545 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7546 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7547 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | return retVal; |
| 7549 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7550 | if (DBG) { |
| 7551 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7552 | + subId + " retVal=false"); |
| 7553 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | return false; |
| 7555 | } |
| 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7558 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7559 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7560 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7561 | /** |
| 7562 | * Check if data is enabled for a specific reason |
| 7563 | * @param subId Subscription index |
| 7564 | * @param reason the reason the data enable change is taking place |
| 7565 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7566 | */ |
| 7567 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7568 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7569 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7570 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7571 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7572 | try { |
| 7573 | mApp.enforceCallingOrSelfPermission( |
| 7574 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7575 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7576 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7577 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7578 | functionName); |
| 7579 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7580 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7581 | try { |
| 7582 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7583 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7584 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7586 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7587 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7588 | } |
| 7589 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7590 | if (!mApp.getResources().getBoolean( |
| 7591 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7592 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7593 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7594 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7595 | |
| 7596 | final long identity = Binder.clearCallingIdentity(); |
| 7597 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7598 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7599 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7600 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7601 | + " reason=" + reason); |
| 7602 | } |
| 7603 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7604 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7605 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7606 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7607 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7608 | return retVal; |
| 7609 | } else { |
| 7610 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7611 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7612 | + subId + " retVal=false"); |
| 7613 | } |
| 7614 | return false; |
| 7615 | } |
| 7616 | } finally { |
| 7617 | Binder.restoreCallingIdentity(identity); |
| 7618 | } |
| 7619 | } |
| 7620 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7621 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7622 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7623 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7624 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7625 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7626 | // No permission needed; this only lets the caller inspect their own status. |
| 7627 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7628 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7629 | |
| 7630 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7631 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7632 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7633 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7634 | if (!mApp.getResources().getBoolean( |
| 7635 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7636 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7637 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7638 | "getCarrierPrivilegeStatusForUid"); |
| 7639 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7640 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7641 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7642 | } |
| 7643 | |
| 7644 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7645 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7646 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7647 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7648 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7649 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7650 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7651 | if (cpt == null) { |
| 7652 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7653 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7654 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7655 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7656 | } |
| 7657 | |
| 7658 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7659 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7660 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7661 | |
| 7662 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7663 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7664 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7665 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7666 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7667 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7668 | Phone phone = getPhone(subId); |
| 7669 | if (phone == null) { |
| 7670 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7671 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7672 | } |
| 7673 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7674 | if (cpt == null) { |
| 7675 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7676 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7677 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7678 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7679 | } |
| 7680 | |
| 7681 | @Override |
| 7682 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7683 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7684 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7685 | if (!mApp.getResources().getBoolean( |
| 7686 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7687 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7688 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7689 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7690 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7691 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7692 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7693 | } |
| 7694 | |
| 7695 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7696 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7697 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7698 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7699 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7700 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7701 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7702 | if (phone == null) { |
| 7703 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7704 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7705 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7706 | if (cpt == null) { |
| 7707 | continue; |
| 7708 | } |
| 7709 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7710 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7711 | break; |
| 7712 | } |
| 7713 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7714 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7715 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7716 | |
| 7717 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7718 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7719 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7720 | |
| 7721 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7722 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7723 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7724 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7725 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7726 | if (phone == null) { |
| 7727 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7728 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7729 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7730 | if (cpt == null) { |
| 7731 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7732 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7733 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7734 | } |
| 7735 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7736 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7737 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7738 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Yan Yan | 965c84f | 2024-09-24 18:14:17 -0700 | [diff] [blame] | 7739 | |
| 7740 | enforceTelephonyFeatureWithException( |
| 7741 | getCurrentPackageName(), |
| 7742 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7743 | "getPackagesWithCarrierPrivileges"); |
| 7744 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7745 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7746 | if (phone == null) { |
| 7747 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7748 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7749 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7750 | if (cpt == null) { |
| 7751 | return Collections.emptyList(); |
| 7752 | } |
| 7753 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7754 | } |
| 7755 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7756 | @Override |
| 7757 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7758 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7759 | |
| 7760 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7761 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7762 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7763 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7764 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7765 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7766 | try { |
| 7767 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7768 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7769 | } |
| 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7772 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7773 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7774 | } |
| 7775 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7776 | @Override |
| 7777 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7778 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7779 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7780 | if (!mApp.getResources().getBoolean( |
| 7781 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7782 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7783 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7784 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7785 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7786 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7787 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7788 | if (phone == null) { |
| 7789 | return null; |
| 7790 | } |
| 7791 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7792 | if (cpt == null) { |
| 7793 | return null; |
| 7794 | } |
| 7795 | return cpt.getCarrierServicePackageName(); |
| 7796 | } |
| 7797 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7798 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7799 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7800 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7801 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7802 | return null; |
| 7803 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7804 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7805 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7806 | return null; |
| 7807 | } |
| 7808 | return iccId; |
| 7809 | } |
| 7810 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7811 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7812 | public void setCallComposerStatus(int subId, int status) { |
| 7813 | enforceModifyPermission(); |
| 7814 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7815 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7816 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7817 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7818 | final long identity = Binder.clearCallingIdentity(); |
| 7819 | try { |
| 7820 | Phone phone = getPhone(subId); |
| 7821 | if (phone != null) { |
| 7822 | Phone defaultPhone = phone.getImsPhone(); |
| 7823 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7824 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7825 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7826 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7827 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7828 | } |
| 7829 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7830 | } catch (ImsException e) { |
| 7831 | throw new ServiceSpecificException(e.getCode()); |
| 7832 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7833 | Binder.restoreCallingIdentity(identity); |
| 7834 | } |
| 7835 | } |
| 7836 | |
| 7837 | @Override |
| 7838 | public int getCallComposerStatus(int subId) { |
| 7839 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7840 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7841 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7842 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7843 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7844 | final long identity = Binder.clearCallingIdentity(); |
| 7845 | try { |
| 7846 | Phone phone = getPhone(subId); |
| 7847 | if (phone != null) { |
| 7848 | Phone defaultPhone = phone.getImsPhone(); |
| 7849 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7850 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7851 | return imsPhone.getCallComposerStatus(); |
| 7852 | } |
| 7853 | } |
| 7854 | } finally { |
| 7855 | Binder.restoreCallingIdentity(identity); |
| 7856 | } |
| 7857 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7858 | } |
| 7859 | |
| 7860 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7861 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7862 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7863 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7864 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7865 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7866 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7867 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7868 | "setLine1NumberForDisplayForSubscriber"); |
| 7869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
| 7872 | final String iccId = getIccId(subId); |
| 7873 | final Phone phone = getPhone(subId); |
| 7874 | if (phone == null) { |
| 7875 | return false; |
| 7876 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7877 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7878 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7879 | return false; |
| 7880 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7881 | final String subscriberId = phone.getSubscriberId(); |
| 7882 | |
| 7883 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7884 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7885 | + subscriberId + " to " + number); |
| 7886 | } |
| 7887 | |
| 7888 | if (TextUtils.isEmpty(iccId)) { |
| 7889 | return false; |
| 7890 | } |
| 7891 | |
| 7892 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7893 | |
| 7894 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7895 | if (alphaTag == null) { |
| 7896 | editor.remove(alphaTagPrefKey); |
| 7897 | } else { |
| 7898 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7899 | } |
| 7900 | |
| 7901 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7902 | // track all merged IMSIs based on line number |
| 7903 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7904 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7905 | if (number == null) { |
| 7906 | editor.remove(numberPrefKey); |
| 7907 | editor.remove(subscriberPrefKey); |
| 7908 | } else { |
| 7909 | editor.putString(numberPrefKey, number); |
| 7910 | editor.putString(subscriberPrefKey, subscriberId); |
| 7911 | } |
| 7912 | |
| 7913 | editor.commit(); |
| 7914 | return true; |
| 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7917 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7921 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7922 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7923 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7925 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7926 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7927 | return null; |
| 7928 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7929 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7930 | if (!mApp.getResources().getBoolean( |
| 7931 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7932 | enforceTelephonyFeatureWithException(callingPackage, |
| 7933 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7934 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | try { |
| 7938 | String iccId = getIccId(subId); |
| 7939 | if (iccId != null) { |
| 7940 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7941 | if (DBG_MERGE) { |
| 7942 | log("getLine1NumberForDisplay returning " |
| 7943 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7944 | } |
| 7945 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7947 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7948 | return null; |
| 7949 | } finally { |
| 7950 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7951 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7952 | } |
| 7953 | |
| 7954 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7955 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7956 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7957 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7958 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7959 | return null; |
| 7960 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7962 | final long identity = Binder.clearCallingIdentity(); |
| 7963 | try { |
| 7964 | String iccId = getIccId(subId); |
| 7965 | if (iccId != null) { |
| 7966 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7967 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7968 | } |
| 7969 | return null; |
| 7970 | } finally { |
| 7971 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7972 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7973 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7974 | |
| 7975 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7976 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7977 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7978 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7979 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7980 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7981 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7982 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7983 | return null; |
| 7984 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7985 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7986 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7987 | // the process, where TelephonyManager was instantiated. |
| 7988 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7989 | final long identity = Binder.clearCallingIdentity(); |
| 7990 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7991 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7993 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7994 | |
| 7995 | // Figure out what subscribers are currently active |
| 7996 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7997 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7998 | // Only consider subs which match the current subId |
| 7999 | // This logic can be simplified. See b/131189269 for progress. |
| 8000 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8001 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8003 | |
| 8004 | // First pass, find a number override for an active subscriber |
| 8005 | String mergeNumber = null; |
| 8006 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8007 | for (String key : prefs.keySet()) { |
| 8008 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8009 | final String subscriberId = (String) prefs.get(key); |
| 8010 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8011 | final String iccId = key.substring( |
| 8012 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8013 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8014 | mergeNumber = (String) prefs.get(numberKey); |
| 8015 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8016 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | + " for active subscriber " + subscriberId); |
| 8018 | } |
| 8019 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8020 | break; |
| 8021 | } |
| 8022 | } |
| 8023 | } |
| 8024 | } |
| 8025 | |
| 8026 | // Shortcut when no active merged subscribers |
| 8027 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8028 | return null; |
| 8029 | } |
| 8030 | |
| 8031 | // Second pass, find all subscribers under that line override |
| 8032 | final ArraySet<String> result = new ArraySet<>(); |
| 8033 | for (String key : prefs.keySet()) { |
| 8034 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8035 | final String number = (String) prefs.get(key); |
| 8036 | if (mergeNumber.equals(number)) { |
| 8037 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8038 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8039 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8040 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8041 | result.add(subscriberId); |
| 8042 | } |
| 8043 | } |
| 8044 | } |
| 8045 | } |
| 8046 | |
| 8047 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8048 | Arrays.sort(resultArray); |
| 8049 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8050 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8051 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8052 | } |
| 8053 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8054 | } finally { |
| 8055 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8056 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8057 | } |
| 8058 | |
| 8059 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8060 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8061 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8062 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8063 | enforceTelephonyFeatureWithException(callingPackage, |
| 8064 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8065 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
| 8068 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8069 | TelephonyManager.class); |
| 8070 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8071 | if (subscriberId == null) { |
| 8072 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8073 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8074 | + subId); |
| 8075 | } |
| 8076 | return null; |
| 8077 | } |
| 8078 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8079 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8080 | .getSubscriptionInfo(subId); |
| 8081 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8082 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8083 | if (groupUuid == null) { |
| 8084 | return new String[]{subscriberId}; |
| 8085 | } |
| 8086 | |
| 8087 | // Get all subscriberIds from the group. |
| 8088 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8089 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8090 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8091 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8092 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8093 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8094 | if (subscriberId != null) { |
| 8095 | mergedSubscriberIds.add(subscriberId); |
| 8096 | } |
| 8097 | } |
| 8098 | |
| 8099 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8100 | } finally { |
| 8101 | Binder.restoreCallingIdentity(identity); |
| 8102 | |
| 8103 | } |
| 8104 | } |
| 8105 | |
| 8106 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8107 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8108 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8109 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8110 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8111 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8112 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8113 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | final long identity = Binder.clearCallingIdentity(); |
| 8115 | try { |
| 8116 | final Phone phone = getPhone(subId); |
| 8117 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8118 | } finally { |
| 8119 | Binder.restoreCallingIdentity(identity); |
| 8120 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8121 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8122 | |
| 8123 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8124 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8125 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8126 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8127 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8128 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8129 | |
| 8130 | final long identity = Binder.clearCallingIdentity(); |
| 8131 | try { |
| 8132 | final Phone phone = getPhone(subId); |
| 8133 | if (phone == null) { |
| 8134 | return false; |
| 8135 | } |
| 8136 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8137 | cdmaNonRoamingList); |
| 8138 | } finally { |
| 8139 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8140 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8141 | } |
| 8142 | |
| 8143 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8144 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8145 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8146 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8147 | if (phone == null) { |
| 8148 | return raf; |
| 8149 | } |
| 8150 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8151 | try { |
| 8152 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8153 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8154 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8155 | } catch (SecurityException e) { |
| 8156 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8157 | throw e; |
| 8158 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8159 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8160 | if (!mApp.getResources().getBoolean( |
| 8161 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8162 | enforceTelephonyFeatureWithException(callingPackage, |
| 8163 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8164 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8166 | final long identity = Binder.clearCallingIdentity(); |
| 8167 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8168 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(identity); |
| 8171 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8172 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8173 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8174 | |
| 8175 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8176 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8177 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8178 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8179 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8180 | enforceTelephonyFeatureWithException(callingPackage, |
| 8181 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8182 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8183 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8184 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8185 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8186 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8187 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8188 | throw new SecurityException("App must be the dialer role holder to" |
| 8189 | + " upload a call composer pic"); |
| 8190 | } |
| 8191 | |
| 8192 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8193 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8194 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8195 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8196 | boolean readUntilEnd = false; |
| 8197 | int totalBytesRead = 0; |
| 8198 | byte[] buffer = new byte[16 * 1024]; |
| 8199 | while (true) { |
| 8200 | int numRead; |
| 8201 | try { |
| 8202 | numRead = input.read(buffer); |
| 8203 | } catch (IOException e) { |
| 8204 | try { |
| 8205 | fd.checkError(); |
| 8206 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8207 | null); |
| 8208 | } catch (IOException e1) { |
| 8209 | // This means that the other side closed explicitly with an error. If this |
| 8210 | // happens, log and ignore. |
| 8211 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8212 | } |
| 8213 | break; |
| 8214 | } |
| 8215 | if (numRead == -1) { |
| 8216 | readUntilEnd = true; |
| 8217 | break; |
| 8218 | } |
| 8219 | totalBytesRead += numRead; |
| 8220 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8221 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8222 | try { |
| 8223 | input.close(); |
| 8224 | } catch (IOException e) { |
| 8225 | // ignore |
| 8226 | } |
| 8227 | break; |
| 8228 | } |
| 8229 | output.write(buffer, 0, numRead); |
| 8230 | } |
| 8231 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8232 | // close is above, where the picture size is too big. |
| 8233 | |
| 8234 | try { |
| 8235 | fd.checkError(); |
| 8236 | } catch (IOException e) { |
| 8237 | loge("Remote end for call composer closed with an error: " + e); |
| 8238 | return; |
| 8239 | } |
| 8240 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8241 | if (!readUntilEnd) { |
| 8242 | loge("Did not finish reading entire image; aborting"); |
| 8243 | return; |
| 8244 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8245 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8246 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8247 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8248 | new CallComposerPictureTransfer.Factory() {}, |
| 8249 | imageData, |
| 8250 | (result) -> { |
| 8251 | if (result.first != null) { |
| 8252 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8253 | Bundle outputResult = new Bundle(); |
| 8254 | outputResult.putParcelable( |
| 8255 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8256 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8257 | outputResult); |
| 8258 | } else { |
| 8259 | callback.send(result.second, null); |
| 8260 | } |
| 8261 | } |
| 8262 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8263 | }); |
| 8264 | } |
| 8265 | |
| 8266 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8267 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8268 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8269 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8270 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8272 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8276 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8277 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8278 | } finally { |
| 8279 | Binder.restoreCallingIdentity(identity); |
| 8280 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8281 | } |
| 8282 | |
| 8283 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8284 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8285 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8286 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8287 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8288 | return false; |
| 8289 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8290 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8291 | enforceTelephonyFeatureWithException(callingPackage, |
| 8292 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8294 | final long identity = Binder.clearCallingIdentity(); |
| 8295 | try { |
| 8296 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8297 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8298 | // In the long run, we may instead need to check if there exists a connection service |
| 8299 | // which can support video calling. |
| 8300 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8301 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | return imsManager.isVtEnabledByPlatform() |
| 8303 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8304 | && imsManager.isVtEnabledByUser(); |
| 8305 | } finally { |
| 8306 | Binder.restoreCallingIdentity(identity); |
| 8307 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8308 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8309 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8310 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8311 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8312 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8314 | mApp, subId, callingPackage, callingFeatureId, |
| 8315 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8316 | return false; |
| 8317 | } |
| 8318 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8319 | enforceTelephonyFeatureWithException(callingPackage, |
| 8320 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8321 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8322 | final long identity = Binder.clearCallingIdentity(); |
| 8323 | try { |
| 8324 | CarrierConfigManager configManager = |
| 8325 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8326 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8327 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8328 | } finally { |
| 8329 | Binder.restoreCallingIdentity(identity); |
| 8330 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8334 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8335 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8336 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8337 | return false; |
| 8338 | } |
| 8339 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8340 | enforceTelephonyFeatureWithException(callingPackage, |
| 8341 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8343 | final long identity = Binder.clearCallingIdentity(); |
| 8344 | try { |
| 8345 | CarrierConfigManager configManager = |
| 8346 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8347 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8348 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8349 | } finally { |
| 8350 | Binder.restoreCallingIdentity(identity); |
| 8351 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8352 | } |
| 8353 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8354 | @Override |
| 8355 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8356 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8357 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8358 | } |
| 8359 | |
| 8360 | @Override |
| 8361 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8362 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8363 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8365 | final long identity = Binder.clearCallingIdentity(); |
| 8366 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8367 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8371 | } |
| 8372 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8373 | /** |
| 8374 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8375 | * support for the feature and device firmware support. |
| 8376 | * |
| 8377 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8378 | */ |
| 8379 | @Override |
| 8380 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8381 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8382 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8383 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8384 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8385 | final Phone phone = getPhone(subscriptionId); |
| 8386 | if (phone == null) { |
| 8387 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8388 | return false; |
| 8389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8390 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8391 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8393 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8394 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8395 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | return isCarrierSupported && isDeviceSupported; |
| 8397 | } finally { |
| 8398 | Binder.restoreCallingIdentity(identity); |
| 8399 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8400 | } |
| 8401 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8402 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8403 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8404 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8405 | * 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] | 8406 | */ |
| 8407 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | final long identity = Binder.clearCallingIdentity(); |
| 8409 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8410 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8411 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8412 | return false; |
| 8413 | } |
| 8414 | } |
| 8415 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8416 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8417 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8418 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8419 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8420 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8421 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8422 | } finally { |
| 8423 | Binder.restoreCallingIdentity(identity); |
| 8424 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8427 | @Deprecated |
| 8428 | @Override |
| 8429 | public String getDeviceId(String callingPackage) { |
| 8430 | return getDeviceIdWithFeature(callingPackage, null); |
| 8431 | } |
| 8432 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8433 | /** |
| 8434 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8435 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8436 | * |
| 8437 | * <p>Requires Permission: |
| 8438 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8439 | */ |
| 8440 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8441 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8442 | try { |
| 8443 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8444 | } catch (SecurityException se) { |
| 8445 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8446 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8447 | + Binder.getCallingUid()); |
| 8448 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8449 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8450 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8451 | return null; |
| 8452 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8453 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8454 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8455 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8456 | return null; |
| 8457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8458 | |
| 8459 | final long identity = Binder.clearCallingIdentity(); |
| 8460 | try { |
| 8461 | return phone.getDeviceId(); |
| 8462 | } finally { |
| 8463 | Binder.restoreCallingIdentity(identity); |
| 8464 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8465 | } |
| 8466 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8467 | /** |
| 8468 | * {@hide} |
| 8469 | * Returns the IMS Registration Status on a particular subid |
| 8470 | * |
| 8471 | * @param subId |
| 8472 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8473 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8474 | Phone phone = getPhone(subId); |
| 8475 | if (phone != null) { |
| 8476 | return phone.isImsRegistered(); |
| 8477 | } else { |
| 8478 | return false; |
| 8479 | } |
| 8480 | } |
| 8481 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8482 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8483 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8484 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8486 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8487 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8488 | } |
| 8489 | final long identity = Binder.clearCallingIdentity(); |
| 8490 | try { |
| 8491 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8492 | } finally { |
| 8493 | Binder.restoreCallingIdentity(identity); |
| 8494 | } |
| 8495 | } |
| 8496 | |
| 8497 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8498 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8499 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8500 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8501 | mApp, |
| 8502 | subscriptionId, |
| 8503 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8504 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8505 | |
| 8506 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8507 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8508 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8509 | final long identity = Binder.clearCallingIdentity(); |
| 8510 | try { |
| 8511 | Phone phone = getPhone(subscriptionId); |
| 8512 | if (phone == null) { |
| 8513 | return null; |
| 8514 | } |
| 8515 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
| 8518 | } |
| 8519 | } |
| 8520 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8521 | /** |
| 8522 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8523 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8524 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8525 | final long identity = Binder.clearCallingIdentity(); |
| 8526 | try { |
| 8527 | Phone phone = getPhone(subId); |
| 8528 | if (phone != null) { |
| 8529 | return phone.isWifiCallingEnabled(); |
| 8530 | } else { |
| 8531 | return false; |
| 8532 | } |
| 8533 | } finally { |
| 8534 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8535 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8536 | } |
| 8537 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8538 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8539 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8540 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8541 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8542 | final long identity = Binder.clearCallingIdentity(); |
| 8543 | try { |
| 8544 | Phone phone = getPhone(subId); |
| 8545 | if (phone != null) { |
| 8546 | return phone.isVideoEnabled(); |
| 8547 | } else { |
| 8548 | return false; |
| 8549 | } |
| 8550 | } finally { |
| 8551 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8552 | } |
| 8553 | } |
| 8554 | |
| 8555 | /** |
| 8556 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8557 | * defined in {@link ImsRegistrationImplBase}. |
| 8558 | */ |
| 8559 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8560 | final long identity = Binder.clearCallingIdentity(); |
| 8561 | try { |
| 8562 | Phone phone = getPhone(subId); |
| 8563 | if (phone != null) { |
| 8564 | return phone.getImsRegistrationTech(); |
| 8565 | } else { |
| 8566 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8567 | } |
| 8568 | } finally { |
| 8569 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8570 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8571 | } |
| 8572 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8573 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8574 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8575 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8576 | |
| 8577 | enforceTelephonyFeatureWithException(callingPackage, |
| 8578 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8579 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8580 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8581 | return; |
| 8582 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8583 | Phone defaultPhone = getDefaultPhone(); |
| 8584 | if (defaultPhone != null) { |
| 8585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8586 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8587 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8588 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8589 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8590 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8591 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8592 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8593 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8594 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8595 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8596 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8597 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8598 | setDataRoamingEnabled(subId, phone == null ? false |
| 8599 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8600 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8601 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8602 | // There has been issues when Sms raw table somehow stores orphan |
| 8603 | // fragments. They lead to garbled message when new fragments come |
| 8604 | // in and combined with those stale ones. In case this happens again, |
| 8605 | // user can reset all network settings which will clean up this table. |
| 8606 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8607 | // Clean up IMS settings as well here. |
| 8608 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8609 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8610 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8611 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8612 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8613 | if (defaultPhone == null) { |
| 8614 | return; |
| 8615 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8616 | // Erase modem config if erase modem on network setting is enabled. |
| 8617 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8618 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8619 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8620 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8621 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8622 | |
| 8623 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8626 | } |
| 8627 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8628 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8629 | @VisibleForTesting |
| 8630 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8631 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8632 | return; |
| 8633 | } |
| 8634 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8635 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8636 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8637 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8638 | "user=" + defaultNetworkType); |
| 8639 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8640 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8641 | defaultNetworkType, null); |
| 8642 | } |
| 8643 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8644 | private void cleanUpSmsRawTable(Context context) { |
| 8645 | ContentResolver resolver = context.getContentResolver(); |
| 8646 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8647 | resolver.delete(uri, null, null); |
| 8648 | } |
| 8649 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8650 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8651 | public String getSimLocaleForSubscriber(int subId) { |
| 8652 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8653 | |
| 8654 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8655 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8656 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8657 | final Phone phone = getPhone(subId); |
| 8658 | if (phone == null) { |
| 8659 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8660 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8661 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8662 | final long identity = Binder.clearCallingIdentity(); |
| 8663 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8664 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8665 | phone.getContext().getOpPackageName(), |
| 8666 | phone.getContext().getAttributionTag()); |
| 8667 | if (info == null) { |
| 8668 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8669 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8670 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8671 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8672 | // preferences (EF-PL and EF-LI)... |
| 8673 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8674 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8675 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8676 | if (localeFromDefaultSim != null) { |
| 8677 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8678 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8679 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8680 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8681 | } else { |
| 8682 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8683 | } |
| 8684 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8685 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8686 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8687 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8688 | // the SIM and carrier preferences does not include a country we add the country |
| 8689 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8690 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8691 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8692 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8693 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8694 | } |
| 8695 | |
| 8696 | if (DBG) log("No locale found - returning null"); |
| 8697 | return null; |
| 8698 | } finally { |
| 8699 | Binder.restoreCallingIdentity(identity); |
| 8700 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8701 | } |
| 8702 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8703 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8704 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8705 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8706 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8707 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8708 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8709 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8710 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8711 | return localeTag; |
| 8712 | } |
| 8713 | } |
| 8714 | return inputLocale.toLanguageTag(); |
| 8715 | } |
| 8716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8717 | /** |
| 8718 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8719 | */ |
| 8720 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8721 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8722 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8723 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8724 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8725 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8726 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8727 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8728 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8729 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8730 | * representing the state of the modem. |
| 8731 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8732 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8733 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8734 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8735 | */ |
| 8736 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8737 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8738 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8739 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8740 | if (!mApp.getResources().getBoolean( |
| 8741 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8742 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8743 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8744 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8745 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8746 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8747 | |
| 8748 | final long identity = Binder.clearCallingIdentity(); |
| 8749 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8750 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8753 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8754 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8755 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8756 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8757 | // less than total activity duration. |
| 8758 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8759 | if (info == null) { |
| 8760 | return false; |
| 8761 | } |
| 8762 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8763 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8764 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8765 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8766 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8767 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8768 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8769 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8770 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8771 | } |
| 8772 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8773 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8774 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8775 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8776 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8777 | |
| 8778 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8779 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8780 | } |
| 8781 | |
| 8782 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8783 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8784 | rat, |
| 8785 | freq, |
| 8786 | info.getReceiveTimeMillis(rat, freq) |
| 8787 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8788 | } |
| 8789 | |
| 8790 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8791 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8792 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8793 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8794 | |
| 8795 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8796 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8797 | } |
| 8798 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8799 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8800 | rat, |
| 8801 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8802 | } |
| 8803 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8804 | /** |
| 8805 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8806 | * @param info recent ModemActivityInfo |
| 8807 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8808 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8809 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8810 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8811 | boolean matched; |
| 8812 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8813 | matched = false; |
| 8814 | int rat = info.getSpecificInfoRat(i); |
| 8815 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8816 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8817 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8818 | //if it already exists |
| 8819 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8820 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8821 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8822 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8823 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8824 | updateLastModemActivityInfo(info, rat, freq); |
| 8825 | matched = true; |
| 8826 | } |
| 8827 | } else { |
| 8828 | updateLastModemActivityInfo(info, rat); |
| 8829 | matched = true; |
| 8830 | } |
| 8831 | } |
| 8832 | } |
| 8833 | |
| 8834 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8835 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8836 | new ActivityStatsTechSpecificInfo( |
| 8837 | rat, |
| 8838 | freq, |
| 8839 | info.getTransmitTimeMillis(rat, freq), |
| 8840 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8841 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8842 | } |
| 8843 | } |
| 8844 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8845 | mLastModemActivitySpecificInfo = |
| 8846 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8847 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8848 | |
| 8849 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8850 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8851 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8852 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8853 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8854 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8855 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8856 | |
| 8857 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8858 | new ModemActivityInfo( |
| 8859 | mLastModemActivityInfo.getTimestampMillis(), |
| 8860 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8861 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8862 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8863 | } |
| 8864 | |
| 8865 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8866 | ActivityStatsTechSpecificInfo[] info) { |
| 8867 | int infoSize = info.length; |
| 8868 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8869 | for (int i = 0; i < infoSize; i++) { |
| 8870 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8871 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8872 | info[i].getTransmitTimeMillis(), |
| 8873 | (int) info[i].getReceiveTimeMillis()); |
| 8874 | } |
| 8875 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8876 | } |
| 8877 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8878 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8879 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8880 | */ |
| 8881 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8882 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8883 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8884 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8885 | if (phone == null) { |
| 8886 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8887 | return null; |
| 8888 | } |
| 8889 | |
| 8890 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8892 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8893 | return null; |
| 8894 | } |
| 8895 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8896 | enforceTelephonyFeatureWithException(callingPackage, |
| 8897 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8898 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8899 | boolean hasFinePermission = false; |
| 8900 | boolean hasCoarsePermission = false; |
| 8901 | if (!renounceFineLocationAccess) { |
| 8902 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8903 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8904 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8905 | .setCallingPackage(callingPackage) |
| 8906 | .setCallingFeatureId(callingFeatureId) |
| 8907 | .setCallingPid(Binder.getCallingPid()) |
| 8908 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8909 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8910 | .setLogAsInfo(true) |
| 8911 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8912 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8913 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8914 | .build()); |
| 8915 | hasFinePermission = |
| 8916 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8917 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8918 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8919 | if (!renounceCoarseLocationAccess) { |
| 8920 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8921 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8922 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8923 | .setCallingPackage(callingPackage) |
| 8924 | .setCallingFeatureId(callingFeatureId) |
| 8925 | .setCallingPid(Binder.getCallingPid()) |
| 8926 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8927 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8928 | .setLogAsInfo(true) |
| 8929 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8930 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8931 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8932 | .build()); |
| 8933 | hasCoarsePermission = |
| 8934 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8935 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8936 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8937 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8938 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8939 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8940 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8941 | if (subInfo != null && !subInfo.isActive()) { |
| 8942 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8943 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8944 | } |
| 8945 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8946 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8947 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8948 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8949 | |
| 8950 | // Scrub out the location info in ServiceState depending on what level of access |
| 8951 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8952 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8953 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8954 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8955 | } finally { |
| 8956 | Binder.restoreCallingIdentity(identity); |
| 8957 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8958 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8959 | |
| 8960 | /** |
| 8961 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8962 | * |
| 8963 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8964 | * voicemail ringtone. |
| 8965 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8966 | * PhoneAccount. |
| 8967 | */ |
| 8968 | @Override |
| 8969 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8970 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8971 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8973 | final long identity = Binder.clearCallingIdentity(); |
| 8974 | try { |
| 8975 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8976 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8977 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8980 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8981 | } finally { |
| 8982 | Binder.restoreCallingIdentity(identity); |
| 8983 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8984 | } |
| 8985 | |
| 8986 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8987 | * Sets the per-account voicemail ringtone. |
| 8988 | * |
| 8989 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8990 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8991 | * |
| 8992 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8993 | * voicemail ringtone. |
| 8994 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8995 | * PhoneAccount. |
| 8996 | */ |
| 8997 | @Override |
| 8998 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8999 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9000 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9001 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9002 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9003 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9005 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9006 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9008 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9009 | enforceTelephonyFeatureWithException(callingPackage, |
| 9010 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9012 | final long identity = Binder.clearCallingIdentity(); |
| 9013 | try { |
| 9014 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9015 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9016 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9017 | } |
| 9018 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9019 | } finally { |
| 9020 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9021 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9022 | } |
| 9023 | |
| 9024 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9025 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9026 | * |
| 9027 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9028 | * voicemail vibration setting. |
| 9029 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9030 | */ |
| 9031 | @Override |
| 9032 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9033 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9034 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9035 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9036 | final long identity = Binder.clearCallingIdentity(); |
| 9037 | try { |
| 9038 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9039 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9040 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9041 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9042 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9043 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9044 | } finally { |
| 9045 | Binder.restoreCallingIdentity(identity); |
| 9046 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9047 | } |
| 9048 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9049 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9050 | * Sets the per-account voicemail vibration. |
| 9051 | * |
| 9052 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9053 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9054 | * |
| 9055 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9056 | * voicemail vibration setting. |
| 9057 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9058 | * specific PhoneAccount. |
| 9059 | */ |
| 9060 | @Override |
| 9061 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9062 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9063 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9064 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9065 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9066 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9068 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9069 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9070 | } |
| 9071 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9072 | enforceTelephonyFeatureWithException(callingPackage, |
| 9073 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9074 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9075 | final long identity = Binder.clearCallingIdentity(); |
| 9076 | try { |
| 9077 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9078 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9079 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9080 | } |
| 9081 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9082 | } finally { |
| 9083 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9084 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9085 | } |
| 9086 | |
| 9087 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9088 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9089 | * |
| 9090 | * @throws SecurityException if the caller does not have the required permission |
| 9091 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9092 | @VisibleForTesting |
| 9093 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9094 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9095 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9096 | } |
| 9097 | |
| 9098 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9099 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9100 | * permission. |
| 9101 | * |
| 9102 | * @throws SecurityException if the caller does not have the required permission |
| 9103 | */ |
| 9104 | private void enforceSendSmsPermission() { |
| 9105 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9106 | } |
| 9107 | |
| 9108 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9109 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9110 | * users permission. |
| 9111 | * |
| 9112 | * @throws SecurityException if the caller does not have the required permission |
| 9113 | */ |
| 9114 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9115 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9116 | } |
| 9117 | |
| 9118 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9119 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9120 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9121 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9122 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9123 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9124 | final long identity = Binder.clearCallingIdentity(); |
| 9125 | try { |
| 9126 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9127 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9128 | if (componentName == null) { |
| 9129 | throw new SecurityException( |
| 9130 | "Caller not current active visual voicemail package[null]"); |
| 9131 | } |
| 9132 | String vvmPackage = componentName.getPackageName(); |
| 9133 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9134 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9135 | } |
| 9136 | } finally { |
| 9137 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9138 | } |
| 9139 | } |
| 9140 | |
| 9141 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9142 | * Return the application ID for the app type. |
| 9143 | * |
| 9144 | * @param subId the subscription ID that this request applies to. |
| 9145 | * @param appType the uicc app type. |
| 9146 | * @return Application ID for specificied app type, or null if no uicc. |
| 9147 | */ |
| 9148 | @Override |
| 9149 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9150 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9151 | |
| 9152 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9153 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9154 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9155 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9156 | |
| 9157 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9158 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9159 | if (phone == null) { |
| 9160 | return null; |
| 9161 | } |
| 9162 | String aid = null; |
| 9163 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9164 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9165 | .getApplicationByType(appType).getAid(); |
| 9166 | } catch (Exception e) { |
| 9167 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9168 | } |
| 9169 | return aid; |
| 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9172 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9173 | } |
| 9174 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9175 | /** |
| 9176 | * Return the Electronic Serial Number. |
| 9177 | * |
| 9178 | * @param subId the subscription ID that this request applies to. |
| 9179 | * @return ESN or null if error. |
| 9180 | */ |
| 9181 | @Override |
| 9182 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9183 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9184 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9185 | |
| 9186 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9187 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9188 | if (phone == null) { |
| 9189 | return null; |
| 9190 | } |
| 9191 | String esn = null; |
| 9192 | try { |
| 9193 | esn = phone.getEsn(); |
| 9194 | } catch (Exception e) { |
| 9195 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9196 | } |
| 9197 | return esn; |
| 9198 | } finally { |
| 9199 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9200 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9201 | } |
| 9202 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9203 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9204 | * Return the Preferred Roaming List Version. |
| 9205 | * |
| 9206 | * @param subId the subscription ID that this request applies to. |
| 9207 | * @return PRLVersion or null if error. |
| 9208 | */ |
| 9209 | @Override |
| 9210 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9211 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9212 | |
| 9213 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9214 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9215 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9216 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9217 | |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9219 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9220 | if (phone == null) { |
| 9221 | return null; |
| 9222 | } |
| 9223 | String cdmaPrlVersion = null; |
| 9224 | try { |
| 9225 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9226 | } catch (Exception e) { |
| 9227 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9228 | } |
| 9229 | return cdmaPrlVersion; |
| 9230 | } finally { |
| 9231 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9232 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9233 | } |
| 9234 | |
| 9235 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9236 | * Get snapshot of Telephony histograms |
| 9237 | * @return List of Telephony histograms |
| 9238 | * @hide |
| 9239 | */ |
| 9240 | @Override |
| 9241 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9243 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9244 | |
| 9245 | final long identity = Binder.clearCallingIdentity(); |
| 9246 | try { |
| 9247 | return RIL.getTelephonyRILTimingHistograms(); |
| 9248 | } finally { |
| 9249 | Binder.restoreCallingIdentity(identity); |
| 9250 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9251 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9252 | |
| 9253 | /** |
| 9254 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9255 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9256 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9257 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9258 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9259 | * @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] | 9260 | */ |
| 9261 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9262 | @TelephonyManager.SetCarrierRestrictionResult |
| 9263 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9264 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9265 | |
| 9266 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9267 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9268 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9269 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9270 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9271 | if (carrierRestrictionRules == null) { |
| 9272 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9273 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9275 | final long identity = Binder.clearCallingIdentity(); |
| 9276 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9277 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9278 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9279 | } finally { |
| 9280 | Binder.restoreCallingIdentity(identity); |
| 9281 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9282 | } |
| 9283 | |
| 9284 | /** |
| 9285 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9286 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9287 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9288 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9289 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9290 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9291 | */ |
| 9292 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9293 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9294 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9295 | |
| 9296 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9297 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9298 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9299 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9300 | |
| 9301 | final long identity = Binder.clearCallingIdentity(); |
| 9302 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9303 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9304 | if (response instanceof CarrierRestrictionRules) { |
| 9305 | return (CarrierRestrictionRules) response; |
| 9306 | } |
| 9307 | // Response is an Exception of some kind, |
| 9308 | // which is signalled to the user as a NULL retval |
| 9309 | return null; |
| 9310 | } catch (Exception e) { |
| 9311 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9312 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9313 | } finally { |
| 9314 | Binder.restoreCallingIdentity(identity); |
| 9315 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9316 | } |
| 9317 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9318 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9319 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9320 | * through the callback. |
| 9321 | * |
| 9322 | * @param callback The callback that will be used to send the result. |
| 9323 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9324 | * the caller is not allowlisted. |
| 9325 | */ |
| 9326 | @Override |
| 9327 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9328 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9329 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9330 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9331 | try { |
| 9332 | mApp.enforceCallingOrSelfPermission( |
| 9333 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9334 | functionName); |
| 9335 | } catch (SecurityException e) { |
| 9336 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9337 | functionName); |
| 9338 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9339 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9340 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9341 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9342 | throw new SecurityException("Not an authorized caller"); |
| 9343 | } |
| 9344 | final long identity = Binder.clearCallingIdentity(); |
| 9345 | try { |
| 9346 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9347 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9348 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9349 | } finally { |
| 9350 | Binder.restoreCallingIdentity(identity); |
| 9351 | } |
| 9352 | } |
| 9353 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9354 | @Override |
| 9355 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9356 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9357 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9358 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9359 | } |
| 9360 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9361 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9362 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9363 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9364 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9368 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9369 | * @param subId the subscription ID that this action applies to. |
| 9370 | * @param enabled control enable or disable radio. |
| 9371 | * {@hide} |
| 9372 | */ |
| 9373 | @Override |
| 9374 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9375 | enforceModifyPermission(); |
| 9376 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9377 | |
| 9378 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9379 | if (phone == null) { |
| 9380 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9381 | return; |
| 9382 | } |
| 9383 | try { |
| 9384 | phone.carrierActionSetRadioEnabled(enabled); |
| 9385 | } catch (Exception e) { |
| 9386 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9389 | } |
| 9390 | } |
| 9391 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9392 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9393 | * Enable or disable Voice over NR (VoNR) |
| 9394 | * @param subId the subscription ID that this action applies to. |
| 9395 | * @param enabled enable or disable VoNR. |
| 9396 | * @return operation result. |
| 9397 | */ |
| 9398 | @Override |
| 9399 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9400 | enforceModifyPermission(); |
| 9401 | final Phone phone = getPhone(subId); |
| 9402 | |
| 9403 | final long identity = Binder.clearCallingIdentity(); |
| 9404 | if (phone == null) { |
| 9405 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9406 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9407 | } |
| 9408 | |
| 9409 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9410 | try { |
| 9411 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9412 | workSource); |
| 9413 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9414 | |
| 9415 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9416 | if (DBG) { |
| 9417 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9418 | } |
| 9419 | SubscriptionManager.setSubscriptionProperty( |
| 9420 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9421 | (enabled ? "1" : "0")); |
| 9422 | } |
| 9423 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9424 | return result; |
| 9425 | } finally { |
| 9426 | Binder.restoreCallingIdentity(identity); |
| 9427 | } |
| 9428 | } |
| 9429 | |
| 9430 | /** |
| 9431 | * Is voice over NR enabled |
| 9432 | * @return true if VoNR is enabled else false |
| 9433 | */ |
| 9434 | @Override |
| 9435 | public boolean isVoNrEnabled(int subId) { |
| 9436 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9437 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9438 | final long identity = Binder.clearCallingIdentity(); |
| 9439 | try { |
| 9440 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9441 | null, subId, workSource); |
| 9442 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9443 | return isEnabled; |
| 9444 | } finally { |
| 9445 | Binder.restoreCallingIdentity(identity); |
| 9446 | } |
| 9447 | } |
| 9448 | |
| 9449 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9450 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9451 | * network status based on which carrier apps could apply actions accordingly, |
| 9452 | * enable/disable default url handler for example. |
| 9453 | * |
| 9454 | * @param subId the subscription ID that this action applies to. |
| 9455 | * @param report control start/stop reporting the default network status. |
| 9456 | * {@hide} |
| 9457 | */ |
| 9458 | @Override |
| 9459 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9460 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9461 | |
| 9462 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9463 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9464 | "carrierActionReportDefaultNetworkStatus"); |
| 9465 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9466 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9467 | |
| 9468 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9469 | if (phone == null) { |
| 9470 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9471 | return; |
| 9472 | } |
| 9473 | try { |
| 9474 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9475 | } catch (Exception e) { |
| 9476 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9477 | } finally { |
| 9478 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9479 | } |
| 9480 | } |
| 9481 | |
| 9482 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9483 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9484 | * @param subId the subscription ID that this action applies to. |
| 9485 | * {@hide} |
| 9486 | */ |
| 9487 | @Override |
| 9488 | public void carrierActionResetAll(int subId) { |
| 9489 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9490 | |
| 9491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9492 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9493 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9494 | final Phone phone = getPhone(subId); |
| 9495 | if (phone == null) { |
| 9496 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9497 | return; |
| 9498 | } |
| 9499 | try { |
| 9500 | phone.carrierActionResetAll(); |
| 9501 | } catch (Exception e) { |
| 9502 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9503 | } |
| 9504 | } |
| 9505 | |
| 9506 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9507 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9508 | * bug report is being generated. |
| 9509 | */ |
| 9510 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9511 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9512 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9513 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9514 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9515 | + Binder.getCallingPid() |
| 9516 | + ", uid=" + Binder.getCallingUid() |
| 9517 | + "without permission " |
| 9518 | + android.Manifest.permission.DUMP); |
| 9519 | return; |
| 9520 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9521 | try { |
| 9522 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9523 | } catch (Exception e) { |
| 9524 | writer.println("Failed to dump phone information: " + e); |
| 9525 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9526 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9527 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9528 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9529 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9530 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9531 | @NonNull String[] args) { |
| 9532 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9533 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9534 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9535 | } |
| 9536 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9537 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9538 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9539 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9540 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9541 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9542 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9543 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9544 | */ |
| 9545 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9546 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9547 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9548 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9549 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9550 | try { |
| 9551 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9552 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9553 | } catch (SecurityException se) { |
| 9554 | enforceModifyPermission(); |
| 9555 | } |
| 9556 | } else { |
| 9557 | enforceModifyPermission(); |
| 9558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9559 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9560 | enforceTelephonyFeatureWithException(callingPackage, |
| 9561 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9562 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9563 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9564 | final long identity = Binder.clearCallingIdentity(); |
| 9565 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9566 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9567 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9568 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9569 | callingUid, callingPackage, null, null); |
| 9570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9571 | Phone phone = getPhone(subId); |
| 9572 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9573 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9574 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9575 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9576 | phone.getDataSettingsManager().setDataEnabled( |
| 9577 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9579 | } |
| 9580 | } finally { |
| 9581 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9582 | } |
| 9583 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9584 | |
| 9585 | /** |
| 9586 | * Get Client request stats |
| 9587 | * @return List of Client Request Stats |
| 9588 | * @hide |
| 9589 | */ |
| 9590 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9591 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9592 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9593 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9594 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9595 | return null; |
| 9596 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9597 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
| 9601 | if (phone != null) { |
| 9602 | return phone.getClientRequestStats(); |
| 9603 | } |
| 9604 | |
| 9605 | return null; |
| 9606 | } finally { |
| 9607 | Binder.restoreCallingIdentity(identity); |
| 9608 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9609 | } |
| 9610 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9611 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9612 | PackageManager pm; |
| 9613 | if (mFeatureFlags.hsumPackageManager()) { |
| 9614 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9615 | .getPackageManager(); |
| 9616 | } else { |
| 9617 | pm = mApp.getPackageManager(); |
| 9618 | } |
| 9619 | |
| 9620 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9621 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9622 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9623 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9624 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9625 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9626 | // commands that plumb through the RIL as root, like so: |
| 9627 | // $ adb root |
| 9628 | // $ adb shell cmd phone ... |
| 9629 | packageName = "root"; |
| 9630 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9631 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9632 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9633 | |
| 9634 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9635 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9636 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9637 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9638 | * @param state State of SIM (power down, power up, pass through) |
| 9639 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9640 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9641 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9642 | * |
| 9643 | **/ |
| 9644 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9645 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9646 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9647 | |
| 9648 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9649 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9650 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9651 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9652 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9653 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9654 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9655 | final long identity = Binder.clearCallingIdentity(); |
| 9656 | try { |
| 9657 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9658 | phone.setSimPowerState(state, null, workSource); |
| 9659 | } |
| 9660 | } finally { |
| 9661 | Binder.restoreCallingIdentity(identity); |
| 9662 | } |
| 9663 | } |
| 9664 | |
| 9665 | /** |
| 9666 | * Set SIM card power state. |
| 9667 | * |
| 9668 | * @param slotIndex SIM slot id. |
| 9669 | * @param state State of SIM (power down, power up, pass through) |
| 9670 | * @param callback callback to trigger after success or failure |
| 9671 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9672 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9673 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9674 | * |
| 9675 | **/ |
| 9676 | @Override |
| 9677 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9678 | IIntegerConsumer callback) { |
| 9679 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9680 | |
| 9681 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9682 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9683 | "setSimPowerStateForSlotWithCallback"); |
| 9684 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9685 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9686 | |
| 9687 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9688 | |
| 9689 | final long identity = Binder.clearCallingIdentity(); |
| 9690 | try { |
| 9691 | if (phone != null) { |
| 9692 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9693 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9694 | } |
| 9695 | } finally { |
| 9696 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9697 | } |
| 9698 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9699 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9700 | private boolean isUssdApiAllowed(int subId) { |
| 9701 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9702 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9703 | if (configManager == null) { |
| 9704 | return false; |
| 9705 | } |
| 9706 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9707 | if (pb == null) { |
| 9708 | return false; |
| 9709 | } |
| 9710 | return pb.getBoolean( |
| 9711 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9712 | } |
| 9713 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9714 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9715 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9716 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9717 | * @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] | 9718 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9719 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9720 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9721 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9722 | |
| 9723 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9724 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9726 | final long identity = Binder.clearCallingIdentity(); |
| 9727 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9728 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9731 | } |
| 9732 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9733 | |
| 9734 | /** |
| 9735 | * Get the current signal strength information for the given subscription. |
| 9736 | * Because this information is not updated when the device is in a low power state |
| 9737 | * it should not be relied-upon to be current. |
| 9738 | * @param subId Subscription index |
| 9739 | * @return the most recent cached signal strength info from the modem |
| 9740 | */ |
| 9741 | @Override |
| 9742 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9743 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9744 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9746 | final long identity = Binder.clearCallingIdentity(); |
| 9747 | try { |
| 9748 | Phone p = getPhone(subId); |
| 9749 | if (p == null) { |
| 9750 | return null; |
| 9751 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9753 | return p.getSignalStrength(); |
| 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
| 9756 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9757 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9758 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9759 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9760 | * Get the current modem radio state for the given slot. |
| 9761 | * @param slotIndex slot index. |
| 9762 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9763 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9764 | * @return the current radio power state from the modem |
| 9765 | */ |
| 9766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9767 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9768 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9769 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9770 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9771 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9772 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9773 | } |
| 9774 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9775 | enforceTelephonyFeatureWithException(callingPackage, |
| 9776 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9777 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9778 | final long identity = Binder.clearCallingIdentity(); |
| 9779 | try { |
| 9780 | return phone.getRadioPowerState(); |
| 9781 | } finally { |
| 9782 | Binder.restoreCallingIdentity(identity); |
| 9783 | } |
| 9784 | } |
| 9785 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9786 | } |
| 9787 | |
| 9788 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9789 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9790 | * |
| 9791 | * <p>Requires one of the following permissions: |
| 9792 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9793 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9794 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9795 | * privileges. |
| 9796 | * |
| 9797 | * @param subId subscription id |
| 9798 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9799 | * {@code false}. |
| 9800 | */ |
| 9801 | @Override |
| 9802 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9803 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9804 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9805 | try { |
| 9806 | mApp.enforceCallingOrSelfPermission( |
| 9807 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9808 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9809 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9810 | mApp.enforceCallingOrSelfPermission( |
| 9811 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9812 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9813 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9814 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9815 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9816 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9817 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9818 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9819 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9820 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9821 | boolean isEnabled = false; |
| 9822 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9823 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9824 | Phone phone = getPhone(subId); |
| 9825 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9826 | } finally { |
| 9827 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9828 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9829 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9830 | } |
| 9831 | |
| 9832 | |
| 9833 | /** |
| 9834 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9835 | * |
| 9836 | * <p> Requires permission: |
| 9837 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9838 | * privileges. |
| 9839 | * |
| 9840 | * @param subId subscription id |
| 9841 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9842 | */ |
| 9843 | @Override |
| 9844 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9846 | mApp, subId, "setDataRoamingEnabled"); |
| 9847 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9848 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9849 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9850 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9851 | final long identity = Binder.clearCallingIdentity(); |
| 9852 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9853 | Phone phone = getPhone(subId); |
| 9854 | if (phone != null) { |
| 9855 | phone.setDataRoamingEnabled(isEnabled); |
| 9856 | } |
| 9857 | } finally { |
| 9858 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9859 | } |
| 9860 | } |
| 9861 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9862 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9863 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9864 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9865 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9866 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9867 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9868 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9869 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9870 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9871 | boolean isAllowed = true; |
| 9872 | final long identity = Binder.clearCallingIdentity(); |
| 9873 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9874 | Phone phone = getPhone(subId); |
| 9875 | if (phone != null) { |
| 9876 | isAllowed = phone.isCspPlmnEnabled(); |
| 9877 | } |
| 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | return isAllowed; |
| 9882 | } |
| 9883 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9884 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9885 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9886 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9887 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9888 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9889 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9890 | if (phone == null) { |
| 9891 | return false; |
| 9892 | } |
| 9893 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9894 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9895 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9896 | } |
| 9897 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9898 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9899 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9900 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9901 | mApp.getSystemService(AppOpsManager.class) |
| 9902 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9903 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9904 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9905 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9906 | try { |
| 9907 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9908 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9909 | } catch (SecurityException e) { |
| 9910 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9911 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9912 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9913 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9914 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9915 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9916 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9917 | |
| 9918 | enforceTelephonyFeatureWithException(callingPackage, |
| 9919 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9920 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9921 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9922 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9923 | Binder.getCallingUid())) { |
| 9924 | isIccIdAccessRestricted = true; |
| 9925 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9926 | final long identity = Binder.clearCallingIdentity(); |
| 9927 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9928 | UiccController uiccController = UiccController.getInstance(); |
| 9929 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9930 | if (hasReadPermission) { |
| 9931 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9932 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9933 | |
| 9934 | // Remove private info if the caller doesn't have access |
| 9935 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9936 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9937 | //setting the value after compatibility check |
| 9938 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9939 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9940 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9941 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9942 | if (card == null) { |
| 9943 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9944 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9945 | continue; |
| 9946 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9947 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9948 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9949 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9950 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9951 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9952 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9953 | for (UiccPortInfo portInfo : portInfos) { |
| 9954 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9955 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9956 | if (port == null) { |
| 9957 | // assume no access if port is null |
| 9958 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9959 | continue; |
| 9960 | } |
| 9961 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9962 | uiccPortInfos.add(portInfo); |
| 9963 | } else { |
| 9964 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9965 | } |
| 9966 | } |
| 9967 | filteredInfos.add(new UiccCardInfo( |
| 9968 | cardInfo.isEuicc(), |
| 9969 | cardInfo.getCardId(), |
| 9970 | null, |
| 9971 | cardInfo.getPhysicalSlotIndex(), |
| 9972 | cardInfo.isRemovable(), |
| 9973 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9974 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9975 | } |
| 9976 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9977 | } finally { |
| 9978 | Binder.restoreCallingIdentity(identity); |
| 9979 | } |
| 9980 | } |
| 9981 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9982 | /** |
| 9983 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9984 | * generally private and require carrier privileges to view. |
| 9985 | * |
| 9986 | * @hide |
| 9987 | */ |
| 9988 | @NonNull |
| 9989 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9990 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9991 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9992 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9993 | } |
| 9994 | return new UiccCardInfo( |
| 9995 | cardInfo.isEuicc(), |
| 9996 | cardInfo.getCardId(), |
| 9997 | null, |
| 9998 | cardInfo.getPhysicalSlotIndex(), |
| 9999 | cardInfo.isRemovable(), |
| 10000 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10001 | portinfo |
| 10002 | ); |
| 10003 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10004 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10005 | /** |
| 10006 | * @hide |
| 10007 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10008 | * These values are generally private and require carrier privileges to view. |
| 10009 | */ |
| 10010 | @NonNull |
| 10011 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10012 | return new UiccPortInfo( |
| 10013 | UiccPortInfo.ICCID_REDACTED, |
| 10014 | portInfo.getPortIndex(), |
| 10015 | portInfo.getLogicalSlotIndex(), |
| 10016 | portInfo.isActive() |
| 10017 | ); |
| 10018 | } |
| 10019 | @Override |
| 10020 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10021 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10022 | mApp.getSystemService(AppOpsManager.class) |
| 10023 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10024 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10025 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10026 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10027 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10028 | // we are reading iccId which is PII data. |
| 10029 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10030 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10031 | enforceTelephonyFeatureWithException(callingPackage, |
| 10032 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10033 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10034 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10035 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10036 | Binder.getCallingUid())) { |
| 10037 | isLogicalSlotAccessRestricted = true; |
| 10038 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10039 | final long identity = Binder.clearCallingIdentity(); |
| 10040 | try { |
| 10041 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10042 | if (slots == null || slots.length == 0) { |
| 10043 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10044 | return null; |
| 10045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10046 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10047 | for (int i = 0; i < slots.length; i++) { |
| 10048 | UiccSlot slot = slots[i]; |
| 10049 | if (slot == null) { |
| 10050 | continue; |
| 10051 | } |
| 10052 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10053 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10054 | UiccCard card = slot.getUiccCard(); |
| 10055 | if (card != null) { |
| 10056 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10057 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10058 | cardId = slot.getEid(); |
| 10059 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10060 | // If cardId is null, use iccId of default port as cardId. |
| 10061 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10062 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10063 | } |
| 10064 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10065 | if (cardId != null) { |
| 10066 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10067 | // if cardId is an EID, it's all digits so this is fine |
| 10068 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10069 | } |
| 10070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10071 | int cardState = 0; |
| 10072 | switch (slot.getCardState()) { |
| 10073 | case CARDSTATE_ABSENT: |
| 10074 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10075 | break; |
| 10076 | case CARDSTATE_PRESENT: |
| 10077 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10078 | break; |
| 10079 | case CARDSTATE_ERROR: |
| 10080 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10081 | break; |
| 10082 | case CARDSTATE_RESTRICTED: |
| 10083 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10084 | break; |
| 10085 | default: |
| 10086 | break; |
| 10087 | |
| 10088 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10089 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10090 | int[] portIndexes = slot.getPortList(); |
| 10091 | for (int portIdx : portIndexes) { |
| 10092 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10093 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10094 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10095 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10096 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10097 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10098 | slot.isEuicc(), |
| 10099 | cardId, |
| 10100 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10101 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10102 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10103 | //setting the value after compatibility check |
| 10104 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10105 | } |
| 10106 | return infos; |
| 10107 | } finally { |
| 10108 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10109 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10110 | } |
| 10111 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10112 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10113 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10114 | boolean hasReadPermission) { |
| 10115 | String iccId = slot.getIccId(portIndex); |
| 10116 | if (hasReadPermission) { // if has read permission |
| 10117 | return iccId; |
| 10118 | } else { |
| 10119 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10120 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10121 | // if no read permission, checking carrier privilege access |
| 10122 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10123 | return iccId; |
| 10124 | } |
| 10125 | } |
| 10126 | } |
| 10127 | // No read permission or carrier privilege access. |
| 10128 | return UiccPortInfo.ICCID_REDACTED; |
| 10129 | } |
| 10130 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10131 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10132 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10133 | public boolean switchSlots(int[] physicalSlots) { |
| 10134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10135 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10136 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10137 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10139 | final long identity = Binder.clearCallingIdentity(); |
| 10140 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10141 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10142 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10143 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10144 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10145 | physicalSlots[i], i)); |
| 10146 | } |
| 10147 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10148 | } finally { |
| 10149 | Binder.restoreCallingIdentity(identity); |
| 10150 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10151 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10152 | |
| 10153 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10154 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10155 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10156 | enforceModifyPermission(); |
| 10157 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10159 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10160 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10161 | final long identity = Binder.clearCallingIdentity(); |
| 10162 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10163 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
| 10168 | |
| 10169 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10170 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10171 | enforceTelephonyFeatureWithException(callingPackage, |
| 10172 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10173 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10174 | final long identity = Binder.clearCallingIdentity(); |
| 10175 | try { |
| 10176 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10177 | } finally { |
| 10178 | Binder.restoreCallingIdentity(identity); |
| 10179 | } |
| 10180 | } |
| 10181 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10182 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10183 | * A test API to reload the UICC profile. |
| 10184 | * |
| 10185 | * <p>Requires that the calling app has permission |
| 10186 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10187 | * @hide |
| 10188 | */ |
| 10189 | @Override |
| 10190 | public void refreshUiccProfile(int subId) { |
| 10191 | enforceModifyPermission(); |
| 10192 | |
| 10193 | final long identity = Binder.clearCallingIdentity(); |
| 10194 | try { |
| 10195 | Phone phone = getPhone(subId); |
| 10196 | if (phone == null) { |
| 10197 | return; |
| 10198 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10199 | UiccPort uiccPort = phone.getUiccPort(); |
| 10200 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10201 | return; |
| 10202 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10203 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10204 | if (uiccProfile == null) { |
| 10205 | return; |
| 10206 | } |
| 10207 | uiccProfile.refresh(); |
| 10208 | } finally { |
| 10209 | Binder.restoreCallingIdentity(identity); |
| 10210 | } |
| 10211 | } |
| 10212 | |
| 10213 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10214 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10215 | */ |
| 10216 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10217 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10218 | } |
| 10219 | |
| 10220 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10221 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10222 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10223 | */ |
| 10224 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10225 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10226 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10227 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10228 | return list.get(phoneId); |
| 10229 | } |
| 10230 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10231 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10232 | |
| 10233 | @Override |
| 10234 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10235 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10236 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10237 | |
| 10238 | final long identity = Binder.clearCallingIdentity(); |
| 10239 | try { |
| 10240 | final Phone phone = getPhone(subId); |
| 10241 | if (phone == null) { |
| 10242 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10243 | return; |
| 10244 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10245 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10246 | if (cpt != null) { |
| 10247 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10248 | } |
| 10249 | // 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] | 10250 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10251 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10252 | if (carrierPrivilegeRules == null) { |
| 10253 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10254 | } else { |
| 10255 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10256 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10257 | } finally { |
| 10258 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10259 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10260 | } |
| 10261 | |
| 10262 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10263 | public void setCarrierServicePackageOverride( |
| 10264 | int subId, String carrierServicePackage, String callingPackage) { |
| 10265 | TelephonyPermissions.enforceShellOnly( |
| 10266 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10267 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10268 | final long identity = Binder.clearCallingIdentity(); |
| 10269 | try { |
| 10270 | final Phone phone = getPhone(subId); |
| 10271 | if (phone == null || phone.getSubId() != subId) { |
| 10272 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10273 | throw new IllegalArgumentException("No phone for subid"); |
| 10274 | } |
| 10275 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10276 | if (cpt == null) { |
| 10277 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10278 | throw new IllegalStateException("No CPT for phone"); |
| 10279 | } |
| 10280 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10281 | } finally { |
| 10282 | Binder.restoreCallingIdentity(identity); |
| 10283 | } |
| 10284 | } |
| 10285 | |
| 10286 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10287 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10288 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10289 | |
| 10290 | final long identity = Binder.clearCallingIdentity(); |
| 10291 | try { |
| 10292 | final Phone phone = getPhone(subId); |
| 10293 | if (phone == null) { |
| 10294 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10295 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10296 | } |
| 10297 | return phone.getCarrierIdListVersion(); |
| 10298 | } finally { |
| 10299 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10300 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10301 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10302 | |
| 10303 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10304 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10305 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10306 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10307 | mApp, subId, callingPackage, callingFeatureId, |
| 10308 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10309 | return -1; |
| 10310 | } |
| 10311 | |
| 10312 | final long identity = Binder.clearCallingIdentity(); |
| 10313 | try { |
| 10314 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10315 | } finally { |
| 10316 | Binder.restoreCallingIdentity(identity); |
| 10317 | } |
| 10318 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10319 | |
| 10320 | @Override |
| 10321 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10322 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10323 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10324 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10325 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10326 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10327 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10328 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10329 | final long identity = Binder.clearCallingIdentity(); |
| 10330 | try { |
| 10331 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10332 | } finally { |
| 10333 | Binder.restoreCallingIdentity(identity); |
| 10334 | } |
| 10335 | } |
| 10336 | |
| 10337 | @Override |
| 10338 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10340 | mApp, subId, "setCdmaRoamingMode"); |
| 10341 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10342 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10343 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10344 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10345 | final long identity = Binder.clearCallingIdentity(); |
| 10346 | try { |
| 10347 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10348 | } finally { |
| 10349 | Binder.restoreCallingIdentity(identity); |
| 10350 | } |
| 10351 | } |
| 10352 | |
| 10353 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10354 | public int getCdmaSubscriptionMode(int subId) { |
| 10355 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10356 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10357 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10358 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10359 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10360 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10361 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10362 | final long identity = Binder.clearCallingIdentity(); |
| 10363 | try { |
| 10364 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10365 | } finally { |
| 10366 | Binder.restoreCallingIdentity(identity); |
| 10367 | } |
| 10368 | } |
| 10369 | |
| 10370 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10371 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10373 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10374 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10375 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10376 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10377 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10378 | final long identity = Binder.clearCallingIdentity(); |
| 10379 | try { |
| 10380 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10381 | } finally { |
| 10382 | Binder.restoreCallingIdentity(identity); |
| 10383 | } |
| 10384 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10385 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10386 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10387 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10388 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10390 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10391 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10392 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10393 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10394 | |
| 10395 | enforceTelephonyFeatureWithException(callingPackage, |
| 10396 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10397 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10398 | final long identity = Binder.clearCallingIdentity(); |
| 10399 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10400 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10401 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10402 | if (phone.getEmergencyNumberTracker() != null |
| 10403 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10404 | emergencyNumberListInternal.put( |
| 10405 | phone.getSubId(), |
| 10406 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10407 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10408 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10409 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10410 | } finally { |
| 10411 | Binder.restoreCallingIdentity(identity); |
| 10412 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10413 | } |
| 10414 | |
| 10415 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10416 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10417 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10418 | if (!exactMatch) { |
| 10419 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10420 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10421 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10422 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10423 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10424 | if (!mApp.getResources().getBoolean( |
| 10425 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10426 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10427 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10428 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10429 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10430 | final long identity = Binder.clearCallingIdentity(); |
| 10431 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10432 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10433 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10434 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10435 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10436 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10437 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10438 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10439 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10440 | } |
| 10441 | return false; |
| 10442 | } finally { |
| 10443 | Binder.restoreCallingIdentity(identity); |
| 10444 | } |
| 10445 | } |
| 10446 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10447 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10448 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10449 | */ |
| 10450 | @Override |
| 10451 | public void startEmergencyCallbackMode() { |
| 10452 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10453 | "startEmergencyCallbackMode"); |
| 10454 | enforceModifyPermission(); |
| 10455 | final long identity = Binder.clearCallingIdentity(); |
| 10456 | try { |
| 10457 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10458 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10459 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10460 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10461 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10462 | gsmCdmaPhone.obtainMessage( |
| 10463 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10464 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10465 | } |
| 10466 | } |
| 10467 | } finally { |
| 10468 | Binder.restoreCallingIdentity(identity); |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10473 | * Update emergency number list for test mode. |
| 10474 | */ |
| 10475 | @Override |
| 10476 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10477 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10478 | "updateEmergencyNumberListTestMode"); |
| 10479 | |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
| 10482 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10483 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10484 | if (tracker != null) { |
| 10485 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10486 | } |
| 10487 | } |
| 10488 | } finally { |
| 10489 | Binder.restoreCallingIdentity(identity); |
| 10490 | } |
| 10491 | } |
| 10492 | |
| 10493 | /** |
| 10494 | * Get the full emergency number list for test mode. |
| 10495 | */ |
| 10496 | @Override |
| 10497 | public List<String> getEmergencyNumberListTestMode() { |
| 10498 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10499 | "getEmergencyNumberListTestMode"); |
| 10500 | |
| 10501 | final long identity = Binder.clearCallingIdentity(); |
| 10502 | try { |
| 10503 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10504 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10505 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10506 | if (tracker != null) { |
| 10507 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10508 | emergencyNumbers.add(num.getNumber()); |
| 10509 | } |
| 10510 | } |
| 10511 | } |
| 10512 | return new ArrayList<>(emergencyNumbers); |
| 10513 | } finally { |
| 10514 | Binder.restoreCallingIdentity(identity); |
| 10515 | } |
| 10516 | } |
| 10517 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10518 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10519 | public int getEmergencyNumberDbVersion(int subId) { |
| 10520 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10521 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10522 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10523 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10524 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10525 | final long identity = Binder.clearCallingIdentity(); |
| 10526 | try { |
| 10527 | final Phone phone = getPhone(subId); |
| 10528 | if (phone == null) { |
| 10529 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10530 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10531 | } |
| 10532 | return phone.getEmergencyNumberDbVersion(); |
| 10533 | } finally { |
| 10534 | Binder.restoreCallingIdentity(identity); |
| 10535 | } |
| 10536 | } |
| 10537 | |
| 10538 | @Override |
| 10539 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10540 | enforceModifyPermission(); |
| 10541 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10542 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10543 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10544 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10545 | final long identity = Binder.clearCallingIdentity(); |
| 10546 | try { |
| 10547 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10548 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10549 | if (tracker != null) { |
| 10550 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10551 | } |
| 10552 | } |
| 10553 | } finally { |
| 10554 | Binder.restoreCallingIdentity(identity); |
| 10555 | } |
| 10556 | } |
| 10557 | |
| 10558 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10559 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10560 | enforceActiveEmergencySessionPermission(); |
| 10561 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10562 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10563 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10564 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10565 | final long identity = Binder.clearCallingIdentity(); |
| 10566 | try { |
| 10567 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10568 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10569 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10570 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10571 | } |
| 10572 | } |
| 10573 | } finally { |
| 10574 | Binder.restoreCallingIdentity(identity); |
| 10575 | } |
| 10576 | } |
| 10577 | |
| 10578 | @Override |
| 10579 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10580 | enforceActiveEmergencySessionPermission(); |
| 10581 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10582 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10583 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10584 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10585 | final long identity = Binder.clearCallingIdentity(); |
| 10586 | try { |
| 10587 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10588 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10589 | if (tracker != null) { |
| 10590 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10591 | } |
| 10592 | } |
| 10593 | } finally { |
| 10594 | Binder.restoreCallingIdentity(identity); |
| 10595 | } |
| 10596 | } |
| 10597 | |
| 10598 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10599 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10600 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10601 | Phone phone = getPhone(subId); |
| 10602 | if (phone == null) { |
| 10603 | return null; |
| 10604 | } |
| 10605 | final long identity = Binder.clearCallingIdentity(); |
| 10606 | try { |
| 10607 | UiccProfile profile = UiccController.getInstance() |
| 10608 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10609 | if (profile != null) { |
| 10610 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10611 | } |
| 10612 | } finally { |
| 10613 | Binder.restoreCallingIdentity(identity); |
| 10614 | } |
| 10615 | return null; |
| 10616 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10617 | |
| 10618 | /** |
| 10619 | * Enable or disable a modem stack. |
| 10620 | */ |
| 10621 | @Override |
| 10622 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10623 | enforceModifyPermission(); |
| 10624 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10625 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10626 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10627 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10628 | final long identity = Binder.clearCallingIdentity(); |
| 10629 | try { |
| 10630 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10631 | if (phone == null) { |
| 10632 | return false; |
| 10633 | } else { |
| 10634 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10635 | } |
| 10636 | } finally { |
| 10637 | Binder.restoreCallingIdentity(identity); |
| 10638 | } |
| 10639 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10640 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10641 | /** |
| 10642 | * Whether a modem stack is enabled or not. |
| 10643 | */ |
| 10644 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10645 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10646 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10647 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10648 | if (phone == null) return false; |
| 10649 | |
| 10650 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10651 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10652 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10653 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10654 | } |
| 10655 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10656 | enforceTelephonyFeatureWithException(callingPackage, |
| 10657 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10658 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10659 | final long identity = Binder.clearCallingIdentity(); |
| 10660 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10661 | try { |
| 10662 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10663 | } catch (NoSuchElementException ex) { |
| 10664 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10665 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10666 | } finally { |
| 10667 | Binder.restoreCallingIdentity(identity); |
| 10668 | } |
| 10669 | } |
| 10670 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10671 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10672 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10673 | enforceModifyPermission(); |
| 10674 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10675 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10676 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10677 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10678 | final long identity = Binder.clearCallingIdentity(); |
| 10679 | try { |
| 10680 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10681 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10682 | .commit(); |
| 10683 | } finally { |
| 10684 | Binder.restoreCallingIdentity(identity); |
| 10685 | } |
| 10686 | } |
| 10687 | |
| 10688 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10689 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10690 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10691 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10692 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10693 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10694 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10695 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10696 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10697 | enforceTelephonyFeatureWithException(callingPackage, |
| 10698 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10699 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10700 | final long identity = Binder.clearCallingIdentity(); |
| 10701 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10702 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10703 | } finally { |
| 10704 | Binder.restoreCallingIdentity(identity); |
| 10705 | } |
| 10706 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10707 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10708 | @TelephonyManager.IsMultiSimSupportedResult |
| 10709 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10710 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10711 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10712 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10713 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10714 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10715 | } |
| 10716 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10717 | // supported by the modem, indicate that it is restricted. |
| 10718 | PhoneCapability staticCapability = |
| 10719 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10720 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10721 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10722 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10723 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10724 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10725 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10726 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10727 | } |
| 10728 | // Check if support of multiple SIMs is restricted by carrier |
| 10729 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10730 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10731 | } |
| 10732 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10733 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10734 | } |
| 10735 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10736 | /** |
| 10737 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10738 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10739 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10740 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10741 | * @param numOfSims number of active sims we want to switch to |
| 10742 | */ |
| 10743 | @Override |
| 10744 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10745 | if (numOfSims == 1) { |
| 10746 | enforceModifyPermission(); |
| 10747 | } else { |
| 10748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10749 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10750 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10751 | |
| 10752 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10753 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10754 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10755 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10756 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10757 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10758 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10759 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10760 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10761 | return; |
| 10762 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10763 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10764 | } finally { |
| 10765 | Binder.restoreCallingIdentity(identity); |
| 10766 | } |
| 10767 | } |
| 10768 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10769 | @Override |
| 10770 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10771 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10772 | |
| 10773 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10774 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10775 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10776 | Phone phone = getPhone(subId); |
| 10777 | if (phone == null) { |
| 10778 | return false; |
| 10779 | } |
| 10780 | final long identity = Binder.clearCallingIdentity(); |
| 10781 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10782 | UiccPort uiccPort = phone.getUiccPort(); |
| 10783 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10784 | return false; |
| 10785 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10786 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10787 | if (uiccProfile == null) { |
| 10788 | return false; |
| 10789 | } |
| 10790 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10791 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10792 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10793 | } |
| 10794 | return false; |
| 10795 | } finally { |
| 10796 | Binder.restoreCallingIdentity(identity); |
| 10797 | } |
| 10798 | } |
| 10799 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10800 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10801 | * Get whether making changes to modem configurations will trigger reboot. |
| 10802 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10803 | */ |
| 10804 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10805 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10806 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10807 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10808 | mApp, subId, callingPackage, callingFeatureId, |
| 10809 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10810 | return false; |
| 10811 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10812 | |
| 10813 | enforceTelephonyFeatureWithException(callingPackage, |
| 10814 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10815 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10816 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10817 | final long identity = Binder.clearCallingIdentity(); |
| 10818 | try { |
| 10819 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10820 | } finally { |
| 10821 | Binder.restoreCallingIdentity(identity); |
| 10822 | } |
| 10823 | } |
| 10824 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10825 | private void updateModemStateMetrics() { |
| 10826 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10827 | // TODO: check the state for each modem if the api is ready. |
| 10828 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10829 | } |
| 10830 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10831 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10832 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10833 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10834 | // Verify that the callingPackage belongs to the calling UID |
| 10835 | mApp.getSystemService(AppOpsManager.class) |
| 10836 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10837 | |
| 10838 | enforceTelephonyFeatureWithException(callingPackage, |
| 10839 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10840 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10841 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10842 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10843 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10844 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10845 | if (slotInfos != null) { |
| 10846 | for (int i = 0; i < slotInfos.length; i++) { |
| 10847 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10848 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10849 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10850 | portInfo.getLogicalSlotIndex())); |
| 10851 | } |
| 10852 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10853 | } |
| 10854 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10855 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10856 | } finally { |
| 10857 | Binder.restoreCallingIdentity(identity); |
| 10858 | } |
| 10859 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10860 | |
| 10861 | /** |
| 10862 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10863 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10864 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10865 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10866 | @Override |
| 10867 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10868 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10869 | } |
| 10870 | |
| 10871 | /** |
| 10872 | * Get the HAL Version of a specific service |
| 10873 | */ |
| 10874 | @Override |
| 10875 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10876 | Phone phone = getDefaultPhone(); |
| 10877 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10878 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10879 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10880 | return hv.major * 100 + hv.minor; |
| 10881 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10882 | |
| 10883 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10884 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10885 | * |
| 10886 | * @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] | 10887 | */ |
| 10888 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10889 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10890 | if (mFeatureFlags.hsumPackageManager()) { |
| 10891 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10892 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10893 | if (pm == null) return null; |
| 10894 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10895 | return (callingUids == null) ? null : callingUids[0]; |
| 10896 | } |
| 10897 | if (mPackageManager == null) return null; |
| 10898 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10899 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10900 | } |
| 10901 | |
| 10902 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10903 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10904 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10905 | * actually always the caller. |
| 10906 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10907 | */ |
| 10908 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10909 | PackageManager pm; |
| 10910 | if (mFeatureFlags.hsumPackageManager()) { |
| 10911 | pm = mApp.getBaseContext().createContextAsUser( |
| 10912 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10913 | } else { |
| 10914 | pm = mApp.getPackageManager(); |
| 10915 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10916 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10917 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10918 | return getCurrentPackageName(); |
| 10919 | } |
| 10920 | |
| 10921 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10922 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10923 | * corresponding network requests on a subId. |
| 10924 | * |
| 10925 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10926 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10927 | * 2) APN is un-metered for this subscription, or |
| 10928 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10929 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10930 | * |
| 10931 | * @return whether data is allowed for a apn type. |
| 10932 | * |
| 10933 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10934 | */ |
| 10935 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10936 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10937 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10938 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10939 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10940 | enforceTelephonyFeatureWithException(callingPackage, |
| 10941 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10942 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10943 | // Now that all security checks passes, perform the operation as ourselves. |
| 10944 | final long identity = Binder.clearCallingIdentity(); |
| 10945 | try { |
| 10946 | Phone phone = getPhone(subId); |
| 10947 | if (phone == null) return false; |
| 10948 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10949 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10950 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10951 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10952 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10953 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10954 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10955 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10956 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10957 | } finally { |
| 10958 | Binder.restoreCallingIdentity(identity); |
| 10959 | } |
| 10960 | } |
| 10961 | |
| 10962 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10963 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10964 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10965 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10966 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10967 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10968 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10969 | // Now that all security checks passes, perform the operation as ourselves. |
| 10970 | final long identity = Binder.clearCallingIdentity(); |
| 10971 | try { |
| 10972 | Phone phone = getPhone(subId); |
| 10973 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10974 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10975 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10976 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10977 | } finally { |
| 10978 | Binder.restoreCallingIdentity(identity); |
| 10979 | } |
| 10980 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10981 | |
| 10982 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10983 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10984 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10985 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10986 | |
| 10987 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10988 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10989 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10990 | long token = Binder.clearCallingIdentity(); |
| 10991 | try { |
| 10992 | Phone phone = getPhone(subscriptionId); |
| 10993 | if (phone == null) { |
| 10994 | try { |
| 10995 | if (resultCallback != null) { |
| 10996 | resultCallback.accept(false); |
| 10997 | } |
| 10998 | } catch (RemoteException e) { |
| 10999 | // ignore |
| 11000 | } |
| 11001 | return; |
| 11002 | } |
| 11003 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11004 | Pair.create(specifiers, (x) -> { |
| 11005 | try { |
| 11006 | if (resultCallback != null) { |
| 11007 | resultCallback.accept(x); |
| 11008 | } |
| 11009 | } catch (RemoteException e) { |
| 11010 | // ignore |
| 11011 | } |
| 11012 | }); |
| 11013 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11014 | } finally { |
| 11015 | Binder.restoreCallingIdentity(token); |
| 11016 | } |
| 11017 | } |
| 11018 | |
| 11019 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11020 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11021 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11022 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11023 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11024 | |
| 11025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11026 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11027 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11028 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11029 | final long identity = Binder.clearCallingIdentity(); |
| 11030 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11031 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11032 | if (result instanceof IllegalStateException) { |
| 11033 | throw (IllegalStateException) result; |
| 11034 | } |
| 11035 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11036 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11037 | return specifiers; |
| 11038 | } finally { |
| 11039 | Binder.restoreCallingIdentity(identity); |
| 11040 | } |
| 11041 | } |
| 11042 | |
| 11043 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11044 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11045 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11046 | |
| 11047 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11048 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11049 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11050 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11051 | } |
| 11052 | |
| 11053 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11054 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11055 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11056 | if (callingPackage == null) { |
| 11057 | callingPackage = getCurrentPackageName(); |
| 11058 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11059 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11060 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11061 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11062 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11063 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11064 | } |
| 11065 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11066 | Intent intent = new Intent(); |
| 11067 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11068 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11069 | // Bring up choose default SMS subscription dialog right now |
| 11070 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11071 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11072 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11073 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11074 | |
| 11075 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11076 | public void showSwitchToManagedProfileDialog() { |
| 11077 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11078 | try { |
| 11079 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11080 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11081 | // for work telephony. |
| 11082 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11083 | intent.setData(Uri.parse("smsto:")); |
| 11084 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11085 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11086 | } catch (ActivityNotFoundException e) { |
| 11087 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11088 | Intent intent = new Intent(); |
| 11089 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11090 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11091 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11092 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11093 | } |
| 11094 | |
| 11095 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11096 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11098 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11099 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11100 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11101 | final long identity = Binder.clearCallingIdentity(); |
| 11102 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11103 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11104 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11105 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11106 | return carrierUAProfUrl; |
| 11107 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11108 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11109 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11110 | } finally { |
| 11111 | Binder.restoreCallingIdentity(identity); |
| 11112 | } |
| 11113 | } |
| 11114 | |
| 11115 | @Override |
| 11116 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11117 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11118 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11119 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11120 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11121 | final long identity = Binder.clearCallingIdentity(); |
| 11122 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11123 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11124 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11125 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11126 | return carrierUserAgent; |
| 11127 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11128 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11129 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11130 | } finally { |
| 11131 | Binder.restoreCallingIdentity(identity); |
| 11132 | } |
| 11133 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11134 | |
| 11135 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11136 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11137 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11138 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11139 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11140 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11141 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11142 | final long identity = Binder.clearCallingIdentity(); |
| 11143 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11144 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11145 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11146 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11147 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11148 | } finally { |
| 11149 | Binder.restoreCallingIdentity(identity); |
| 11150 | } |
| 11151 | } |
| 11152 | |
| 11153 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11154 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11155 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11156 | enforceModifyPermission(); |
| 11157 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11159 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11160 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11161 | final long identity = Binder.clearCallingIdentity(); |
| 11162 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11163 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11164 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11165 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11166 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11167 | } finally { |
| 11168 | Binder.restoreCallingIdentity(identity); |
| 11169 | } |
| 11170 | } |
| 11171 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11172 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11173 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11174 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11175 | * otherwise. |
| 11176 | */ |
| 11177 | @Override |
| 11178 | public void setCepEnabled(boolean isCepEnabled) { |
| 11179 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11180 | |
| 11181 | final long identity = Binder.clearCallingIdentity(); |
| 11182 | try { |
| 11183 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11184 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11185 | Phone defaultPhone = phone.getImsPhone(); |
| 11186 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11187 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11188 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11189 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11190 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11191 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11192 | + imsPhone.getMsisdn()); |
| 11193 | } |
| 11194 | } |
| 11195 | } finally { |
| 11196 | Binder.restoreCallingIdentity(identity); |
| 11197 | } |
| 11198 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11199 | |
| 11200 | /** |
| 11201 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11202 | * |
| 11203 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11204 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11205 | * before being read. |
| 11206 | */ |
| 11207 | @Override |
| 11208 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11209 | isCompressed) { |
| 11210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11211 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11212 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11213 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11214 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11215 | |
| 11216 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11217 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11218 | Binder.getCallingUserHandle())) { |
| 11219 | if (!isImsAvailableOnDevice()) { |
| 11220 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11221 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11222 | throw new IllegalStateException("IMS not available on device."); |
| 11223 | } |
| 11224 | } else { |
| 11225 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11226 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11227 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11228 | } |
| 11229 | |
| 11230 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11231 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11232 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11233 | } finally { |
| 11234 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11235 | } |
| 11236 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11237 | |
| 11238 | @Override |
| 11239 | public boolean isIccLockEnabled(int subId) { |
| 11240 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11242 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11243 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11244 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11245 | // Now that all security checks passes, perform the operation as ourselves. |
| 11246 | final long identity = Binder.clearCallingIdentity(); |
| 11247 | try { |
| 11248 | Phone phone = getPhone(subId); |
| 11249 | if (phone != null && phone.getIccCard() != null) { |
| 11250 | return phone.getIccCard().getIccLockEnabled(); |
| 11251 | } else { |
| 11252 | return false; |
| 11253 | } |
| 11254 | } finally { |
| 11255 | Binder.restoreCallingIdentity(identity); |
| 11256 | } |
| 11257 | } |
| 11258 | |
| 11259 | /** |
| 11260 | * Set the ICC pin lock enabled or disabled. |
| 11261 | * |
| 11262 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11263 | * three cases: |
| 11264 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11265 | * successfully. |
| 11266 | * - Positive number and zero for remaining password attempts. |
| 11267 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11268 | * |
| 11269 | */ |
| 11270 | @Override |
| 11271 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11272 | enforceModifyPermission(); |
| 11273 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11274 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11275 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11276 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11277 | Phone phone = getPhone(subId); |
| 11278 | if (phone == null) { |
| 11279 | return 0; |
| 11280 | } |
| 11281 | // Now that all security checks passes, perform the operation as ourselves. |
| 11282 | final long identity = Binder.clearCallingIdentity(); |
| 11283 | try { |
| 11284 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11285 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11286 | return attemptsRemaining; |
| 11287 | |
| 11288 | } catch (Exception e) { |
| 11289 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11290 | } finally { |
| 11291 | Binder.restoreCallingIdentity(identity); |
| 11292 | } |
| 11293 | return 0; |
| 11294 | } |
| 11295 | |
| 11296 | /** |
| 11297 | * Change the ICC password used in ICC pin lock. |
| 11298 | * |
| 11299 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11300 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11301 | * - Positive number and zero for remaining password attempts. |
| 11302 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11303 | * |
| 11304 | */ |
| 11305 | @Override |
| 11306 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11307 | enforceModifyPermission(); |
| 11308 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11309 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11310 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11311 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11312 | Phone phone = getPhone(subId); |
| 11313 | if (phone == null) { |
| 11314 | return 0; |
| 11315 | } |
| 11316 | // Now that all security checks passes, perform the operation as ourselves. |
| 11317 | final long identity = Binder.clearCallingIdentity(); |
| 11318 | try { |
| 11319 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11320 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11321 | return attemptsRemaining; |
| 11322 | |
| 11323 | } catch (Exception e) { |
| 11324 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11325 | } finally { |
| 11326 | Binder.restoreCallingIdentity(identity); |
| 11327 | } |
| 11328 | return 0; |
| 11329 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11330 | |
| 11331 | /** |
| 11332 | * Request for receiving user activity notification |
| 11333 | */ |
| 11334 | @Override |
| 11335 | public void requestUserActivityNotification() { |
| 11336 | if (!mNotifyUserActivity.get() |
| 11337 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11338 | mNotifyUserActivity.set(true); |
| 11339 | } |
| 11340 | } |
| 11341 | |
| 11342 | /** |
| 11343 | * Called when userActivity is signalled in the power manager. |
| 11344 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11345 | */ |
| 11346 | @Override |
| 11347 | public void userActivity() { |
| 11348 | // *************************************** |
| 11349 | // * Inherited from PhoneWindowManager * |
| 11350 | // *************************************** |
| 11351 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11352 | // WITH ITS LOCKS HELD. |
| 11353 | // |
| 11354 | // This code must be VERY careful about the locks |
| 11355 | // it acquires. |
| 11356 | // In fact, the current code acquires way too many, |
| 11357 | // and probably has lurking deadlocks. |
| 11358 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11359 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11360 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11361 | } |
| 11362 | |
| 11363 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11364 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11365 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11366 | } |
| 11367 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11368 | |
| 11369 | @Override |
| 11370 | public boolean canConnectTo5GInDsdsMode() { |
| 11371 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11372 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11373 | |
| 11374 | @Override |
| 11375 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11376 | String callingFeatureId) { |
| 11377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11378 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11379 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11380 | } |
| 11381 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11382 | enforceTelephonyFeatureWithException(callingPackage, |
| 11383 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11384 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11385 | Phone phone = getPhone(subId); |
| 11386 | if (phone == null) { |
| 11387 | throw new RuntimeException("phone is not available"); |
| 11388 | } |
| 11389 | // Now that all security checks passes, perform the operation as ourselves. |
| 11390 | final long identity = Binder.clearCallingIdentity(); |
| 11391 | try { |
| 11392 | return phone.getEquivalentHomePlmns(); |
| 11393 | } finally { |
| 11394 | Binder.restoreCallingIdentity(identity); |
| 11395 | } |
| 11396 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11397 | |
| 11398 | @Override |
| 11399 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11400 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11401 | if (!mApp.getResources().getBoolean( |
| 11402 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11403 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11404 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11405 | "isRadioInterfaceCapabilitySupported"); |
| 11406 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11407 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11408 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11409 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11410 | if (radioInterfaceCapabilities == null) { |
| 11411 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11412 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11413 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11414 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11415 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11416 | @Override |
| 11417 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11418 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11419 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11420 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11421 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11422 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11423 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11424 | |
| 11425 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11426 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11427 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11428 | if (DBG) { |
| 11429 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11430 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11431 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11432 | } |
| 11433 | |
| 11434 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11435 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11436 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11437 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11438 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11439 | if (callback != null) { |
| 11440 | try { |
| 11441 | callback.onAuthenticationFailure( |
| 11442 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11443 | } catch (RemoteException exception) { |
| 11444 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11445 | } |
| 11446 | return; |
| 11447 | } |
| 11448 | } |
| 11449 | |
| 11450 | final long token = Binder.clearCallingIdentity(); |
| 11451 | try { |
| 11452 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11453 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11454 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11455 | } finally { |
| 11456 | Binder.restoreCallingIdentity(token); |
| 11457 | } |
| 11458 | } |
| 11459 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11460 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11461 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11462 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11463 | * requested radio power state will actually be set. See {@link |
| 11464 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11465 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11466 | * @param enable {@code true} if trying to turn radio on. |
| 11467 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11468 | * false}. |
| 11469 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11470 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11471 | boolean isPhoneAvailable = false; |
| 11472 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11473 | Phone phone = PhoneFactory.getPhone(i); |
| 11474 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11475 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11476 | isPhoneAvailable = true; |
| 11477 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11478 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11479 | |
| 11480 | // return true if successfully informed the phone object about the thermal radio power |
| 11481 | // request. |
| 11482 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11483 | } |
| 11484 | |
| 11485 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11486 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11487 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11488 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11489 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11490 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11491 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11492 | } |
| 11493 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11494 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11495 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11496 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11497 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11498 | } |
| 11499 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11500 | setDataEnabledForReason( |
| 11501 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11502 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11503 | if (isDataThrottlingSupported) { |
| 11504 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11505 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11506 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11507 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11508 | } else if (thermalMitigationResult |
| 11509 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11510 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11511 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11512 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11513 | } |
| 11514 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11515 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11516 | |
| 11517 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11518 | } |
| 11519 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11520 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11521 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11522 | for (String pckg : context.getResources() |
| 11523 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11524 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11525 | } |
| 11526 | } |
| 11527 | |
| 11528 | return sThermalMitigationAllowlistedPackages; |
| 11529 | } |
| 11530 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11531 | private boolean isAnyPhoneInEmergencyState() { |
| 11532 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11533 | if (tm.isInEmergencyCall()) { |
| 11534 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11535 | return true; |
| 11536 | } |
| 11537 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11538 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11539 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11540 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11541 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11542 | return true; |
| 11543 | } |
| 11544 | } |
| 11545 | |
| 11546 | return false; |
| 11547 | } |
| 11548 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11549 | /** |
| 11550 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11551 | * @param packageName name of package to be allowlisted |
| 11552 | * @param context |
| 11553 | */ |
| 11554 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11555 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11556 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11557 | } |
| 11558 | |
| 11559 | /** |
| 11560 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11561 | * @param packageName name of package to remove from allowlist |
| 11562 | * @param context |
| 11563 | */ |
| 11564 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11565 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11566 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11567 | } |
| 11568 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11569 | /** |
| 11570 | * Thermal mitigation request to control functionalities at modem. |
| 11571 | * |
| 11572 | * @param subId the id of the subscription. |
| 11573 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11574 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11575 | * |
| 11576 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11577 | */ |
| 11578 | @Override |
| 11579 | @ThermalMitigationResult |
| 11580 | public int sendThermalMitigationRequest( |
| 11581 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11582 | ThermalMitigationRequest thermalMitigationRequest, |
| 11583 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11584 | enforceModifyPermission(); |
| 11585 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11586 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11587 | |
| 11588 | enforceTelephonyFeatureWithException(callingPackage, |
| 11589 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11590 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11591 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11592 | .contains(callingPackage)) { |
| 11593 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11594 | + "calling package: " + callingPackage); |
| 11595 | } |
| 11596 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11597 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11598 | final long identity = Binder.clearCallingIdentity(); |
| 11599 | |
| 11600 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11601 | try { |
| 11602 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11603 | switch (thermalMitigationAction) { |
| 11604 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11605 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11606 | handleDataThrottlingRequest(subId, |
| 11607 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11608 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11609 | break; |
| 11610 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11611 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11612 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11613 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11614 | } |
| 11615 | |
| 11616 | // Ensure that radio is on. If not able to power on due to phone being |
| 11617 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11618 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11619 | thermalMitigationResult = |
| 11620 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11621 | break; |
| 11622 | } |
| 11623 | |
| 11624 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11625 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11626 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11627 | break; |
| 11628 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11629 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11630 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11631 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11632 | } |
| 11633 | |
| 11634 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11635 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11636 | Phone phone = getPhone(subId); |
| 11637 | if (phone == null) { |
| 11638 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11639 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11640 | break; |
| 11641 | } |
| 11642 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11643 | TelephonyConnectionService service = |
| 11644 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11645 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11646 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11647 | thermalMitigationResult = |
| 11648 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11649 | break; |
| 11650 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11651 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11652 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11653 | break; |
| 11654 | } |
| 11655 | } else { |
| 11656 | thermalMitigationResult = |
| 11657 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11658 | break; |
| 11659 | } |
| 11660 | |
| 11661 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11662 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11663 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11664 | thermalMitigationResult = |
| 11665 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11666 | break; |
| 11667 | } |
| 11668 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11669 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11670 | break; |
| 11671 | default: |
| 11672 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11673 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11674 | } |
| 11675 | } catch (IllegalArgumentException e) { |
| 11676 | throw e; |
| 11677 | } catch (Exception e) { |
| 11678 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11679 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11680 | } finally { |
| 11681 | Binder.restoreCallingIdentity(identity); |
| 11682 | } |
| 11683 | |
| 11684 | if (DBG) { |
| 11685 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11686 | + thermalMitigationResult); |
| 11687 | } |
| 11688 | |
| 11689 | return thermalMitigationResult; |
| 11690 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11691 | |
| 11692 | /** |
| 11693 | * Set the GbaService Package Name that Telephony will bind to. |
| 11694 | * |
| 11695 | * @param subId The sim that the GbaService is associated with. |
| 11696 | * @param packageName The name of the package to be replaced with. |
| 11697 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11698 | */ |
| 11699 | @Override |
| 11700 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11701 | enforceModifyPermission(); |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11702 | int userId = ActivityManager.getCurrentUser(); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11703 | final long identity = Binder.clearCallingIdentity(); |
| 11704 | try { |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11705 | return getGbaManager(subId).overrideServicePackage(packageName, userId); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11706 | } finally { |
| 11707 | Binder.restoreCallingIdentity(identity); |
| 11708 | } |
| 11709 | } |
| 11710 | |
| 11711 | /** |
| 11712 | * Return the package name of the currently bound GbaService. |
| 11713 | * |
| 11714 | * @param subId The sim that the GbaService is associated with. |
| 11715 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11716 | */ |
| 11717 | @Override |
| 11718 | public String getBoundGbaService(int subId) { |
| 11719 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11720 | |
| 11721 | final long identity = Binder.clearCallingIdentity(); |
| 11722 | try { |
| 11723 | return getGbaManager(subId).getServicePackage(); |
| 11724 | } finally { |
| 11725 | Binder.restoreCallingIdentity(identity); |
| 11726 | } |
| 11727 | } |
| 11728 | |
| 11729 | /** |
| 11730 | * Set the release time for telephony to unbind GbaService. |
| 11731 | * |
| 11732 | * @param subId The sim that the GbaService is associated with. |
| 11733 | * @param interval The release time to unbind GbaService by millisecond. |
| 11734 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11735 | */ |
| 11736 | @Override |
| 11737 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11738 | enforceModifyPermission(); |
| 11739 | |
| 11740 | final long identity = Binder.clearCallingIdentity(); |
| 11741 | try { |
| 11742 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11743 | } finally { |
| 11744 | Binder.restoreCallingIdentity(identity); |
| 11745 | } |
| 11746 | } |
| 11747 | |
| 11748 | /** |
| 11749 | * Return the release time for telephony to unbind GbaService. |
| 11750 | * |
| 11751 | * @param subId The sim that the GbaService is associated with. |
| 11752 | * @return The release time to unbind GbaService by millisecond. |
| 11753 | */ |
| 11754 | @Override |
| 11755 | public int getGbaReleaseTime(int subId) { |
| 11756 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11757 | |
| 11758 | final long identity = Binder.clearCallingIdentity(); |
| 11759 | try { |
| 11760 | return getGbaManager(subId).getReleaseTime(); |
| 11761 | } finally { |
| 11762 | Binder.restoreCallingIdentity(identity); |
| 11763 | } |
| 11764 | } |
| 11765 | |
| 11766 | private GbaManager getGbaManager(int subId) { |
| 11767 | GbaManager instance = GbaManager.getInstance(subId); |
| 11768 | if (instance == null) { |
| 11769 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11770 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11771 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11772 | } |
| 11773 | return instance; |
| 11774 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11775 | |
| 11776 | /** |
| 11777 | * indicate whether the device and the carrier can support |
| 11778 | * RCS VoLTE single registration. |
| 11779 | */ |
| 11780 | @Override |
| 11781 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11782 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11783 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11784 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11785 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11786 | |
| 11787 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11788 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11789 | } |
| 11790 | |
| 11791 | final long identity = Binder.clearCallingIdentity(); |
| 11792 | try { |
| 11793 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11794 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11795 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11796 | if (isCapable != null) { |
| 11797 | return isCapable; |
| 11798 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11799 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11800 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11801 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11802 | } finally { |
| 11803 | Binder.restoreCallingIdentity(identity); |
| 11804 | } |
| 11805 | } |
| 11806 | |
| 11807 | /** |
| 11808 | * Register RCS provisioning callback. |
| 11809 | */ |
| 11810 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11811 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11812 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11813 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11814 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11815 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11816 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11817 | |
| 11818 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11819 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11820 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11821 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11822 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11823 | Binder.getCallingUserHandle())) { |
| 11824 | if (!isImsAvailableOnDevice()) { |
| 11825 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11826 | "IMS not available on device."); |
| 11827 | } |
| 11828 | } else { |
| 11829 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11830 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11831 | } |
| 11832 | |
| 11833 | final long identity = Binder.clearCallingIdentity(); |
| 11834 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11835 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11836 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11837 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11838 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11839 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11840 | } finally { |
| 11841 | Binder.restoreCallingIdentity(identity); |
| 11842 | } |
| 11843 | } |
| 11844 | |
| 11845 | /** |
| 11846 | * Unregister RCS provisioning callback. |
| 11847 | */ |
| 11848 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11849 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11850 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11851 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11852 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11853 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11854 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11855 | |
| 11856 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11857 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11858 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11859 | |
| 11860 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11861 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11862 | Binder.getCallingUserHandle())) { |
| 11863 | if (!isImsAvailableOnDevice()) { |
| 11864 | // operation failed silently |
| 11865 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11866 | return; |
| 11867 | } |
| 11868 | } else { |
| 11869 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11870 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11871 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11872 | } |
| 11873 | |
| 11874 | final long identity = Binder.clearCallingIdentity(); |
| 11875 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11876 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11877 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11878 | } finally { |
| 11879 | Binder.restoreCallingIdentity(identity); |
| 11880 | } |
| 11881 | } |
| 11882 | |
| 11883 | /** |
| 11884 | * trigger RCS reconfiguration. |
| 11885 | */ |
| 11886 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11887 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11888 | "triggerRcsReconfiguration", |
| 11889 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11890 | |
| 11891 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11892 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11893 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11894 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11895 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11896 | Binder.getCallingUserHandle())) { |
| 11897 | if (!isImsAvailableOnDevice()) { |
| 11898 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11899 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11900 | throw new IllegalStateException("IMS not available on device."); |
| 11901 | } |
| 11902 | } else { |
| 11903 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11904 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11905 | } |
| 11906 | |
| 11907 | final long identity = Binder.clearCallingIdentity(); |
| 11908 | try { |
| 11909 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11910 | } finally { |
| 11911 | Binder.restoreCallingIdentity(identity); |
| 11912 | } |
| 11913 | } |
| 11914 | |
| 11915 | /** |
| 11916 | * Provide the client configuration parameters of the RCS application. |
| 11917 | */ |
| 11918 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11919 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11920 | "setRcsClientConfiguration", |
| 11921 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11922 | |
| 11923 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11924 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11925 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11926 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11927 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11928 | Binder.getCallingUserHandle())) { |
| 11929 | if (!isImsAvailableOnDevice()) { |
| 11930 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11931 | "IMS not available on device."); |
| 11932 | } |
| 11933 | } else { |
| 11934 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11935 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11936 | } |
| 11937 | |
| 11938 | final long identity = Binder.clearCallingIdentity(); |
| 11939 | |
| 11940 | try { |
| 11941 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11942 | if (configBinder == null) { |
| 11943 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11945 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11946 | } else { |
| 11947 | configBinder.setRcsClientConfiguration(rcc); |
| 11948 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11949 | |
| 11950 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11951 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11952 | } catch (RemoteException e) { |
| 11953 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11954 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11955 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11956 | } finally { |
| 11957 | Binder.restoreCallingIdentity(identity); |
| 11958 | } |
| 11959 | } |
| 11960 | |
| 11961 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11962 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11963 | */ |
| 11964 | @Override |
| 11965 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11966 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11967 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11968 | |
| 11969 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11970 | } |
| 11971 | |
| 11972 | /** |
| 11973 | * Gets the test mode for RCS VoLTE single registration. |
| 11974 | */ |
| 11975 | @Override |
| 11976 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11977 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11978 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11979 | |
| 11980 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11981 | } |
| 11982 | |
| 11983 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11984 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11985 | */ |
| 11986 | @Override |
| 11987 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11988 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11989 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11990 | enforceModifyPermission(); |
| 11991 | |
| 11992 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11993 | : Boolean.parseBoolean(enabledStr); |
| 11994 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11995 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11996 | } |
| 11997 | |
| 11998 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11999 | * Sends a device to device communication message. Only usable via shell. |
| 12000 | * @param message message to send. |
| 12001 | * @param value message value. |
| 12002 | */ |
| 12003 | @Override |
| 12004 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12005 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12006 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12007 | enforceModifyPermission(); |
| 12008 | |
| 12009 | final long identity = Binder.clearCallingIdentity(); |
| 12010 | try { |
| 12011 | TelephonyConnectionService service = |
| 12012 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12013 | if (service == null) { |
| 12014 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12015 | return; |
| 12016 | } |
| 12017 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12018 | } finally { |
| 12019 | Binder.restoreCallingIdentity(identity); |
| 12020 | } |
| 12021 | } |
| 12022 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12023 | /** |
| 12024 | * Sets the specified device to device transport active. |
| 12025 | * @param transport The transport to set active. |
| 12026 | */ |
| 12027 | @Override |
| 12028 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12029 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12030 | "setActiveDeviceToDeviceTransport"); |
| 12031 | enforceModifyPermission(); |
| 12032 | |
| 12033 | final long identity = Binder.clearCallingIdentity(); |
| 12034 | try { |
| 12035 | TelephonyConnectionService service = |
| 12036 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12037 | if (service == null) { |
| 12038 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12039 | return; |
| 12040 | } |
| 12041 | service.setActiveDeviceToDeviceTransport(transport); |
| 12042 | } finally { |
| 12043 | Binder.restoreCallingIdentity(identity); |
| 12044 | } |
| 12045 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12046 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12047 | @Override |
| 12048 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12049 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12050 | "setDeviceToDeviceForceEnabled"); |
| 12051 | |
| 12052 | final long identity = Binder.clearCallingIdentity(); |
| 12053 | try { |
| 12054 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12055 | p -> { |
| 12056 | Phone thePhone = p.getImsPhone(); |
| 12057 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12058 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12059 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12060 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12061 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12062 | (ImsPhoneCallTracker) tracker; |
| 12063 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12064 | } |
| 12065 | } |
| 12066 | } |
| 12067 | ); |
| 12068 | } finally { |
| 12069 | Binder.restoreCallingIdentity(identity); |
| 12070 | } |
| 12071 | } |
| 12072 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12073 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12074 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12075 | */ |
| 12076 | @Override |
| 12077 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12078 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12079 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12080 | } |
| 12081 | |
| 12082 | /** |
| 12083 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12084 | */ |
| 12085 | @Override |
| 12086 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12087 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12088 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12089 | enforceModifyPermission(); |
| 12090 | |
| 12091 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12092 | : Boolean.parseBoolean(enabledStr); |
| 12093 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12094 | subId, enabled); |
| 12095 | } |
| 12096 | |
| 12097 | /** |
| 12098 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12099 | */ |
| 12100 | @Override |
| 12101 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12102 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12103 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12104 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12105 | |
| 12106 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12107 | * Overrides the ims feature validation result |
| 12108 | */ |
| 12109 | @Override |
| 12110 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12111 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12112 | "setImsFeatureValidationOverride"); |
| 12113 | |
| 12114 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12115 | : Boolean.parseBoolean(enabledStr); |
| 12116 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12117 | subId, enabled); |
| 12118 | } |
| 12119 | |
| 12120 | /** |
| 12121 | * Gets the ims feature validation override value |
| 12122 | */ |
| 12123 | @Override |
| 12124 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12126 | "getImsFeatureValidationOverride"); |
| 12127 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12128 | } |
| 12129 | |
| 12130 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12131 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12132 | * their mobile plan. |
| 12133 | */ |
| 12134 | @Override |
| 12135 | public String getMobileProvisioningUrl() { |
| 12136 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12137 | final long identity = Binder.clearCallingIdentity(); |
| 12138 | try { |
| 12139 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12140 | } finally { |
| 12141 | Binder.restoreCallingIdentity(identity); |
| 12142 | } |
| 12143 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12144 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12145 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12146 | * Get the EAB contact from the EAB database. |
| 12147 | */ |
| 12148 | @Override |
| 12149 | public String getContactFromEab(String contact) { |
| 12150 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12151 | enforceModifyPermission(); |
| 12152 | final long identity = Binder.clearCallingIdentity(); |
| 12153 | try { |
| 12154 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12155 | } finally { |
| 12156 | Binder.restoreCallingIdentity(identity); |
| 12157 | } |
| 12158 | } |
| 12159 | |
| 12160 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12161 | * Get the EAB capability from the EAB database. |
| 12162 | */ |
| 12163 | @Override |
| 12164 | public String getCapabilityFromEab(String contact) { |
| 12165 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12166 | enforceModifyPermission(); |
| 12167 | final long identity = Binder.clearCallingIdentity(); |
| 12168 | try { |
| 12169 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12170 | } finally { |
| 12171 | Binder.restoreCallingIdentity(identity); |
| 12172 | } |
| 12173 | } |
| 12174 | |
| 12175 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12176 | * Remove the EAB contacts from the EAB database. |
| 12177 | */ |
| 12178 | @Override |
| 12179 | public int removeContactFromEab(int subId, String contacts) { |
| 12180 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12181 | enforceModifyPermission(); |
| 12182 | final long identity = Binder.clearCallingIdentity(); |
| 12183 | try { |
| 12184 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12185 | } finally { |
| 12186 | Binder.restoreCallingIdentity(identity); |
| 12187 | } |
| 12188 | } |
| 12189 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12190 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12191 | public boolean getDeviceUceEnabled() { |
| 12192 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12193 | final long identity = Binder.clearCallingIdentity(); |
| 12194 | try { |
| 12195 | return mApp.getDeviceUceEnabled(); |
| 12196 | } finally { |
| 12197 | Binder.restoreCallingIdentity(identity); |
| 12198 | } |
| 12199 | } |
| 12200 | |
| 12201 | @Override |
| 12202 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12203 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12204 | final long identity = Binder.clearCallingIdentity(); |
| 12205 | try { |
| 12206 | mApp.setDeviceUceEnabled(isEnabled); |
| 12207 | } finally { |
| 12208 | Binder.restoreCallingIdentity(identity); |
| 12209 | } |
| 12210 | } |
| 12211 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12212 | /** |
| 12213 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12214 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12215 | */ |
| 12216 | // Used for SHELL command only right now. |
| 12217 | @Override |
| 12218 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12219 | List<String> featureTags) { |
| 12220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12221 | "addUceRegistrationOverrideShell"); |
| 12222 | final long identity = Binder.clearCallingIdentity(); |
| 12223 | try { |
| 12224 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12225 | new ArraySet<>(featureTags)); |
| 12226 | } catch (ImsException e) { |
| 12227 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12228 | } finally { |
| 12229 | Binder.restoreCallingIdentity(identity); |
| 12230 | } |
| 12231 | } |
| 12232 | |
| 12233 | /** |
| 12234 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12235 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12236 | */ |
| 12237 | // Used for SHELL command only right now. |
| 12238 | @Override |
| 12239 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12240 | List<String> featureTags) { |
| 12241 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12242 | "removeUceRegistrationOverrideShell"); |
| 12243 | final long identity = Binder.clearCallingIdentity(); |
| 12244 | try { |
| 12245 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12246 | new ArraySet<>(featureTags)); |
| 12247 | } catch (ImsException e) { |
| 12248 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12249 | } finally { |
| 12250 | Binder.restoreCallingIdentity(identity); |
| 12251 | } |
| 12252 | } |
| 12253 | |
| 12254 | /** |
| 12255 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12256 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12257 | */ |
| 12258 | // Used for SHELL command only right now. |
| 12259 | @Override |
| 12260 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12261 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12262 | "clearUceRegistrationOverrideShell"); |
| 12263 | final long identity = Binder.clearCallingIdentity(); |
| 12264 | try { |
| 12265 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12266 | } catch (ImsException e) { |
| 12267 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12268 | } finally { |
| 12269 | Binder.restoreCallingIdentity(identity); |
| 12270 | } |
| 12271 | } |
| 12272 | |
| 12273 | /** |
| 12274 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12275 | */ |
| 12276 | // Used for SHELL command only right now. |
| 12277 | @Override |
| 12278 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12279 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12280 | "getLatestRcsContactUceCapabilityShell"); |
| 12281 | final long identity = Binder.clearCallingIdentity(); |
| 12282 | try { |
| 12283 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12284 | } catch (ImsException e) { |
| 12285 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12286 | } finally { |
| 12287 | Binder.restoreCallingIdentity(identity); |
| 12288 | } |
| 12289 | } |
| 12290 | |
| 12291 | /** |
| 12292 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12293 | * device does not have an active PUBLISH. |
| 12294 | */ |
| 12295 | // Used for SHELL command only right now. |
| 12296 | @Override |
| 12297 | public String getLastUcePidfXmlShell(int subId) { |
| 12298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12299 | final long identity = Binder.clearCallingIdentity(); |
| 12300 | try { |
| 12301 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12302 | } catch (ImsException e) { |
| 12303 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12304 | } finally { |
| 12305 | Binder.restoreCallingIdentity(identity); |
| 12306 | } |
| 12307 | } |
| 12308 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12309 | /** |
| 12310 | * Remove UCE requests cannot be sent to the network status. |
| 12311 | */ |
| 12312 | // Used for SHELL command only right now. |
| 12313 | @Override |
| 12314 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12315 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12316 | final long identity = Binder.clearCallingIdentity(); |
| 12317 | try { |
| 12318 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12319 | } catch (ImsException e) { |
| 12320 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12321 | } finally { |
| 12322 | Binder.restoreCallingIdentity(identity); |
| 12323 | } |
| 12324 | } |
| 12325 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12326 | /** |
| 12327 | * Remove UCE requests cannot be sent to the network status. |
| 12328 | */ |
| 12329 | // Used for SHELL command only. |
| 12330 | @Override |
| 12331 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12332 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12333 | final long identity = Binder.clearCallingIdentity(); |
| 12334 | try { |
| 12335 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12336 | } catch (ImsException e) { |
| 12337 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12338 | } finally { |
| 12339 | Binder.restoreCallingIdentity(identity); |
| 12340 | } |
| 12341 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12342 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12343 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12344 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12345 | String callingPackage) { |
| 12346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12347 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12348 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12349 | enforceTelephonyFeatureWithException(callingPackage, |
| 12350 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12351 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12352 | final int callingUid = Binder.getCallingUid(); |
| 12353 | // Verify that tha callingPackage belongs to the calling UID |
| 12354 | mApp.getSystemService(AppOpsManager.class) |
| 12355 | .checkPackage(callingUid, callingPackage); |
| 12356 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12357 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12358 | |
| 12359 | final long identity = Binder.clearCallingIdentity(); |
| 12360 | try { |
| 12361 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12362 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12363 | |
| 12364 | if (result instanceof IllegalStateException) { |
| 12365 | throw (IllegalStateException) result; |
| 12366 | } |
| 12367 | } finally { |
| 12368 | Binder.restoreCallingIdentity(identity); |
| 12369 | } |
| 12370 | } |
| 12371 | |
| 12372 | @Override |
| 12373 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12374 | String callingPackage) { |
| 12375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12376 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12377 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12378 | enforceTelephonyFeatureWithException(callingPackage, |
| 12379 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12380 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12381 | final int callingUid = Binder.getCallingUid(); |
| 12382 | // Verify that tha callingPackage belongs to the calling UID |
| 12383 | mApp.getSystemService(AppOpsManager.class) |
| 12384 | .checkPackage(callingUid, callingPackage); |
| 12385 | |
| 12386 | final long identity = Binder.clearCallingIdentity(); |
| 12387 | try { |
| 12388 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12389 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12390 | |
| 12391 | if (result instanceof IllegalStateException) { |
| 12392 | throw (IllegalStateException) result; |
| 12393 | } |
| 12394 | } finally { |
| 12395 | Binder.restoreCallingIdentity(identity); |
| 12396 | } |
| 12397 | } |
| 12398 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12399 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12400 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12401 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12402 | // phone/system process do not have further restriction on request |
| 12403 | return; |
| 12404 | } |
| 12405 | |
| 12406 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12407 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12408 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12409 | context.enforceCallingOrSelfPermission( |
| 12410 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12411 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12412 | } |
| 12413 | |
| 12414 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12415 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12416 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12417 | || info.isEnabled()) { |
| 12418 | throw new IllegalArgumentException( |
| 12419 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12420 | } |
| 12421 | |
| 12422 | // Thresholds length for each RAN need in range. This has been validated in |
| 12423 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12424 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12425 | final int[] thresholds = info.getThresholds(); |
| 12426 | Objects.requireNonNull(thresholds); |
| 12427 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12428 | || thresholds.length |
| 12429 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12430 | throw new IllegalArgumentException( |
| 12431 | "thresholds length is out of range: " + thresholds.length); |
| 12432 | } |
| 12433 | } |
| 12434 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12435 | |
| 12436 | /** |
| 12437 | * Gets the current phone capability. |
| 12438 | * |
| 12439 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12440 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12441 | * It's used to evaluate possible phone config change, for example from single |
| 12442 | * SIM device to multi-SIM device. |
| 12443 | */ |
| 12444 | @Override |
| 12445 | public PhoneCapability getPhoneCapability() { |
| 12446 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12447 | |
| 12448 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12449 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12450 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12451 | final long identity = Binder.clearCallingIdentity(); |
| 12452 | try { |
| 12453 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12454 | } finally { |
| 12455 | Binder.restoreCallingIdentity(identity); |
| 12456 | } |
| 12457 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12458 | |
| 12459 | /** |
| 12460 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12461 | * required to be done shortly after the API is invoked. |
| 12462 | */ |
| 12463 | @Override |
| 12464 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12465 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12466 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12467 | enforceRebootPermission(); |
| 12468 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12469 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12470 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12471 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12472 | final long identity = Binder.clearCallingIdentity(); |
| 12473 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12474 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12475 | } finally { |
| 12476 | Binder.restoreCallingIdentity(identity); |
| 12477 | } |
| 12478 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12479 | |
| 12480 | /** |
| 12481 | * Request to get the current slicing configuration including URSP rules and |
| 12482 | * NSSAIs (configured, allowed and rejected). |
| 12483 | * |
| 12484 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12485 | */ |
| 12486 | @Override |
| 12487 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12488 | TelephonyPermissions |
| 12489 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12490 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12491 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12492 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12493 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12494 | "getSlicingConfig"); |
| 12495 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12496 | final long identity = Binder.clearCallingIdentity(); |
| 12497 | try { |
| 12498 | Phone phone = getDefaultPhone(); |
| 12499 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12500 | } finally { |
| 12501 | Binder.restoreCallingIdentity(identity); |
| 12502 | } |
| 12503 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12504 | |
| 12505 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12506 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12507 | * |
| 12508 | * @param capability The premium capability to check. |
| 12509 | * @param subId The subId to check the premium capability for. |
| 12510 | * |
| 12511 | * @return Whether the given premium capability is available to purchase. |
| 12512 | */ |
| 12513 | @Override |
| 12514 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12515 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12516 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12517 | log("Premium capability " |
| 12518 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12519 | + " is not available for purchase due to missing permissions."); |
| 12520 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12521 | + "permission READ_BASIC_PHONE_STATE."); |
| 12522 | } |
| 12523 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12524 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12525 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12526 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12527 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12528 | if (phone == null) { |
| 12529 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12530 | return false; |
| 12531 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12532 | final long identity = Binder.clearCallingIdentity(); |
| 12533 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12534 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12535 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12536 | } finally { |
| 12537 | Binder.restoreCallingIdentity(identity); |
| 12538 | } |
| 12539 | } |
| 12540 | |
| 12541 | /** |
| 12542 | * Purchase the given premium capability from the carrier. |
| 12543 | * |
| 12544 | * @param capability The premium capability to purchase. |
| 12545 | * @param callback The result of the purchase request. |
| 12546 | * @param subId The subId to purchase the premium capability for. |
| 12547 | */ |
| 12548 | @Override |
| 12549 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12550 | log("purchasePremiumCapability: capability=" |
| 12551 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12552 | + getCurrentPackageName()); |
| 12553 | |
| 12554 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12555 | mApp, "purchasePremiumCapability")) { |
| 12556 | log("purchasePremiumCapability " |
| 12557 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12558 | + " failed due to missing permissions."); |
| 12559 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12560 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12561 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12562 | mApp, "purchasePremiumCapability")) { |
| 12563 | log("purchasePremiumCapability " |
| 12564 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12565 | + " failed due to missing permissions."); |
| 12566 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12567 | } |
| 12568 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12569 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12570 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12571 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12572 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12573 | if (phone == null) { |
| 12574 | try { |
| 12575 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12576 | callback.accept(result); |
| 12577 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12578 | } catch (RemoteException e) { |
| 12579 | String logStr = "Purchase premium capability " |
| 12580 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12581 | + " failed due to RemoteException handling null phone: " + e; |
| 12582 | if (DBG) log(logStr); |
| 12583 | AnomalyReporter.reportAnomaly( |
| 12584 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12585 | } |
| 12586 | return; |
| 12587 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12588 | |
| 12589 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12590 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12591 | if (mFeatureFlags.hsumPackageManager()) { |
| 12592 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12593 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12594 | } else { |
| 12595 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12596 | getCurrentPackageName(), 0).processName; |
| 12597 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12598 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12599 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12600 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12601 | |
| 12602 | boolean isVisible = false; |
| 12603 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12604 | if (am != null) { |
| 12605 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12606 | if (processes != null) { |
| 12607 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12608 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12609 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12610 | if (process.processName.equals(callingProcess) && process.importance |
| 12611 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12612 | isVisible = true; |
| 12613 | break; |
| 12614 | } |
| 12615 | } |
| 12616 | } |
| 12617 | } |
| 12618 | |
| 12619 | if (!isVisible) { |
| 12620 | try { |
| 12621 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12622 | callback.accept(result); |
| 12623 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12624 | } catch (RemoteException e) { |
| 12625 | String logStr = "Purchase premium capability " |
| 12626 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12627 | + " failed due to RemoteException handling background application: " + e; |
| 12628 | if (DBG) log(logStr); |
| 12629 | AnomalyReporter.reportAnomaly( |
| 12630 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12631 | } |
| 12632 | return; |
| 12633 | } |
| 12634 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12635 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12636 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12637 | } |
| 12638 | |
| 12639 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12640 | * Register an IMS connection state callback |
| 12641 | */ |
| 12642 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12643 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12644 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12645 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12646 | // ImsMmTelManager |
| 12647 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12648 | TelephonyPermissions |
| 12649 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12650 | mApp, subId, "registerImsStateCallback"); |
| 12651 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12652 | // ImsRcsManager or SipDelegateManager |
| 12653 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12654 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12655 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12656 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12657 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12658 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12659 | } |
| 12660 | |
| 12661 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12662 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12663 | "IMS not available on device."); |
| 12664 | } |
| 12665 | |
| 12666 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12667 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12668 | } |
| 12669 | |
| 12670 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12671 | if (controller == null) { |
| 12672 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12673 | "IMS not available on device."); |
| 12674 | } |
| 12675 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12676 | if (callingPackage == null) { |
| 12677 | callingPackage = getCurrentPackageName(); |
| 12678 | } |
| 12679 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12680 | final long token = Binder.clearCallingIdentity(); |
| 12681 | try { |
| 12682 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12683 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12684 | } catch (ImsException e) { |
| 12685 | throw new ServiceSpecificException(e.getCode()); |
| 12686 | } finally { |
| 12687 | Binder.restoreCallingIdentity(token); |
| 12688 | } |
| 12689 | } |
| 12690 | |
| 12691 | /** |
| 12692 | * Unregister an IMS connection state callback |
| 12693 | */ |
| 12694 | @Override |
| 12695 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12696 | final long token = Binder.clearCallingIdentity(); |
| 12697 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12698 | if (controller == null) { |
| 12699 | return; |
| 12700 | } |
| 12701 | try { |
| 12702 | controller.unregisterImsStateCallback(cb); |
| 12703 | } finally { |
| 12704 | Binder.restoreCallingIdentity(token); |
| 12705 | } |
| 12706 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12707 | |
| 12708 | /** |
| 12709 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12710 | * |
| 12711 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12712 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12713 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12714 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12715 | * If there is current registered network this value will be same as the registered cell |
| 12716 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12717 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12718 | * it will be cleared and null will be returned. |
| 12719 | * |
| 12720 | */ |
| 12721 | @Override |
| 12722 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12723 | String callingFeatureId) { |
| 12724 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12725 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12726 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12727 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12728 | .setCallingPackage(callingPackage) |
| 12729 | .setCallingFeatureId(callingFeatureId) |
| 12730 | .setCallingPid(Binder.getCallingPid()) |
| 12731 | .setCallingUid(Binder.getCallingUid()) |
| 12732 | .setMethod("getLastKnownCellIdentity") |
| 12733 | .setLogAsInfo(true) |
| 12734 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12735 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12736 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12737 | .build()); |
| 12738 | |
| 12739 | boolean hasFinePermission = |
| 12740 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12741 | if (!hasFinePermission |
| 12742 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12743 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12744 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12745 | } |
| 12746 | |
| 12747 | final long identity = Binder.clearCallingIdentity(); |
| 12748 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12749 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12750 | if (sst == null) return null; |
| 12751 | return sst.getLastKnownCellIdentity(); |
| 12752 | } finally { |
| 12753 | Binder.restoreCallingIdentity(identity); |
| 12754 | } |
| 12755 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12756 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12757 | /** |
| 12758 | * Sets the modem service class Name that Telephony will bind to. |
| 12759 | * |
| 12760 | * @param serviceName The class name of the modem service. |
| 12761 | * @return true if the operation is succeed, otherwise false. |
| 12762 | */ |
| 12763 | public boolean setModemService(String serviceName) { |
| 12764 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12765 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12767 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12768 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12769 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12770 | } |
| 12771 | |
| 12772 | /** |
| 12773 | * Return the class name of the currently bounded modem service. |
| 12774 | * |
| 12775 | * @return the class name of the modem service. |
| 12776 | */ |
| 12777 | public String getModemService() { |
| 12778 | String result; |
| 12779 | Log.d(LOG_TAG, "getModemService"); |
| 12780 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12781 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12782 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12783 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12784 | "getModemService"); |
| 12785 | result = mPhoneConfigurationManager.getModemService(); |
| 12786 | Log.d(LOG_TAG, "result = " + result); |
| 12787 | return result; |
| 12788 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12789 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12790 | /** |
| 12791 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12792 | * including carrier config, entitlement server, and config update. |
| 12793 | * |
| 12794 | * @param subId subId The subscription ID of the carrier. |
| 12795 | * |
| 12796 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12797 | * be returned. |
| 12798 | * |
| 12799 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12800 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12801 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12802 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12803 | final long identity = Binder.clearCallingIdentity(); |
| 12804 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12805 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12806 | } finally { |
| 12807 | Binder.restoreCallingIdentity(identity); |
| 12808 | } |
| 12809 | } |
| 12810 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12811 | @Override |
| 12812 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12813 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12814 | mApp.enforceCallingOrSelfPermission( |
| 12815 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12816 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12817 | |
| 12818 | final long identity = Binder.clearCallingIdentity(); |
| 12819 | try { |
| 12820 | Phone phone = getPhone(subId); |
| 12821 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12822 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12823 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12824 | phone.setVoiceServiceStateOverride(hasService); |
| 12825 | } finally { |
| 12826 | Binder.restoreCallingIdentity(identity); |
| 12827 | } |
| 12828 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12829 | |
| 12830 | /** |
| 12831 | * set removable eSIM as default eUICC. |
| 12832 | * |
| 12833 | * @hide |
| 12834 | */ |
| 12835 | @Override |
| 12836 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12837 | enforceModifyPermission(); |
| 12838 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12839 | |
| 12840 | final long identity = Binder.clearCallingIdentity(); |
| 12841 | try { |
| 12842 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12843 | } finally { |
| 12844 | Binder.restoreCallingIdentity(identity); |
| 12845 | } |
| 12846 | } |
| 12847 | |
| 12848 | /** |
| 12849 | * Returns whether the removable eSIM is default eUICC or not. |
| 12850 | * |
| 12851 | * @hide |
| 12852 | */ |
| 12853 | @Override |
| 12854 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12855 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12856 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12857 | |
| 12858 | final long identity = Binder.clearCallingIdentity(); |
| 12859 | try { |
| 12860 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12861 | } finally { |
| 12862 | Binder.restoreCallingIdentity(identity); |
| 12863 | } |
| 12864 | } |
| 12865 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12866 | /** |
| 12867 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12868 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12869 | * application currently configured for this user. |
| 12870 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12871 | * {@code null} if the functionality is not supported. |
| 12872 | * @hide |
| 12873 | */ |
| 12874 | @Override |
| 12875 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12876 | boolean updateIfNeeded) { |
| 12877 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12878 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12879 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12880 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12881 | "getDefaultRespondViaMessageApplication"); |
| 12882 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12883 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12884 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12885 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12886 | UserHandle mainUser = null; |
| 12887 | Context userContext = null; |
| 12888 | final long identity = Binder.clearCallingIdentity(); |
| 12889 | try { |
| 12890 | mainUser = mUserManager.getMainUser(); |
| 12891 | userContext = context.createContextAsUser(mainUser, 0); |
| 12892 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12893 | } finally { |
| 12894 | Binder.restoreCallingIdentity(identity); |
| 12895 | } |
| 12896 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12897 | updateIfNeeded, mainUser); |
| 12898 | } else { |
| 12899 | UserHandle userHandle = null; |
| 12900 | final long identity = Binder.clearCallingIdentity(); |
| 12901 | try { |
| 12902 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12903 | } finally { |
| 12904 | Binder.restoreCallingIdentity(identity); |
| 12905 | } |
| 12906 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12907 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12908 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12909 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12910 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12911 | |
| 12912 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12913 | * Set whether the device is able to connect with null ciphering or integrity |
| 12914 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12915 | * and all new subscriptions after this. |
| 12916 | * |
| 12917 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12918 | * @hide |
| 12919 | */ |
| 12920 | @Override |
| 12921 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12922 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12923 | enforceModifyPermission(); |
| 12924 | checkForNullCipherAndIntegritySupport(); |
| 12925 | |
| 12926 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12927 | // for listening to these preference changes and applying them immediately. |
| 12928 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12929 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12930 | editor.apply(); |
| 12931 | |
| 12932 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12933 | phone.handleNullCipherEnabledChange(); |
| 12934 | } |
| 12935 | } |
| 12936 | |
| 12937 | |
| 12938 | /** |
| 12939 | * Get whether the device is able to connect with null ciphering or integrity |
| 12940 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12941 | * the state of the radio. |
| 12942 | * |
| 12943 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12944 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12945 | * version for this feature. |
| 12946 | * @hide |
| 12947 | */ |
| 12948 | @Override |
| 12949 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12950 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12951 | enforceReadPermission(); |
| 12952 | checkForNullCipherAndIntegritySupport(); |
| 12953 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12954 | } |
| 12955 | |
| 12956 | private void checkForNullCipherAndIntegritySupport() { |
| 12957 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12958 | throw new UnsupportedOperationException( |
| 12959 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12960 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12961 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12962 | throw new UnsupportedOperationException( |
| 12963 | "Null cipher and integrity operations unsupported by modem"); |
| 12964 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12965 | } |
| 12966 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12967 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12968 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12969 | throw new UnsupportedOperationException( |
| 12970 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12971 | + "above"); |
| 12972 | } |
| 12973 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12974 | throw new UnsupportedOperationException( |
| 12975 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12976 | } |
| 12977 | } |
| 12978 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12979 | private void checkForNullCipherNotificationSupport() { |
| 12980 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12981 | throw new UnsupportedOperationException( |
| 12982 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12983 | } |
| 12984 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12985 | throw new UnsupportedOperationException( |
| 12986 | "Null cipher notification operations unsupported by modem"); |
| 12987 | } |
| 12988 | } |
| 12989 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12990 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12991 | * Get the SIM state for the slot index. |
| 12992 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12993 | * |
| 12994 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12995 | */ |
| 12996 | @Override |
| 12997 | @SimState |
| 12998 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 12999 | if (!mApp.getResources().getBoolean( |
| 13000 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 13001 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13002 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13003 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13004 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13005 | IccCardConstants.State simState; |
| 13006 | if (slotIndex < 0) { |
| 13007 | simState = IccCardConstants.State.UNKNOWN; |
| 13008 | } else { |
| 13009 | Phone phone = null; |
| 13010 | try { |
| 13011 | phone = PhoneFactory.getPhone(slotIndex); |
| 13012 | } catch (IllegalStateException e) { |
| 13013 | // ignore |
| 13014 | } |
| 13015 | if (phone == null) { |
| 13016 | simState = IccCardConstants.State.UNKNOWN; |
| 13017 | } else { |
| 13018 | IccCard icc = phone.getIccCard(); |
| 13019 | if (icc == null) { |
| 13020 | simState = IccCardConstants.State.UNKNOWN; |
| 13021 | } else { |
| 13022 | simState = icc.getState(); |
| 13023 | } |
| 13024 | } |
| 13025 | } |
| 13026 | return simState.ordinal(); |
| 13027 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13028 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13029 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13030 | boolean enableLogcat, |
| 13031 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13032 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13033 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13034 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13035 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13036 | ecdDataBuilder |
| 13037 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13038 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13039 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13040 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13041 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13042 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13043 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13044 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13045 | Executors.newCachedThreadPool(), db, |
| 13046 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13047 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13048 | } |
| 13049 | |
| 13050 | /** |
| 13051 | * Request telephony to persist state for debugging emergency call failures. |
| 13052 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13053 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13054 | * @param enableLogcat whether to collect logcat output |
| 13055 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13056 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13057 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13058 | */ |
| 13059 | @Override |
| 13060 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13061 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13062 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13063 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13064 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13065 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13066 | && Flags.enableReadDropboxPermission()) { |
| 13067 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13068 | "persistEmergencyCallDiagnosticData"); |
| 13069 | } else { |
| 13070 | // Otherwise, enforce legacy permission. |
| 13071 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13072 | "persistEmergencyCallDiagnosticData"); |
| 13073 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13074 | final long identity = Binder.clearCallingIdentity(); |
| 13075 | try { |
| 13076 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13077 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13078 | |
| 13079 | } finally { |
| 13080 | Binder.restoreCallingIdentity(identity); |
| 13081 | } |
| 13082 | } |
| 13083 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13084 | /** |
| 13085 | * Get current cell broadcast ranges. |
| 13086 | */ |
| 13087 | @Override |
| 13088 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13089 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13090 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13091 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13092 | |
| 13093 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13094 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13095 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13096 | final long identity = Binder.clearCallingIdentity(); |
| 13097 | try { |
| 13098 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13099 | } finally { |
| 13100 | Binder.restoreCallingIdentity(identity); |
| 13101 | } |
| 13102 | } |
| 13103 | |
| 13104 | /** |
| 13105 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13106 | * |
| 13107 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13108 | */ |
| 13109 | @Override |
| 13110 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13111 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13112 | @Nullable IIntegerConsumer callback) { |
| 13113 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13114 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13115 | |
| 13116 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13117 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13118 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13119 | final long identity = Binder.clearCallingIdentity(); |
| 13120 | try { |
| 13121 | Phone phone = getPhoneFromSubId(subId); |
| 13122 | if (DBG) { |
| 13123 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13124 | } |
| 13125 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13126 | if (callback != null) { |
| 13127 | try { |
| 13128 | callback.accept(result); |
| 13129 | } catch (RemoteException e) { |
| 13130 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13131 | } |
| 13132 | } |
| 13133 | }); |
| 13134 | } finally { |
| 13135 | Binder.restoreCallingIdentity(identity); |
| 13136 | } |
| 13137 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13138 | |
| 13139 | /** |
| 13140 | * Returns whether the device supports the domain selection service. |
| 13141 | * |
| 13142 | * @return {@code true} if the device supports the domain selection service. |
| 13143 | */ |
| 13144 | @Override |
| 13145 | public boolean isDomainSelectionSupported() { |
| 13146 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13147 | "isDomainSelectionSupported"); |
| 13148 | |
| 13149 | final long identity = Binder.clearCallingIdentity(); |
| 13150 | try { |
| 13151 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13152 | } finally { |
| 13153 | Binder.restoreCallingIdentity(identity); |
| 13154 | } |
| 13155 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13156 | |
| 13157 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13158 | * Returns whether the AOSP domain selection service is supported. |
| 13159 | * |
| 13160 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13161 | * {@code false} otherwise. |
| 13162 | */ |
| 13163 | @Override |
| 13164 | public boolean isAospDomainSelectionService() { |
| 13165 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13166 | "isAospDomainSelectionService"); |
| 13167 | |
| 13168 | final long identity = Binder.clearCallingIdentity(); |
| 13169 | try { |
| 13170 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13171 | String dssComponentName = mApp.getResources().getString( |
| 13172 | R.string.config_domain_selection_service_component_name); |
| 13173 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13174 | TelephonyDomainSelectionService.class.getName()); |
| 13175 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13176 | + ", aosp=" + componentName.flattenToString()); |
| 13177 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13178 | } |
| 13179 | } finally { |
| 13180 | Binder.restoreCallingIdentity(identity); |
| 13181 | } |
| 13182 | return false; |
| 13183 | } |
| 13184 | |
| 13185 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13186 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13187 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13188 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13189 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13190 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13191 | * {@code false} to disable. |
| 13192 | * @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] | 13193 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13194 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13195 | * |
| 13196 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13197 | */ |
| 13198 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13199 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13200 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13201 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13202 | final long identity = Binder.clearCallingIdentity(); |
| 13203 | try { |
| 13204 | if (enableSatellite) { |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13205 | String caller = "PIM:requestSatelliteEnabled"; |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 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); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13211 | mSatelliteController.decrementResultReceiverCount(caller); |
| 13212 | |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13213 | boolean isAllowed = false; |
| 13214 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13215 | callback::accept); |
| 13216 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13217 | if (resultData != null |
| 13218 | && resultData.containsKey( |
| 13219 | KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13220 | isAllowed = resultData.getBoolean( |
| 13221 | KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13222 | } else { |
| 13223 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13224 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13225 | } else { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13226 | result.accept(resultCode); |
| 13227 | return; |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13228 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13229 | if (isAllowed) { |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13230 | if (mFeatureFlags.carrierRoamingNbIotNtn() |
| 13231 | && !mSatelliteAccessController.getSatelliteDisallowedReasons() |
| 13232 | .isEmpty()) { |
| 13233 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13234 | } else { |
| 13235 | mSatelliteController.requestSatelliteEnabled( |
| 13236 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13237 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13238 | } else { |
| 13239 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13240 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13241 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13242 | }; |
| 13243 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
| 13244 | resultReceiver, true); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13245 | mSatelliteController.incrementResultReceiverCount(caller); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13246 | } else { |
| 13247 | // No need to check if satellite is allowed at current location when disabling |
| 13248 | // satellite |
| 13249 | mSatelliteController.requestSatelliteEnabled( |
| 13250 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13251 | } |
| 13252 | } finally { |
| 13253 | Binder.restoreCallingIdentity(identity); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13254 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13255 | } |
| 13256 | |
| 13257 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13258 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13259 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13260 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13261 | * 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] | 13262 | * |
| 13263 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13264 | */ |
| 13265 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13266 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13267 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13268 | final long identity = Binder.clearCallingIdentity(); |
| 13269 | try { |
| 13270 | mSatelliteController.requestIsSatelliteEnabled(result); |
| 13271 | } finally { |
| 13272 | Binder.restoreCallingIdentity(identity); |
| 13273 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13274 | } |
| 13275 | |
| 13276 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13277 | * Request to get whether the satellite service demo mode is enabled. |
| 13278 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13279 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13280 | * if the request is successful or an error code if the request failed. |
| 13281 | * |
| 13282 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13283 | */ |
| 13284 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13285 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13286 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13287 | final long identity = Binder.clearCallingIdentity(); |
| 13288 | try { |
| 13289 | mSatelliteController.requestIsDemoModeEnabled(result); |
| 13290 | } finally { |
| 13291 | Binder.restoreCallingIdentity(identity); |
| 13292 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13293 | } |
| 13294 | |
| 13295 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13296 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13297 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13298 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13299 | * enabled if the request is successful or an error code if the request failed. |
| 13300 | * |
| 13301 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13302 | */ |
| 13303 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13304 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13305 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13306 | final long identity = Binder.clearCallingIdentity(); |
| 13307 | try { |
| 13308 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
| 13309 | } finally { |
| 13310 | Binder.restoreCallingIdentity(identity); |
| 13311 | } |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13312 | } |
| 13313 | |
| 13314 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13315 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13316 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13317 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13318 | * 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] | 13319 | * |
| 13320 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13321 | */ |
| 13322 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13323 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13324 | enforceSatelliteCommunicationPermission("requestIsSatelliteSupported"); |
| 13325 | final long identity = Binder.clearCallingIdentity(); |
| 13326 | try { |
| 13327 | mSatelliteController.requestIsSatelliteSupported(result); |
| 13328 | } finally { |
| 13329 | Binder.restoreCallingIdentity(identity); |
| 13330 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13331 | } |
| 13332 | |
| 13333 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13334 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13335 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13336 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13337 | * 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] | 13338 | * |
| 13339 | * @throws SecurityException if the caller doesn't have required permission. |
| 13340 | */ |
| 13341 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13342 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13343 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13344 | final long identity = Binder.clearCallingIdentity(); |
| 13345 | try { |
| 13346 | mSatelliteController.requestSatelliteCapabilities(result); |
| 13347 | } finally { |
| 13348 | Binder.restoreCallingIdentity(identity); |
| 13349 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13350 | } |
| 13351 | |
| 13352 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13353 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13354 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13355 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13356 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13357 | * @param resultCallback The callback to get the result of the request. |
| 13358 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13359 | * |
| 13360 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13361 | */ |
| 13362 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13363 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13364 | @NonNull IIntegerConsumer resultCallback, |
| 13365 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13366 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13367 | final long identity = Binder.clearCallingIdentity(); |
| 13368 | try { |
| 13369 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
| 13370 | } finally { |
| 13371 | Binder.restoreCallingIdentity(identity); |
| 13372 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13373 | } |
| 13374 | |
| 13375 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13376 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13377 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13378 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13379 | * @param resultCallback The callback to get the result of the request. |
| 13380 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13381 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13382 | * |
| 13383 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13384 | */ |
| 13385 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13386 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13387 | @NonNull IIntegerConsumer resultCallback, |
| 13388 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13389 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13390 | final long identity = Binder.clearCallingIdentity(); |
| 13391 | try { |
| 13392 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
| 13393 | } finally { |
| 13394 | Binder.restoreCallingIdentity(identity); |
| 13395 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13396 | } |
| 13397 | |
| 13398 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13399 | * Register the subscription with a satellite provider. |
| 13400 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13401 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13402 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13403 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13404 | * @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] | 13405 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13406 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13407 | * @return The signal transport used by the caller to cancel the provision request, |
| 13408 | * or {@code null} if the request failed. |
| 13409 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13410 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13411 | */ |
| 13412 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13413 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13414 | @NonNull String token, @NonNull byte[] provisionData, |
| 13415 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13416 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13417 | final long identity = Binder.clearCallingIdentity(); |
| 13418 | try { |
| 13419 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13420 | callback); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13421 | } finally { |
| 13422 | Binder.restoreCallingIdentity(identity); |
| 13423 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13424 | } |
| 13425 | |
| 13426 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13427 | * Unregister the device/subscription with the satellite provider. |
| 13428 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13429 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13430 | * should report as deprovisioned. |
| 13431 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13432 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13433 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13434 | * |
| 13435 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13436 | */ |
| 13437 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13438 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13439 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13440 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13441 | final long identity = Binder.clearCallingIdentity(); |
| 13442 | try { |
| 13443 | mSatelliteController.deprovisionSatelliteService(token, callback); |
| 13444 | } finally { |
| 13445 | Binder.restoreCallingIdentity(identity); |
| 13446 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13447 | } |
| 13448 | |
| 13449 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13450 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13451 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13452 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13453 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13454 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13455 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13456 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13457 | */ |
| 13458 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13459 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13460 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13461 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13462 | final long identity = Binder.clearCallingIdentity(); |
| 13463 | try { |
| 13464 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
| 13465 | } finally { |
| 13466 | Binder.restoreCallingIdentity(identity); |
| 13467 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13468 | } |
| 13469 | |
| 13470 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13471 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13472 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13473 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13474 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13475 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13476 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13477 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13478 | */ |
| 13479 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13480 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13481 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13482 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13483 | final long identity = Binder.clearCallingIdentity(); |
| 13484 | try { |
| 13485 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
| 13486 | } finally { |
| 13487 | Binder.restoreCallingIdentity(identity); |
| 13488 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13489 | } |
| 13490 | |
| 13491 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13492 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13493 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13494 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13495 | * satellite provider if the request is successful or an error code if the |
| 13496 | * request failed. |
| 13497 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13498 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13499 | */ |
| 13500 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13501 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13502 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13503 | final long identity = Binder.clearCallingIdentity(); |
| 13504 | try { |
| 13505 | mSatelliteController.requestIsSatelliteProvisioned(result); |
| 13506 | } finally { |
| 13507 | Binder.restoreCallingIdentity(identity); |
| 13508 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13509 | } |
| 13510 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13511 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13512 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13513 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13514 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13515 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13516 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13517 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13518 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13519 | */ |
| 13520 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13521 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13522 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13523 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13524 | final long identity = Binder.clearCallingIdentity(); |
| 13525 | try { |
| 13526 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
| 13527 | } finally { |
| 13528 | Binder.restoreCallingIdentity(identity); |
| 13529 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13530 | } |
| 13531 | |
| 13532 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13533 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13534 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13535 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13536 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13537 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13538 | * |
| 13539 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13540 | */ |
| 13541 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13542 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13543 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13544 | final long identity = Binder.clearCallingIdentity(); |
| 13545 | try { |
| 13546 | mSatelliteController.unregisterForModemStateChanged(callback); |
| 13547 | } finally { |
| 13548 | Binder.restoreCallingIdentity(identity); |
| 13549 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13550 | } |
| 13551 | |
| 13552 | /** |
| 13553 | * Register to receive incoming datagrams over satellite. |
| 13554 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13555 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13556 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13557 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13558 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13559 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13560 | */ |
| 13561 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13562 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13563 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13564 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13565 | final long identity = Binder.clearCallingIdentity(); |
| 13566 | try { |
| 13567 | return mSatelliteController.registerForIncomingDatagram(callback); |
| 13568 | } finally { |
| 13569 | Binder.restoreCallingIdentity(identity); |
| 13570 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13571 | } |
| 13572 | |
| 13573 | /** |
| 13574 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13575 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13576 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13577 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13578 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13579 | * |
| 13580 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13581 | */ |
| 13582 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13583 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13584 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13585 | final long identity = Binder.clearCallingIdentity(); |
| 13586 | try { |
| 13587 | mSatelliteController.unregisterForIncomingDatagram(callback); |
| 13588 | } finally { |
| 13589 | Binder.restoreCallingIdentity(identity); |
| 13590 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13591 | } |
| 13592 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13593 | /** |
| 13594 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13595 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13596 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13597 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13598 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13599 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13600 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13601 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13602 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13603 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13604 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13605 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13606 | final long identity = Binder.clearCallingIdentity(); |
| 13607 | try { |
| 13608 | mSatelliteController.pollPendingDatagrams(callback); |
| 13609 | } finally { |
| 13610 | Binder.restoreCallingIdentity(identity); |
| 13611 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13612 | } |
| 13613 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13614 | /** |
| 13615 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13616 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13617 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13618 | * input to this method. Datagram received here will be passed down to modem without any |
| 13619 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13620 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13621 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13622 | * SOS_SMS or LOCATION_SHARING. |
| 13623 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13624 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13625 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13626 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13627 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13628 | * |
| 13629 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13630 | */ |
| 13631 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13632 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13633 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13634 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13635 | enforceSatelliteCommunicationPermission("sendDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13636 | final long identity = Binder.clearCallingIdentity(); |
| 13637 | try { |
| 13638 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
| 13639 | callback); |
| 13640 | } finally { |
| 13641 | Binder.restoreCallingIdentity(identity); |
| 13642 | } |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13643 | } |
| 13644 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13645 | /** |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13646 | * Returns integer array of disallowed reasons of satellite. |
| 13647 | * |
| 13648 | * @return Integer array of disallowed reasons of satellite. |
| 13649 | * |
| 13650 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13651 | */ |
| 13652 | @NonNull public int[] getSatelliteDisallowedReasons() { |
| 13653 | enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons"); |
| 13654 | final long identity = Binder.clearCallingIdentity(); |
| 13655 | try { |
| 13656 | return mSatelliteAccessController.getSatelliteDisallowedReasons() |
| 13657 | .stream().mapToInt(Integer::intValue).toArray(); |
| 13658 | } finally { |
| 13659 | Binder.restoreCallingIdentity(identity); |
| 13660 | } |
| 13661 | } |
| 13662 | |
| 13663 | /** |
| 13664 | * Registers for disallowed reasons change event from satellite service. |
| 13665 | * |
| 13666 | * @param callback The callback to handle disallowed reasons changed event. |
| 13667 | * |
| 13668 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13669 | */ |
| 13670 | @Override |
| 13671 | public void registerForSatelliteDisallowedReasonsChanged( |
| 13672 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13673 | enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged"); |
| 13674 | final long identity = Binder.clearCallingIdentity(); |
| 13675 | try { |
| 13676 | mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback); |
| 13677 | } finally { |
| 13678 | Binder.restoreCallingIdentity(identity); |
| 13679 | } |
| 13680 | } |
| 13681 | |
| 13682 | /** |
| 13683 | * Unregisters for disallowed reasons change event from satellite service. |
| 13684 | * If callback was not registered before, the request will be ignored. |
| 13685 | * |
| 13686 | * @param callback The callback to handle disallowed reasons changed event. |
| 13687 | * {@link #registerForSatelliteDisallowedReasonsChanged( |
| 13688 | * ISatelliteDisallowedReasonsCallback)}. |
| 13689 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13690 | */ |
| 13691 | @Override |
| 13692 | public void unregisterForSatelliteDisallowedReasonsChanged( |
| 13693 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13694 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged"); |
| 13695 | final long identity = Binder.clearCallingIdentity(); |
| 13696 | try { |
| 13697 | mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback); |
| 13698 | } finally { |
| 13699 | Binder.restoreCallingIdentity(identity); |
| 13700 | } |
| 13701 | } |
| 13702 | |
| 13703 | /** |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13704 | * Request to get whether satellite communication is allowed for the current location. |
| 13705 | * |
| 13706 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13707 | * allowed for the current location for. |
| 13708 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13709 | * for the current location if the request is successful or an error code |
| 13710 | * if the request failed. |
| 13711 | * |
| 13712 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13713 | */ |
| 13714 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13715 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13716 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13717 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13718 | final long identity = Binder.clearCallingIdentity(); |
| 13719 | try { |
| 13720 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, |
| 13721 | false); |
| 13722 | } finally { |
| 13723 | Binder.restoreCallingIdentity(identity); |
| 13724 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13725 | } |
| 13726 | |
| 13727 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13728 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13729 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13730 | * @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] | 13731 | * be visible if the request is successful or an error code if the request failed. |
| 13732 | * |
| 13733 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13734 | */ |
| 13735 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13736 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13737 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13738 | final long identity = Binder.clearCallingIdentity(); |
| 13739 | try { |
| 13740 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
| 13741 | } finally { |
| 13742 | Binder.restoreCallingIdentity(identity); |
| 13743 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13744 | } |
| 13745 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13746 | /** |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13747 | * 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] | 13748 | * |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13749 | * @param isAligned {@code true} Device is aligned with the satellite. |
| 13750 | * {@code false} Device fails to align with the satellite. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13751 | * |
| 13752 | * @throws SecurityException if the caller doesn't have required permission. |
| 13753 | */ |
| 13754 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13755 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13756 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13757 | enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite"); |
| 13758 | final long identity = Binder.clearCallingIdentity(); |
| 13759 | try { |
| 13760 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
| 13761 | } finally { |
| 13762 | Binder.restoreCallingIdentity(identity); |
| 13763 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13764 | } |
| 13765 | |
| 13766 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13767 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13768 | * by modem. |
| 13769 | * |
| 13770 | * @param subId The subId of the subscription to request for. |
| 13771 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13772 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13773 | * operation. |
| 13774 | * |
| 13775 | * @throws SecurityException if the caller doesn't have required permission. |
| 13776 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13777 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13778 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13779 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13780 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13781 | final long identity = Binder.clearCallingIdentity(); |
| 13782 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13783 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13784 | } finally { |
| 13785 | Binder.restoreCallingIdentity(identity); |
| 13786 | } |
| 13787 | } |
| 13788 | |
| 13789 | /** |
| 13790 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13791 | * by modem. |
| 13792 | * |
| 13793 | * @param subId The subId of the subscription to request for. |
| 13794 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13795 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13796 | * operation. |
| 13797 | * |
| 13798 | * @throws SecurityException if the caller doesn't have required permission. |
| 13799 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13800 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13801 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13802 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13803 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13804 | final long identity = Binder.clearCallingIdentity(); |
| 13805 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13806 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13807 | } finally { |
| 13808 | Binder.restoreCallingIdentity(identity); |
| 13809 | } |
| 13810 | } |
| 13811 | |
| 13812 | /** |
| 13813 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13814 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13815 | * |
| 13816 | * @param subId The subId of the subscription to request for. |
| 13817 | * |
| 13818 | * @return Integer array of reasons for disallowing satellite communication. |
| 13819 | * |
| 13820 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13821 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13822 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13823 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13824 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13825 | final long identity = Binder.clearCallingIdentity(); |
| 13826 | try { |
| 13827 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13828 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13829 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13830 | } finally { |
| 13831 | Binder.restoreCallingIdentity(identity); |
| 13832 | } |
| 13833 | } |
| 13834 | |
| 13835 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13836 | * Request to get the signal strength of the satellite connection. |
| 13837 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13838 | * @param result Result receiver to get the error code of the request and the current signal |
| 13839 | * strength of the satellite connection. |
| 13840 | * |
| 13841 | * @throws SecurityException if the caller doesn't have required permission. |
| 13842 | */ |
| 13843 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13844 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13845 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13846 | final long identity = Binder.clearCallingIdentity(); |
| 13847 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13848 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13849 | } finally { |
| 13850 | Binder.restoreCallingIdentity(identity); |
| 13851 | } |
| 13852 | } |
| 13853 | |
| 13854 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13855 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13856 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13857 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13858 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13859 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13860 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13861 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13862 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13863 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13864 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13865 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13866 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13867 | */ |
| 13868 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13869 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13870 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13871 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13872 | final long identity = Binder.clearCallingIdentity(); |
| 13873 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13874 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13875 | } finally { |
| 13876 | Binder.restoreCallingIdentity(identity); |
| 13877 | } |
| 13878 | } |
| 13879 | |
| 13880 | /** |
| 13881 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13882 | * If callback was not registered before, the request will be ignored. |
| 13883 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13884 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13885 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13886 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13887 | * |
| 13888 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13889 | */ |
| 13890 | @Override |
| 13891 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13892 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13893 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13894 | final long identity = Binder.clearCallingIdentity(); |
| 13895 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13896 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13897 | } finally { |
| 13898 | Binder.restoreCallingIdentity(identity); |
| 13899 | } |
| 13900 | } |
| 13901 | |
| 13902 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13903 | * Registers for satellite capabilities change event from the satellite service. |
| 13904 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13905 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13906 | * |
| 13907 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13908 | * |
| 13909 | * @throws SecurityException if the caller doesn't have required permission. |
| 13910 | */ |
| 13911 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13912 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13913 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13914 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13915 | final long identity = Binder.clearCallingIdentity(); |
| 13916 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13917 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13918 | } finally { |
| 13919 | Binder.restoreCallingIdentity(identity); |
| 13920 | } |
| 13921 | } |
| 13922 | |
| 13923 | /** |
| 13924 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13925 | * If callback was not registered before, the request will be ignored. |
| 13926 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13927 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13928 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13929 | * |
| 13930 | * @throws SecurityException if the caller doesn't have required permission. |
| 13931 | */ |
| 13932 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13933 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13934 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13935 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13936 | final long identity = Binder.clearCallingIdentity(); |
| 13937 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13938 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13939 | } finally { |
| 13940 | Binder.restoreCallingIdentity(identity); |
| 13941 | } |
| 13942 | } |
| 13943 | |
| 13944 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13945 | * Registers for the satellite supported state changed. |
| 13946 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13947 | * @param callback The callback to handle the satellite supported state changed event. |
| 13948 | * |
| 13949 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13950 | * |
| 13951 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13952 | */ |
| 13953 | @Override |
| 13954 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13955 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13956 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13957 | final long identity = Binder.clearCallingIdentity(); |
| 13958 | try { |
| 13959 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
| 13960 | } finally { |
| 13961 | Binder.restoreCallingIdentity(identity); |
| 13962 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13963 | } |
| 13964 | |
| 13965 | /** |
| 13966 | * Unregisters for the satellite supported state changed. |
| 13967 | * If callback was not registered before, the request will be ignored. |
| 13968 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13969 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13970 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13971 | * |
| 13972 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13973 | */ |
| 13974 | @Override |
| 13975 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13976 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13977 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13978 | final long identity = Binder.clearCallingIdentity(); |
| 13979 | try { |
| 13980 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
| 13981 | } finally { |
| 13982 | Binder.restoreCallingIdentity(identity); |
| 13983 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13984 | } |
| 13985 | |
| 13986 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13987 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13988 | * |
| 13989 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13990 | * @param provisioned Whether satellite should be provisioned or not. |
| 13991 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13992 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13993 | * {@code false} otherwise. |
| 13994 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13995 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 13996 | String provisioned) { |
| 13997 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 13998 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13999 | TelephonyPermissions.enforceShellOnly( |
| 14000 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 14001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14002 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14003 | "setSatelliteServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14004 | final long identity = Binder.clearCallingIdentity(); |
| 14005 | try { |
| 14006 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 14007 | provisioned); |
| 14008 | } finally { |
| 14009 | Binder.restoreCallingIdentity(identity); |
| 14010 | } |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14011 | } |
| 14012 | |
| 14013 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14014 | * This API can be used by only CTS to update satellite gateway service package name. |
| 14015 | * |
| 14016 | * @param servicePackageName The package name of the satellite gateway service. |
| 14017 | * @return {@code true} if the satellite gateway service is set successfully, |
| 14018 | * {@code false} otherwise. |
| 14019 | */ |
| 14020 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 14021 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 14022 | TelephonyPermissions.enforceShellOnly( |
| 14023 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 14024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14025 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14026 | "setSatelliteGatewayServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14027 | final long identity = Binder.clearCallingIdentity(); |
| 14028 | try { |
| 14029 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 14030 | } finally { |
| 14031 | Binder.restoreCallingIdentity(identity); |
| 14032 | } |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14033 | } |
| 14034 | |
| 14035 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14036 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 14037 | * |
| 14038 | * @param packageName The package name of the satellite pointing UI app. |
| 14039 | * @param className The class name of the satellite pointing UI app. |
| 14040 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 14041 | * {@code false} otherwise. |
| 14042 | */ |
| 14043 | public boolean setSatellitePointingUiClassName( |
| 14044 | @Nullable String packageName, @Nullable String className) { |
| 14045 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 14046 | + ", className=" + className); |
| 14047 | TelephonyPermissions.enforceShellOnly( |
| 14048 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 14049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14050 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14051 | "setSatellitePointingUiClassName"); |
| 14052 | final long identity = Binder.clearCallingIdentity(); |
| 14053 | try { |
| 14054 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 14055 | } finally { |
| 14056 | Binder.restoreCallingIdentity(identity); |
| 14057 | } |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14058 | } |
| 14059 | |
| 14060 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14061 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 14062 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 14063 | * listening mode. |
| 14064 | * |
| 14065 | * @param timeoutMillis The timeout duration in millisecond. |
| 14066 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14067 | */ |
| 14068 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 14069 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 14070 | TelephonyPermissions.enforceShellOnly( |
| 14071 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 14072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14073 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14074 | "setSatelliteListeningTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14075 | final long identity = Binder.clearCallingIdentity(); |
| 14076 | try { |
| 14077 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 14078 | } finally { |
| 14079 | Binder.restoreCallingIdentity(identity); |
| 14080 | } |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14081 | } |
| 14082 | |
| 14083 | /** |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14084 | * This API can be used by only CTS to control ingoring cellular service state event. |
| 14085 | * |
| 14086 | * @param enabled Whether to enable boolean config. |
| 14087 | * @return {@code true} if the value is set successfully, {@code false} otherwise. |
| 14088 | */ |
| 14089 | public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14090 | Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14091 | TelephonyPermissions.enforceShellOnly( |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14092 | Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState"); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14094 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14095 | "setSatelliteIgnoreCellularServiceState"); |
| 14096 | final long identity = Binder.clearCallingIdentity(); |
| 14097 | try { |
| 14098 | return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled); |
| 14099 | } finally { |
| 14100 | Binder.restoreCallingIdentity(identity); |
| 14101 | } |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14102 | } |
| 14103 | |
| 14104 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14105 | * This API can be used by only CTS to override the timeout durations used by the |
| 14106 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14107 | * |
| 14108 | * @param timeoutMillis The timeout duration in millisecond. |
| 14109 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14110 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14111 | public boolean setDatagramControllerTimeoutDuration( |
| 14112 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14113 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14114 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14115 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14116 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14117 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14118 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14119 | "setDatagramControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14120 | final long identity = Binder.clearCallingIdentity(); |
| 14121 | try { |
| 14122 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 14123 | reset, timeoutType, timeoutMillis); |
| 14124 | } finally { |
| 14125 | Binder.restoreCallingIdentity(identity); |
| 14126 | } |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14127 | } |
| 14128 | |
| 14129 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14130 | * This API can be used by only CTS to override the boolean configs used by the |
| 14131 | * DatagramController module. |
| 14132 | * |
| 14133 | * @param enable Whether to enable or disable boolean config. |
| 14134 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 14135 | */ |
| 14136 | public boolean setDatagramControllerBooleanConfig( |
| 14137 | boolean reset, int booleanType, boolean enable) { |
| 14138 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 14139 | + ", reset=" + reset + ", enable=" + enable); |
| 14140 | TelephonyPermissions.enforceShellOnly( |
| 14141 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 14142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14143 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14144 | "ssetDatagramControllerBooleanConfig"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14145 | final long identity = Binder.clearCallingIdentity(); |
| 14146 | try { |
| 14147 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, |
| 14148 | enable); |
| 14149 | } finally { |
| 14150 | Binder.restoreCallingIdentity(identity); |
| 14151 | } |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14152 | } |
| 14153 | |
| 14154 | |
| 14155 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14156 | * This API can be used by only CTS to override the timeout durations used by the |
| 14157 | * SatelliteController module. |
| 14158 | * |
| 14159 | * @param timeoutMillis The timeout duration in millisecond. |
| 14160 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14161 | */ |
| 14162 | public boolean setSatelliteControllerTimeoutDuration( |
| 14163 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14164 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14165 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 14166 | TelephonyPermissions.enforceShellOnly( |
| 14167 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 14168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14169 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14170 | "setSatelliteControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14171 | final long identity = Binder.clearCallingIdentity(); |
| 14172 | try { |
| 14173 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 14174 | reset, timeoutType, timeoutMillis); |
| 14175 | } finally { |
| 14176 | Binder.restoreCallingIdentity(identity); |
| 14177 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14178 | } |
| 14179 | |
| 14180 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14181 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 14182 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 14183 | * |
| 14184 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 14185 | * of the following values to enable the override: |
| 14186 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 14187 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 14188 | * To disable the override, use -1 for handoverType. |
| 14189 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 14190 | * delaySeconds after the emergency call starts. |
| 14191 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 14192 | */ |
| 14193 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 14194 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 14195 | TelephonyPermissions.enforceShellOnly( |
| 14196 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 14197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14198 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14199 | "setEmergencyCallToSatelliteHandoverType"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14200 | final long identity = Binder.clearCallingIdentity(); |
| 14201 | try { |
| 14202 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 14203 | handoverType, delaySeconds); |
| 14204 | } finally { |
| 14205 | Binder.restoreCallingIdentity(identity); |
| 14206 | } |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14207 | } |
| 14208 | |
| 14209 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14210 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 14211 | * |
| 14212 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 14213 | * otherwise. |
| 14214 | * @param isProvisioned The overriding provision status. |
| 14215 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 14216 | */ |
| 14217 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 14218 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 14219 | + ", isProvisioned=" + isProvisioned); |
| 14220 | TelephonyPermissions.enforceShellOnly( |
| 14221 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 14222 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14223 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14224 | "setOemEnabledSatelliteProvisionStatus"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14225 | final long identity = Binder.clearCallingIdentity(); |
| 14226 | try { |
| 14227 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 14228 | } finally { |
| 14229 | Binder.restoreCallingIdentity(identity); |
| 14230 | } |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14231 | } |
| 14232 | |
| 14233 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14234 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 14235 | * |
| 14236 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 14237 | */ |
| 14238 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 14239 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 14240 | long locationCountryCodeTimestampNanos) { |
| 14241 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 14242 | + String.join(", ", currentNetworkCountryCodes) |
| 14243 | + ", locationCountryCode=" + locationCountryCode |
| 14244 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 14245 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 14246 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14247 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14249 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes"); |
| 14250 | final long identity = Binder.clearCallingIdentity(); |
| 14251 | try { |
| 14252 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), |
| 14253 | mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes, |
| 14254 | cachedNetworkCountryCodes, locationCountryCode, |
| 14255 | locationCountryCodeTimestampNanos); |
| 14256 | } finally { |
| 14257 | Binder.restoreCallingIdentity(identity); |
| 14258 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14259 | } |
| 14260 | |
| 14261 | /** |
| 14262 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 14263 | * access controller. |
| 14264 | * |
| 14265 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 14266 | * otherwise. |
| 14267 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 14268 | */ |
| 14269 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14270 | String s2CellFile, long locationFreshDurationNanos, |
| 14271 | List<String> satelliteCountryCodes) { |
| 14272 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14273 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14274 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14275 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 14276 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 14277 | TelephonyPermissions.enforceShellOnly( |
| 14278 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14279 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14280 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14281 | "setSatelliteAccessControlOverlayConfigs"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14282 | final long identity = Binder.clearCallingIdentity(); |
| 14283 | try { |
| 14284 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, |
| 14285 | isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 14286 | } finally { |
| 14287 | Binder.restoreCallingIdentity(identity); |
| 14288 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14289 | } |
| 14290 | |
| 14291 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14292 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14293 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14294 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14295 | * |
| 14296 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14297 | * satellite modem or not. |
| 14298 | * |
| 14299 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14300 | */ |
| 14301 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14302 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14303 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14304 | + "disabled"); |
| 14305 | return false; |
| 14306 | } |
| 14307 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14308 | TelephonyPermissions.enforceShellOnly( |
| 14309 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14311 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14312 | "setShouldSendDatagramToModemInDemoMode"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14313 | final long identity = Binder.clearCallingIdentity(); |
| 14314 | try { |
| 14315 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14316 | shouldSendToModemInDemoMode); |
| 14317 | } finally { |
| 14318 | Binder.restoreCallingIdentity(identity); |
| 14319 | } |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14320 | } |
| 14321 | |
| 14322 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14323 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14324 | * |
| 14325 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14326 | * the allowed state. |
| 14327 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14328 | */ |
| 14329 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14330 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14331 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14332 | + "oemEnabledSatelliteFlag is disabled"); |
| 14333 | return false; |
| 14334 | } |
| 14335 | |
| 14336 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14337 | + "state=" + state); |
| 14338 | TelephonyPermissions.enforceShellOnly( |
| 14339 | Binder.getCallingUid(), |
| 14340 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14342 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14343 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14344 | final long identity = Binder.clearCallingIdentity(); |
| 14345 | try { |
| 14346 | return mSatelliteAccessController |
| 14347 | .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state); |
| 14348 | } finally { |
| 14349 | Binder.restoreCallingIdentity(identity); |
| 14350 | } |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14351 | } |
| 14352 | |
| 14353 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14354 | * Sets the service defined in ComponentName to be bound. |
| 14355 | * |
| 14356 | * This should only be used for testing. |
| 14357 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14358 | * {@code false} otherwise. |
| 14359 | */ |
| 14360 | @Override |
| 14361 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14362 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14363 | |
| 14364 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14365 | "setDomainSelectionServiceOverride"); |
| 14366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14367 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14368 | |
| 14369 | final long identity = Binder.clearCallingIdentity(); |
| 14370 | try { |
| 14371 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14372 | return DomainSelectionResolver.getInstance() |
| 14373 | .setDomainSelectionServiceOverride(componentName); |
| 14374 | } |
| 14375 | } finally { |
| 14376 | Binder.restoreCallingIdentity(identity); |
| 14377 | } |
| 14378 | return false; |
| 14379 | } |
| 14380 | |
| 14381 | /** |
| 14382 | * Clears the DomainSelectionService override. |
| 14383 | * |
| 14384 | * This should only be used for testing. |
| 14385 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14386 | * {@code false} otherwise. |
| 14387 | */ |
| 14388 | @Override |
| 14389 | public boolean clearDomainSelectionServiceOverride() { |
| 14390 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14391 | |
| 14392 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14393 | "clearDomainSelectionServiceOverride"); |
| 14394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14395 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14396 | |
| 14397 | final long identity = Binder.clearCallingIdentity(); |
| 14398 | try { |
| 14399 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14400 | return DomainSelectionResolver.getInstance() |
| 14401 | .clearDomainSelectionServiceOverride(); |
| 14402 | } |
| 14403 | } finally { |
| 14404 | Binder.restoreCallingIdentity(identity); |
| 14405 | } |
| 14406 | return false; |
| 14407 | } |
| 14408 | |
| 14409 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14410 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14411 | * |
| 14412 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14413 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14414 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14415 | * |
| 14416 | * @param enable if notifications about disclosure events should be enabled |
| 14417 | * @throws SecurityException if the caller does not have the required privileges |
| 14418 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14419 | */ |
| 14420 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14421 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14422 | enforceModifyPermission(); |
| 14423 | checkForIdentifierDisclosureNotificationSupport(); |
| 14424 | |
| 14425 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14426 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14427 | editor.apply(); |
| 14428 | |
| 14429 | // Each phone instance is responsible for updating its respective modem immediately |
| 14430 | // after we've made a preference change. |
| 14431 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14432 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14433 | } |
| 14434 | } |
| 14435 | |
| 14436 | /** |
| 14437 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14438 | * |
| 14439 | * @throws SecurityException if the caller does not have the required privileges |
| 14440 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14441 | */ |
| 14442 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14443 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14444 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14445 | checkForIdentifierDisclosureNotificationSupport(); |
| 14446 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14447 | } |
| 14448 | |
| 14449 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14450 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14451 | * are in use by the cellular modem. |
| 14452 | * |
| 14453 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14454 | * @throws SecurityException if the caller does not have the required privileges |
| 14455 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14456 | * and integrity algorithms in use |
| 14457 | * @hide |
| 14458 | */ |
| 14459 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14460 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14461 | enforceModifyPermission(); |
| 14462 | checkForNullCipherNotificationSupport(); |
| 14463 | |
| 14464 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14465 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14466 | editor.apply(); |
| 14467 | |
| 14468 | // Each phone instance is responsible for updating its respective modem immediately |
| 14469 | // after a preference change. |
| 14470 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14471 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14472 | } |
| 14473 | } |
| 14474 | |
| 14475 | /** |
| 14476 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14477 | * cellular modem. |
| 14478 | * |
| 14479 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14480 | * @throws SecurityException if the caller does not have the required privileges |
| 14481 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14482 | * and integrity algorithms in use |
| 14483 | * @hide |
| 14484 | */ |
| 14485 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14486 | public boolean isNullCipherNotificationsEnabled() { |
| 14487 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14488 | checkForNullCipherNotificationSupport(); |
| 14489 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14490 | } |
| 14491 | |
| 14492 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14493 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14494 | * |
| 14495 | * <p>This method behaves in one of the following ways: |
| 14496 | * <ul> |
| 14497 | * <li>return true : if the calling package has the appop permission {@link |
| 14498 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14499 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14500 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14501 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14502 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14503 | * </ul> |
| 14504 | */ |
| 14505 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14506 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14507 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14508 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14509 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14510 | return true; |
| 14511 | } |
| 14512 | } |
| 14513 | return false; |
| 14514 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14515 | |
| 14516 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14517 | * @return The subscription manager service instance. |
| 14518 | */ |
| 14519 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14520 | return SubscriptionManagerService.getInstance(); |
| 14521 | } |
| 14522 | |
| 14523 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14524 | * Class binds the consumer[callback] and carrierId. |
| 14525 | */ |
| 14526 | private static class CallerCallbackInfo { |
| 14527 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14528 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14529 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14530 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14531 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14532 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14533 | } |
| 14534 | |
| 14535 | public Consumer<Integer> getConsumer() { |
| 14536 | return mConsumer; |
| 14537 | } |
| 14538 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14539 | public Set<Integer> getCarrierIds() { |
| 14540 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14541 | } |
| 14542 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14543 | |
| 14544 | /* |
| 14545 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14546 | * But the context that is passed in is unused if the phone app is already alive. |
| 14547 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14548 | */ |
| 14549 | @VisibleForTesting |
| 14550 | public void setPackageManager(PackageManager packageManager) { |
| 14551 | mPackageManager = packageManager; |
| 14552 | } |
| 14553 | |
| 14554 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14555 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14556 | * But the context that is passed in is unused if the phone app is already alive. |
| 14557 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14558 | */ |
| 14559 | @VisibleForTesting |
| 14560 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14561 | mAppOps = appOps; |
| 14562 | } |
| 14563 | |
| 14564 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14565 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14566 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14567 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14568 | */ |
| 14569 | @VisibleForTesting |
| 14570 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14571 | mFeatureFlags = featureFlags; |
| 14572 | } |
| 14573 | |
| 14574 | /** |
| 14575 | * Make sure the device has required telephony feature |
| 14576 | * |
| 14577 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14578 | */ |
| 14579 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14580 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14581 | if (callingPackage == null || mPackageManager == null) { |
| 14582 | return; |
| 14583 | } |
| 14584 | |
| 14585 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14586 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14587 | Binder.getCallingUserHandle()) |
| 14588 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14589 | // Skip to check associated telephony feature, |
| 14590 | // if compatibility change is not enabled for the current process or |
| 14591 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14592 | return; |
| 14593 | } |
| 14594 | |
| 14595 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14596 | throw new UnsupportedOperationException( |
| 14597 | methodName + " is unsupported without " + telephonyFeature); |
| 14598 | } |
| 14599 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14600 | |
| 14601 | /** |
| 14602 | * Registers for the satellite communication allowed state changed. |
| 14603 | * |
| 14604 | * @param subId The subId of the subscription to register for the satellite communication |
| 14605 | * allowed state changed. |
| 14606 | * @param callback The callback to handle the satellite communication allowed |
| 14607 | * state changed event. |
| 14608 | * |
| 14609 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14610 | * |
| 14611 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14612 | */ |
| 14613 | @Override |
| 14614 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14615 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14616 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14617 | final long identity = Binder.clearCallingIdentity(); |
| 14618 | try { |
| 14619 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14620 | subId, callback); |
| 14621 | } finally { |
| 14622 | Binder.restoreCallingIdentity(identity); |
| 14623 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14624 | } |
| 14625 | |
| 14626 | /** |
| 14627 | * Unregisters for the satellite communication allowed state changed. |
| 14628 | * If callback was not registered before, the request will be ignored. |
| 14629 | * |
| 14630 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14631 | * allowed state changed. |
| 14632 | * @param callback The callback that was passed to |
| 14633 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14634 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14635 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14636 | */ |
| 14637 | @Override |
| 14638 | public void unregisterForCommunicationAllowedStateChanged( |
| 14639 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14640 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14641 | final long identity = Binder.clearCallingIdentity(); |
| 14642 | try { |
| 14643 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14644 | callback); |
| 14645 | } finally { |
| 14646 | Binder.restoreCallingIdentity(identity); |
| 14647 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14648 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14649 | |
| 14650 | /** |
| 14651 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14652 | * |
| 14653 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14654 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14655 | * if the request is successful or an error code if the request failed. |
| 14656 | * |
| 14657 | * @throws SecurityException if the caller doesn't have required permission. |
| 14658 | */ |
| 14659 | @Override |
| 14660 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14661 | enforceModifyPermission(); |
| 14662 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14663 | final long identity = Binder.clearCallingIdentity(); |
| 14664 | try { |
| 14665 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14666 | } finally { |
| 14667 | Binder.restoreCallingIdentity(identity); |
| 14668 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14669 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14670 | |
| 14671 | /** |
| 14672 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14673 | * |
| 14674 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14675 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14676 | * |
| 14677 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14678 | */ |
| 14679 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14680 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14681 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14682 | final long identity = Binder.clearCallingIdentity(); |
| 14683 | try { |
| 14684 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14685 | } finally { |
| 14686 | Binder.restoreCallingIdentity(identity); |
| 14687 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14688 | } |
| 14689 | |
| 14690 | /** |
| 14691 | * Deliver the list of provisioned satellite subscriber ids. |
| 14692 | * |
| 14693 | * @param list List of provisioned satellite subscriber ids. |
| 14694 | * @param result The result receiver that returns whether deliver success or fail. |
| 14695 | * |
| 14696 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14697 | */ |
| 14698 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14699 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14700 | @NonNull ResultReceiver result) { |
| 14701 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14702 | final long identity = Binder.clearCallingIdentity(); |
| 14703 | try { |
| 14704 | mSatelliteController.provisionSatellite(list, result); |
| 14705 | } finally { |
| 14706 | Binder.restoreCallingIdentity(identity); |
| 14707 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14708 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14709 | |
| 14710 | /** |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14711 | * Deliver the list of deprovisioned satellite subscriber ids. |
| 14712 | * |
| 14713 | * @param list List of deprovisioned satellite subscriber ids. |
| 14714 | * @param result The result receiver that returns whether deliver success or fail. |
| 14715 | * |
| 14716 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14717 | */ |
| 14718 | @Override |
| 14719 | public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
| 14720 | @NonNull ResultReceiver result) { |
| 14721 | enforceSatelliteCommunicationPermission("deprovisionSatellite"); |
| 14722 | final long identity = Binder.clearCallingIdentity(); |
| 14723 | try { |
| 14724 | mSatelliteController.deprovisionSatellite(list, result); |
| 14725 | } finally { |
| 14726 | Binder.restoreCallingIdentity(identity); |
| 14727 | } |
| 14728 | } |
| 14729 | |
Aishwarya Mallampati | a646bc1 | 2024-11-08 23:33:24 +0000 | [diff] [blame^] | 14730 | |
| 14731 | /** |
| 14732 | * Inform whether application supports NTN SMS in satellite mode. |
| 14733 | * |
| 14734 | * This method is used by default messaging application to inform framework whether it supports |
| 14735 | * NTN SMS or not. |
| 14736 | * |
| 14737 | * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}. |
| 14738 | * |
| 14739 | * @throws SecurityException if the caller doesn't have required permission. |
| 14740 | */ |
| 14741 | @Override |
| 14742 | public void setNtnSmsSupported(boolean ntnSmsSupported) { |
| 14743 | enforceSatelliteCommunicationPermission("setNtnSmsSupported"); |
| 14744 | enforceSendSmsPermission(); |
| 14745 | mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported); |
| 14746 | } |
| 14747 | |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14748 | /** |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14749 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14750 | * value : |
| 14751 | * config_satellite_gateway_service_package and |
| 14752 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14753 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14754 | * subscriber informations. |
| 14755 | * |
| 14756 | * @param name the name is one of the following that constitute an intent. |
| 14757 | * Component package name, or component class name. |
| 14758 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14759 | */ |
| 14760 | @Override |
| 14761 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14762 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14763 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14764 | + " carrierRoamingNbIotNtn is disabled"); |
| 14765 | return false; |
| 14766 | } |
| 14767 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14768 | TelephonyPermissions.enforceShellOnly( |
| 14769 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14771 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14772 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14773 | final long identity = Binder.clearCallingIdentity(); |
| 14774 | try { |
| 14775 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14776 | } finally { |
| 14777 | Binder.restoreCallingIdentity(identity); |
| 14778 | } |
| 14779 | } |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 14780 | |
| 14781 | /** |
| 14782 | * This API can be used by only CTS to override the Euicc UI component. |
| 14783 | * |
| 14784 | * @param componentName ui component to be launched for testing. {@code null} to reset. |
| 14785 | * |
| 14786 | * @hide |
| 14787 | */ |
| 14788 | @Override |
| 14789 | public void setTestEuiccUiComponent(@Nullable ComponentName componentName) { |
| 14790 | enforceModifyPermission(); |
| 14791 | log("setTestEuiccUiComponent: " + componentName); |
| 14792 | mTestEuiccUiComponent = componentName; |
| 14793 | } |
| 14794 | |
| 14795 | /** |
| 14796 | * This API can be used by only CTS to retrieve the Euicc UI component. |
| 14797 | * |
| 14798 | * @return Euicc UI component. {@code null} if not available. |
| 14799 | * @hide |
| 14800 | */ |
| 14801 | @Override |
| 14802 | @Nullable |
| 14803 | public ComponentName getTestEuiccUiComponent() { |
| 14804 | enforceReadPrivilegedPermission("getTestEuiccUiComponent"); |
| 14805 | return mTestEuiccUiComponent; |
| 14806 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14807 | |
| 14808 | /** |
| 14809 | * This API can be used only for test purpose to override the carrier roaming Ntn eligibility |
| 14810 | * |
| 14811 | * @param state to update Ntn Eligibility. |
| 14812 | * @param resetRequired to reset the overridden flag in satellite controller. |
| 14813 | * @return {@code true} if the shell command is successful, {@code false} otherwise. |
| 14814 | */ |
| 14815 | public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state, |
| 14816 | boolean resetRequired) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14817 | final long identity = Binder.clearCallingIdentity(); |
| 14818 | try { |
| 14819 | return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state, |
| 14820 | resetRequired); |
| 14821 | } finally { |
| 14822 | Binder.restoreCallingIdentity(identity); |
| 14823 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14824 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14825 | } |