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; |
Sangyun Yun | 8bb6645 | 2024-11-25 15:46:10 +0000 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED; |
| 30 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED; |
| 31 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 32 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 34 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 35 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 36 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 37 | 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] | 38 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 39 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 40 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 41 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 42 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 43 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 44 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 46 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 47 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 48 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 49 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 50 | import android.compat.annotation.ChangeId; |
| 51 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 52 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 53 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 54 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.content.Context; |
| 56 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 58 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 59 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.net.Uri; |
| 61 | import android.os.AsyncResult; |
| 62 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 63 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 65 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 67 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 68 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 69 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.Looper; |
| 71 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 72 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 73 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 74 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 75 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 76 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 77 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 78 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 79 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 80 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 81 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 83 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 84 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 85 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 86 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 87 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 88 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 89 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 90 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 91 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 92 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 93 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 94 | import android.telephony.AccessNetworkConstants; |
| 95 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 96 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 97 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 98 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 99 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 100 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 101 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 102 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 103 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 104 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 105 | import android.telephony.CellIdentityCdma; |
| 106 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 108 | import android.telephony.CellInfoGsm; |
| 109 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 110 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 111 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 112 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 113 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 114 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 115 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 116 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 117 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 118 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 119 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 120 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 121 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 122 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 124 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 125 | import android.telephony.SignalStrengthUpdateRequest; |
| 126 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 127 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 128 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 130 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 131 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 132 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 133 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 134 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 135 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 136 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 137 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 138 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 139 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 140 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 141 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 142 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import android.telephony.gba.GbaAuthRequest; |
| 144 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 145 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 147 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 148 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 149 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 154 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 155 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 156 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 157 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 158 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 159 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteDisallowedReasonsCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 165 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 166 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 167 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Daniel Banta | 9332024 | 2024-11-21 00:34:41 +0000 | [diff] [blame] | 169 | import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 170 | import android.telephony.satellite.NtnSignalStrength; |
| 171 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 173 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 174 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 175 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 176 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 177 | import android.telephony.satellite.SatelliteSubscriberInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 180 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 182 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 183 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 184 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 185 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 186 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 187 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 219 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 226 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 232 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 235 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 236 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 237 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 238 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 240 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.IccIoResult; |
| 243 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 246 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 247 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 248 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 249 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 250 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 251 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 252 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 253 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 254 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 255 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 256 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 257 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 258 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 259 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 260 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 261 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 262 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 263 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 264 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 265 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 266 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 267 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 268 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 269 | import com.android.services.telephony.TelecomAccountRegistry; |
| 270 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 271 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 272 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 273 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 274 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 275 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 276 | import java.io.IOException; |
| 277 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 278 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 280 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 281 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 282 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 283 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 284 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 285 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 286 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 287 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 288 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 289 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 290 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 291 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 292 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 293 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 294 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * Implementation of the ITelephony interface. |
| 298 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 299 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 301 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 302 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 303 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 304 | |
| 305 | // Message codes used with mMainThreadHandler |
| 306 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 307 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 308 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 309 | private static final int CMD_OPEN_CHANNEL = 9; |
| 310 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 311 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 312 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 313 | private static final int CMD_NV_READ_ITEM = 13; |
| 314 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 315 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 316 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 317 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 318 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 319 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 320 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 321 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 322 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 323 | private static final int CMD_SEND_ENVELOPE = 25; |
| 324 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 325 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 326 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 327 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 328 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 330 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 331 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 332 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 333 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 334 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 335 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 336 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 337 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 338 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 339 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 340 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 341 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 342 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 343 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 344 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 345 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 346 | private static final int CMD_SWITCH_SLOTS = 50; |
| 347 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 348 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 349 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 350 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 351 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 352 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 353 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 354 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 355 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 356 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 357 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 358 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 359 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 360 | private static final int CMD_MODEM_REBOOT = 64; |
| 361 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 362 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 363 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 364 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 365 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 366 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 367 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 368 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 369 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 370 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 371 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 372 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 373 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 374 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 375 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 376 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 377 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 378 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 379 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 380 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 381 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 382 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 383 | private static final int CMD_GET_CALL_WAITING = 87; |
| 384 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 385 | private static final int CMD_SET_CALL_WAITING = 89; |
| 386 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 387 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 388 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 389 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 390 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 391 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 392 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 393 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 394 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 395 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 396 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 397 | private static final int CMD_SET_SIM_POWER = 101; |
| 398 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 399 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 400 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 401 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 402 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 403 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 404 | 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] | 405 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 406 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 407 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 408 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 409 | private static final int CMD_ENABLE_VONR = 113; |
| 410 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 411 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 412 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 413 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 414 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 415 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 416 | // Parameters of select command. |
| 417 | private static final int SELECT_COMMAND = 0xA4; |
| 418 | private static final int SELECT_P1 = 0x04; |
| 419 | private static final int SELECT_P2 = 0; |
| 420 | private static final int SELECT_P3 = 0x10; |
| 421 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 422 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 423 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 424 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 425 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 426 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 427 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | /** The singleton instance. */ |
| 430 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 431 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 433 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 434 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 435 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 436 | private final CallManager mCM; |
| 437 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 438 | |
| 439 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 440 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 441 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 442 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 443 | private final SharedPreferences mTelephonySharedPreferences; |
| 444 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 445 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 446 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 447 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 448 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 450 | @Nullable |
| 451 | private ComponentName mTestEuiccUiComponent; |
| 452 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 453 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 454 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 455 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 456 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 457 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 458 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 459 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 460 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 461 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 462 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 463 | // String to store multi SIM allowed |
| 464 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 465 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 466 | // The AID of ISD-R. |
| 467 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 468 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 469 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 470 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 471 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 472 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 473 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 474 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 475 | 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] | 476 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 477 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 478 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 479 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 480 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 481 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 482 | */ |
| 483 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 484 | "reset_network_erase_modem_config_enabled"; |
| 485 | |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 486 | private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 487 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 488 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 489 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 490 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 491 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 492 | /** |
| 493 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 494 | * one ICCID active at the same time. |
| 495 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 496 | * |
| 497 | * @hide |
| 498 | */ |
| 499 | @ChangeId |
| 500 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 501 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 502 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 503 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 504 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 505 | * operation fails. |
| 506 | */ |
| 507 | @ChangeId |
| 508 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 509 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 510 | |
| 511 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 512 | * A request object to use for transmitting data to an ICC. |
| 513 | */ |
| 514 | private static final class IccAPDUArgument { |
| 515 | public int channel, cla, command, p1, p2, p3; |
| 516 | public String data; |
| 517 | |
| 518 | public IccAPDUArgument(int channel, int cla, int command, |
| 519 | int p1, int p2, int p3, String data) { |
| 520 | this.channel = channel; |
| 521 | this.cla = cla; |
| 522 | this.command = command; |
| 523 | this.p1 = p1; |
| 524 | this.p2 = p2; |
| 525 | this.p3 = p3; |
| 526 | this.data = data; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 531 | * A request object to use for transmitting data to an ICC. |
| 532 | */ |
| 533 | private static final class ManualNetworkSelectionArgument { |
| 534 | public OperatorInfo operatorInfo; |
| 535 | public boolean persistSelection; |
| 536 | |
| 537 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 538 | this.operatorInfo = operatorInfo; |
| 539 | this.persistSelection = persistSelection; |
| 540 | } |
| 541 | } |
| 542 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 543 | private static final class PurchasePremiumCapabilityArgument { |
| 544 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 545 | public @NonNull IIntegerConsumer callback; |
| 546 | |
| 547 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 548 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 549 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 550 | this.callback = callback; |
| 551 | } |
| 552 | } |
| 553 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 554 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 556 | * request after sending. The main thread will notify the request when it is complete. |
| 557 | */ |
| 558 | private static final class MainThreadRequest { |
| 559 | /** The argument to use for the request */ |
| 560 | public Object argument; |
| 561 | /** The result of the request that is run on the main thread */ |
| 562 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 563 | // The subscriber id that this request applies to. Defaults to |
| 564 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 565 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 566 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 567 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 568 | public Phone phone; |
| 569 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 570 | public WorkSource workSource; |
| 571 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | public MainThreadRequest(Object argument) { |
| 573 | this.argument = argument; |
| 574 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 575 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 576 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 577 | this.argument = argument; |
| 578 | if (phone != null) { |
| 579 | this.phone = phone; |
| 580 | } |
| 581 | this.workSource = workSource; |
| 582 | } |
| 583 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 584 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 585 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 586 | if (subId != null) { |
| 587 | this.subId = subId; |
| 588 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 589 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 590 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 593 | private static final class IncomingThirdPartyCallArgs { |
| 594 | public final ComponentName component; |
| 595 | public final String callId; |
| 596 | public final String callerDisplayName; |
| 597 | |
| 598 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 599 | String callerDisplayName) { |
| 600 | this.component = component; |
| 601 | this.callId = callId; |
| 602 | this.callerDisplayName = callerDisplayName; |
| 603 | } |
| 604 | } |
| 605 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | /** |
| 607 | * A handler that processes messages on the main thread in the phone process. Since many |
| 608 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 609 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 610 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 611 | * on, which will be notified when the operation completes and will contain the result of the |
| 612 | * request. |
| 613 | * |
| 614 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 615 | * note that request.result must be set to something non-null for the calling thread to |
| 616 | * unblock. |
| 617 | */ |
| 618 | private final class MainThreadHandler extends Handler { |
| 619 | @Override |
| 620 | public void handleMessage(Message msg) { |
| 621 | MainThreadRequest request; |
| 622 | Message onCompleted; |
| 623 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 626 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 627 | |
| 628 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | case CMD_HANDLE_USSD_REQUEST: { |
| 630 | request = (MainThreadRequest) msg.obj; |
| 631 | final Phone phone = getPhoneFromRequest(request); |
| 632 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 635 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | if (!isUssdApiAllowed(request.subId)) { |
| 637 | // Carrier does not support use of this API, return failure. |
| 638 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 639 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 640 | Bundle returnData = new Bundle(); |
| 641 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 642 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 643 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | request.result = true; |
| 645 | notifyRequester(request); |
| 646 | return; |
| 647 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 648 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 649 | try { |
| 650 | request.result = phone != null |
| 651 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 652 | } catch (CallStateException cse) { |
| 653 | request.result = false; |
| 654 | } |
| 655 | // Wake up the requesting thread |
| 656 | notifyRequester(request); |
| 657 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 660 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 662 | final Phone phone = getPhoneFromRequest(request); |
| 663 | request.result = phone != null ? |
| 664 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 665 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 666 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 668 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 670 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 674 | uiccPort = getUiccPortFromRequest(request); |
| 675 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 677 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 681 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 682 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 683 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 684 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 685 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 689 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
| 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; |
| 694 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 695 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | if (ar.result == null) { |
| 697 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
| 702 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 703 | } |
| 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 711 | uiccPort = getUiccPortFromRequest(request); |
| 712 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 713 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 714 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 715 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | } else { |
| 717 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 718 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 719 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 720 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 721 | iccArgument.p2, |
| 722 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | } |
| 724 | break; |
| 725 | |
| 726 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
| 729 | if (ar.exception == null && ar.result != null) { |
| 730 | request.result = ar.result; |
| 731 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 732 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | if (ar.result == null) { |
| 734 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 735 | } else if (ar.exception instanceof CommandException) { |
| 736 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 737 | ar.exception); |
| 738 | } else { |
| 739 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 740 | } |
| 741 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case CMD_EXCHANGE_SIM_IO: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 748 | uiccPort = getUiccPortFromRequest(request); |
| 749 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 750 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 753 | } else { |
| 754 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 755 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 756 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 757 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 758 | iccArgument.data, onCompleted); |
| 759 | } |
| 760 | break; |
| 761 | |
| 762 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 763 | ar = (AsyncResult) msg.obj; |
| 764 | request = (MainThreadRequest) ar.userObj; |
| 765 | if (ar.exception == null && ar.result != null) { |
| 766 | request.result = ar.result; |
| 767 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 768 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 769 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 773 | case CMD_SEND_ENVELOPE: |
| 774 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 775 | uiccPort = getUiccPortFromRequest(request); |
| 776 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 777 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 778 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 779 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 780 | } else { |
| 781 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 782 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case EVENT_SEND_ENVELOPE_DONE: |
| 787 | ar = (AsyncResult) msg.obj; |
| 788 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 789 | if (ar.exception == null && ar.result != null) { |
| 790 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 791 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 793 | if (ar.result == null) { |
| 794 | loge("sendEnvelopeWithStatus: Empty response"); |
| 795 | } else if (ar.exception instanceof CommandException) { |
| 796 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 797 | ar.exception); |
| 798 | } else { |
| 799 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 800 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 801 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 802 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 803 | break; |
| 804 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 805 | case CMD_OPEN_CHANNEL: |
| 806 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 807 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 808 | IccLogicalChannelRequest openChannelRequest = |
| 809 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 810 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 811 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 812 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 813 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 814 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 815 | } else { |
| 816 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 817 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 818 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 819 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case EVENT_OPEN_CHANNEL_DONE: |
| 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 825 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 826 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 827 | int[] result = (int[]) ar.result; |
| 828 | int channelId = result[0]; |
| 829 | byte[] selectResponse = null; |
| 830 | if (result.length > 1) { |
| 831 | selectResponse = new byte[result.length - 1]; |
| 832 | for (int i = 1; i < result.length; ++i) { |
| 833 | selectResponse[i - 1] = (byte) result[i]; |
| 834 | } |
| 835 | } |
| 836 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 837 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 838 | |
| 839 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 840 | if (uiccPort == null) { |
| 841 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 842 | } else { |
| 843 | IccLogicalChannelRequest channelRequest = |
| 844 | (IccLogicalChannelRequest) request.argument; |
| 845 | channelRequest.channel = channelId; |
| 846 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 847 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | if (ar.result == null) { |
| 850 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 852 | if (ar.exception != null) { |
| 853 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 854 | } |
| 855 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 856 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 857 | if (ar.exception instanceof CommandException) { |
| 858 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 859 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 860 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 861 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 862 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 863 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 867 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 868 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 869 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 870 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case CMD_CLOSE_CHANNEL: |
| 874 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 875 | uiccPort = getUiccPortFromRequest(request); |
| 876 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 877 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 878 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 879 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 880 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 881 | } else { |
| 882 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 883 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 884 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 888 | ar = (AsyncResult) msg.obj; |
| 889 | request = (MainThreadRequest) ar.userObj; |
| 890 | if (ar.exception == null) { |
| 891 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 892 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 893 | if (uiccPort == null) { |
| 894 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 895 | } else { |
| 896 | final int channelId = (Integer) request.argument; |
| 897 | uiccPort.onLogicalChannelClosed(channelId); |
| 898 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 899 | } else { |
| 900 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 901 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 902 | if (ar.exception instanceof CommandException) { |
| 903 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 904 | CommandException.Error error = |
| 905 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 906 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 907 | // should only throw exceptions from the binder threads. |
| 908 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 909 | "iccCloseLogicalChannel: invalid argument "); |
| 910 | } |
| 911 | } else { |
| 912 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 913 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 914 | request.result = (exception != null) ? exception : |
| 915 | new IllegalStateException( |
| 916 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 917 | } |
| 918 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case CMD_NV_READ_ITEM: |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 924 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 925 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 929 | ar = (AsyncResult) msg.obj; |
| 930 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | if (ar.exception == null && ar.result != null) { |
| 932 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 933 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | request.result = ""; |
| 935 | if (ar.result == null) { |
| 936 | loge("nvReadItem: Empty response"); |
| 937 | } else if (ar.exception instanceof CommandException) { |
| 938 | loge("nvReadItem: CommandException: " + |
| 939 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 940 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 941 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 944 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 945 | break; |
| 946 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 947 | case CMD_NV_WRITE_ITEM: |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 950 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 951 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 952 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case EVENT_NV_WRITE_ITEM_DONE: |
| 956 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 957 | break; |
| 958 | |
| 959 | case CMD_NV_WRITE_CDMA_PRL: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 960 | if (mFeatureFlags.cleanupCdma()) break; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 961 | request = (MainThreadRequest) msg.obj; |
| 962 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 963 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 964 | break; |
| 965 | |
| 966 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 967 | if (mFeatureFlags.cleanupCdma()) break; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 968 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 969 | break; |
| 970 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 971 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 972 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 973 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 974 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 975 | break; |
| 976 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 977 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 978 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 979 | break; |
| 980 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 981 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 982 | request = (MainThreadRequest) msg.obj; |
| 983 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 984 | request); |
| 985 | Phone phone = getPhoneFromRequest(request); |
| 986 | if (phone != null) { |
| 987 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 988 | } else { |
| 989 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 990 | request.result = false; |
| 991 | notifyRequester(request); |
| 992 | } |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
| 999 | if (ar.exception == null && ar.result != null) { |
| 1000 | request.result = ar.result; |
| 1001 | } else { |
| 1002 | // request.result must be set to something non-null |
| 1003 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1004 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1005 | request.result = ar.result; |
| 1006 | } else { |
| 1007 | request.result = false; |
| 1008 | } |
| 1009 | if (ar.result == null) { |
| 1010 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1011 | } else if (ar.exception instanceof CommandException) { |
| 1012 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1013 | + ar.exception); |
| 1014 | } else { |
| 1015 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1016 | } |
| 1017 | } |
| 1018 | notifyRequester(request); |
| 1019 | break; |
| 1020 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1021 | case CMD_IS_VONR_ENABLED: { |
| 1022 | request = (MainThreadRequest) msg.obj; |
| 1023 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1024 | request); |
| 1025 | Phone phone = getPhoneFromRequest(request); |
| 1026 | if (phone != null) { |
| 1027 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1028 | } else { |
| 1029 | loge("isVoNrEnabled: No phone object"); |
| 1030 | request.result = false; |
| 1031 | notifyRequester(request); |
| 1032 | } |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | if (ar.exception == null && ar.result != null) { |
| 1040 | request.result = ar.result; |
| 1041 | } else { |
| 1042 | // request.result must be set to something non-null |
| 1043 | // for the calling thread to unblock |
| 1044 | if (ar.result != null) { |
| 1045 | request.result = ar.result; |
| 1046 | } else { |
| 1047 | request.result = false; |
| 1048 | } |
| 1049 | if (ar.result == null) { |
| 1050 | loge("isVoNrEnabled: Empty response"); |
| 1051 | } else if (ar.exception instanceof CommandException) { |
| 1052 | loge("isVoNrEnabled: CommandException: " |
| 1053 | + ar.exception); |
| 1054 | } else { |
| 1055 | loge("isVoNrEnabled: Unknown exception"); |
| 1056 | } |
| 1057 | } |
| 1058 | notifyRequester(request); |
| 1059 | break; |
| 1060 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1061 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1062 | request = (MainThreadRequest) msg.obj; |
| 1063 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1064 | Phone phone = getPhoneFromRequest(request); |
| 1065 | if (phone != null) { |
| 1066 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1067 | request.workSource); |
| 1068 | } else { |
| 1069 | loge("enableNrDualConnectivity: No phone object"); |
| 1070 | request.result = |
| 1071 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1072 | notifyRequester(request); |
| 1073 | } |
| 1074 | break; |
| 1075 | } |
| 1076 | |
| 1077 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1078 | ar = (AsyncResult) msg.obj; |
| 1079 | request = (MainThreadRequest) ar.userObj; |
| 1080 | if (ar.exception == null) { |
| 1081 | request.result = |
| 1082 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1083 | } else { |
| 1084 | request.result = |
| 1085 | TelephonyManager |
| 1086 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1087 | if (ar.exception instanceof CommandException) { |
| 1088 | CommandException.Error error = |
| 1089 | ((CommandException) (ar.exception)).getCommandError(); |
| 1090 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1091 | request.result = |
| 1092 | TelephonyManager |
| 1093 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1094 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1095 | request.result = |
| 1096 | TelephonyManager |
| 1097 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1098 | } |
| 1099 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1100 | + ar.exception); |
| 1101 | } else { |
| 1102 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1103 | } |
| 1104 | } |
| 1105 | notifyRequester(request); |
| 1106 | break; |
| 1107 | } |
| 1108 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1109 | case CMD_ENABLE_VONR: { |
| 1110 | request = (MainThreadRequest) msg.obj; |
| 1111 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1112 | Phone phone = getPhoneFromRequest(request); |
| 1113 | if (phone != null) { |
| 1114 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1115 | request.workSource); |
| 1116 | } else { |
| 1117 | loge("setVoNrEnabled: No phone object"); |
| 1118 | request.result = |
| 1119 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1120 | notifyRequester(request); |
| 1121 | } |
| 1122 | break; |
| 1123 | } |
| 1124 | |
| 1125 | case EVENT_ENABLE_VONR_DONE: { |
| 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
| 1128 | if (ar.exception == null) { |
| 1129 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1130 | } else { |
| 1131 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1132 | if (ar.exception instanceof CommandException) { |
| 1133 | CommandException.Error error = |
| 1134 | ((CommandException) (ar.exception)).getCommandError(); |
| 1135 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1136 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1137 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1138 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1139 | } else { |
| 1140 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1141 | } |
| 1142 | loge("setVoNrEnabled" + ": CommandException: " |
| 1143 | + ar.exception); |
| 1144 | } else { |
| 1145 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1146 | } |
| 1147 | } |
| 1148 | notifyRequester(request); |
| 1149 | break; |
| 1150 | } |
| 1151 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1153 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1154 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1155 | request); |
| 1156 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1157 | break; |
| 1158 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1159 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | ar = (AsyncResult) msg.obj; |
| 1161 | request = (MainThreadRequest) ar.userObj; |
| 1162 | if (ar.exception == null && ar.result != null) { |
| 1163 | request.result = ar.result; // Integer |
| 1164 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1165 | // request.result must be set to something non-null |
| 1166 | // for the calling thread to unblock |
| 1167 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1168 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1169 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1170 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1171 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1172 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1173 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1174 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1175 | } |
| 1176 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1177 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1178 | break; |
| 1179 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1180 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1181 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1182 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1183 | request); |
| 1184 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1185 | (Pair<Integer, Long>) request.argument; |
| 1186 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1187 | reasonWithNetworkTypes.first, |
| 1188 | reasonWithNetworkTypes.second, |
| 1189 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1190 | break; |
| 1191 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1192 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1193 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1194 | break; |
| 1195 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1196 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1197 | request = (MainThreadRequest) msg.obj; |
| 1198 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1199 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1200 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1201 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1205 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1206 | break; |
| 1207 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1208 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1211 | request); |
| 1212 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1213 | break; |
| 1214 | |
| 1215 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1216 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1217 | break; |
| 1218 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1219 | case CMD_PERFORM_NETWORK_SCAN: |
| 1220 | request = (MainThreadRequest) msg.obj; |
| 1221 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1222 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1223 | break; |
| 1224 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | request = (MainThreadRequest) msg.obj; |
| 1227 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1229 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1230 | request.argument; |
| 1231 | int callForwardingReason = args.first; |
| 1232 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | } |
| 1235 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | ar = (AsyncResult) msg.obj; |
| 1237 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1239 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1240 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1244 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1245 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1246 | // any service for voice call. |
| 1247 | if ((callForwardInfo.serviceClass |
| 1248 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1249 | callForwardingInfo = new CallForwardingInfo( |
| 1250 | callForwardInfo.status |
| 1251 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | callForwardInfo.reason, |
| 1253 | callForwardInfo.number, |
| 1254 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | break; |
| 1256 | } |
| 1257 | } |
| 1258 | // Didn't find a call forward info for voice call. |
| 1259 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1261 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | } else { |
| 1265 | if (ar.result == null) { |
| 1266 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1267 | } |
| 1268 | if (ar.exception != null) { |
| 1269 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1270 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1271 | int errorCode = TelephonyManager |
| 1272 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | if (ar.exception instanceof CommandException) { |
| 1274 | CommandException.Error error = |
| 1275 | ((CommandException) (ar.exception)).getCommandError(); |
| 1276 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1277 | errorCode = TelephonyManager |
| 1278 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1280 | errorCode = TelephonyManager |
| 1281 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | } |
| 1283 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1285 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1289 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | request = (MainThreadRequest) msg.obj; |
| 1291 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1295 | request.argument).first; |
| 1296 | request.phone.setCallForwardingOption( |
| 1297 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1298 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | callForwardingInfoToSet.getReason(), |
| 1301 | callForwardingInfoToSet.getNumber(), |
| 1302 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1303 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | ar = (AsyncResult) msg.obj; |
| 1308 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | Consumer<Integer> callback = |
| 1310 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1311 | request.argument).second; |
| 1312 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1314 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1315 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | if (ar.exception instanceof CommandException) { |
| 1317 | CommandException.Error error = |
| 1318 | ((CommandException) (ar.exception)).getCommandError(); |
| 1319 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1320 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1321 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1323 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1324 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | callback.accept(errorCode); |
| 1328 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1329 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | request = (MainThreadRequest) msg.obj; |
| 1336 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1337 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1338 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | ar = (AsyncResult) msg.obj; |
| 1343 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1345 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1347 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | // Service Class is a bit mask per 3gpp 27.007. |
| 1349 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1350 | if (callForwardResults.length > 1 |
| 1351 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1353 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1354 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1355 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1357 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | } |
| 1359 | } else { |
| 1360 | if (ar.result == null) { |
| 1361 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1362 | } |
| 1363 | if (ar.exception != null) { |
| 1364 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1365 | } |
| 1366 | if (ar.exception instanceof CommandException) { |
| 1367 | CommandException.Error error = |
| 1368 | ((CommandException) (ar.exception)).getCommandError(); |
| 1369 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1370 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1371 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1372 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1373 | callWaitingStatus = |
| 1374 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1378 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1380 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1382 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1383 | request = (MainThreadRequest) msg.obj; |
| 1384 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1385 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1386 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1387 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1388 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1389 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1390 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | ar = (AsyncResult) msg.obj; |
| 1392 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1393 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1394 | Consumer<Integer> callback = |
| 1395 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1396 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1397 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1398 | if (ar.exception instanceof CommandException) { |
| 1399 | CommandException.Error error = |
| 1400 | ((CommandException) (ar.exception)).getCommandError(); |
| 1401 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1402 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1403 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1404 | callback.accept( |
| 1405 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1406 | } else { |
| 1407 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1408 | } |
| 1409 | } else { |
| 1410 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1411 | } |
| 1412 | } else { |
| 1413 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1414 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1415 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1416 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1417 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1418 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | CellNetworkScanResult cellScanResult; |
| 1422 | if (ar.exception == null && ar.result != null) { |
| 1423 | cellScanResult = new CellNetworkScanResult( |
| 1424 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1425 | (List<OperatorInfo>) ar.result); |
| 1426 | } else { |
| 1427 | if (ar.result == null) { |
| 1428 | loge("getCellNetworkScanResults: Empty response"); |
| 1429 | } |
| 1430 | if (ar.exception != null) { |
| 1431 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1432 | } |
| 1433 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1434 | if (ar.exception instanceof CommandException) { |
| 1435 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1436 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1437 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1438 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1439 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1440 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1441 | } |
| 1442 | } |
| 1443 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1444 | } |
| 1445 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1446 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
| 1449 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1450 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1451 | ManualNetworkSelectionArgument selArg = |
| 1452 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1453 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1454 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1455 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1456 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1457 | break; |
| 1458 | |
| 1459 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1460 | ar = (AsyncResult) msg.obj; |
| 1461 | request = (MainThreadRequest) ar.userObj; |
| 1462 | if (ar.exception == null) { |
| 1463 | request.result = true; |
| 1464 | } else { |
| 1465 | request.result = false; |
| 1466 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1467 | } |
| 1468 | notifyRequester(request); |
| 1469 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1472 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1473 | request = (MainThreadRequest) msg.obj; |
| 1474 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1475 | if (defaultPhone != null) { |
| 1476 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1477 | } else { |
| 1478 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1479 | Bundle bundle = new Bundle(); |
| 1480 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1481 | new ModemActivityInfo(0, 0, 0, |
| 1482 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1483 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1484 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1485 | break; |
| 1486 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1487 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | ar = (AsyncResult) msg.obj; |
| 1489 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1490 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1491 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1492 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1493 | if (mLastModemActivityInfo == null) { |
| 1494 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1495 | mLastModemActivitySpecificInfo[0] = |
| 1496 | new ActivityStatsTechSpecificInfo( |
| 1497 | 0, |
| 1498 | 0, |
| 1499 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1500 | 0); |
| 1501 | mLastModemActivityInfo = |
| 1502 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1503 | } |
| 1504 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1505 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1506 | // Update the last modem activity info and the result of the request. |
| 1507 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1508 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1509 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1510 | } else { |
| 1511 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1512 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1513 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1514 | // We don't want to return mLastModemActivityInfo which is updated |
| 1515 | // inside mergeModemActivityInfo() |
| 1516 | ret = new ModemActivityInfo( |
| 1517 | mLastModemActivityInfo.getTimestampMillis(), |
| 1518 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1519 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1520 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1521 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1522 | } else { |
| 1523 | if (ar.result == null) { |
| 1524 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1525 | error = TelephonyManager.ModemActivityInfoException |
| 1526 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1527 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1528 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1529 | error = TelephonyManager.ModemActivityInfoException |
| 1530 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1531 | } else { |
| 1532 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1533 | error = TelephonyManager.ModemActivityInfoException |
| 1534 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1535 | } |
| 1536 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1537 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1538 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1539 | bundle.putParcelable( |
| 1540 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1541 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1542 | } else { |
| 1543 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1544 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1545 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1546 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1547 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1548 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1549 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1550 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1552 | CarrierRestrictionRules argument = |
| 1553 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1554 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1555 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1557 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1558 | |
| 1559 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1560 | ar = (AsyncResult) msg.obj; |
| 1561 | request = (MainThreadRequest) ar.userObj; |
| 1562 | if (ar.exception == null && ar.result != null) { |
| 1563 | request.result = ar.result; |
| 1564 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1565 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1566 | if (ar.exception instanceof CommandException) { |
| 1567 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1568 | CommandException.Error error = |
| 1569 | ((CommandException) (ar.exception)).getCommandError(); |
| 1570 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1571 | request.result = |
| 1572 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1573 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1574 | } else { |
| 1575 | loge("setAllowedCarriers: Unknown exception"); |
| 1576 | } |
| 1577 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1578 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1579 | break; |
| 1580 | |
| 1581 | case CMD_GET_ALLOWED_CARRIERS: |
| 1582 | request = (MainThreadRequest) msg.obj; |
| 1583 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1584 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1585 | break; |
| 1586 | |
| 1587 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1588 | ar = (AsyncResult) msg.obj; |
| 1589 | request = (MainThreadRequest) ar.userObj; |
| 1590 | if (ar.exception == null && ar.result != null) { |
| 1591 | request.result = ar.result; |
| 1592 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1593 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1594 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1595 | if (ar.result == null) { |
| 1596 | loge("getAllowedCarriers: Empty response"); |
| 1597 | } else if (ar.exception instanceof CommandException) { |
| 1598 | loge("getAllowedCarriers: CommandException: " + |
| 1599 | ar.exception); |
| 1600 | } else { |
| 1601 | loge("getAllowedCarriers: Unknown exception"); |
| 1602 | } |
| 1603 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1604 | if (request.argument != null) { |
| 1605 | // This is for the implementation of carrierRestrictionStatus. |
| 1606 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1607 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1608 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1609 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1610 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1611 | CarrierRestrictionRules carrierRestrictionRules = |
| 1612 | (CarrierRestrictionRules) ar.result; |
| 1613 | int carrierId = -1; |
| 1614 | try { |
| 1615 | CarrierIdentifier carrierIdentifier = |
| 1616 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1617 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1618 | carrierIdentifier); |
| 1619 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1620 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1621 | } |
| 1622 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1623 | int restrictedStatus = |
| 1624 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1625 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1626 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1627 | lockStatus = TelephonyManager |
| 1628 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } else { |
| 1631 | Rlog.e(LOG_TAG, |
| 1632 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1633 | } |
| 1634 | callback.accept(lockStatus); |
| 1635 | } else { |
| 1636 | // This is for the implementation of getAllowedCarriers. |
| 1637 | notifyRequester(request); |
| 1638 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1639 | break; |
| 1640 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1641 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1642 | ar = (AsyncResult) msg.obj; |
| 1643 | request = (MainThreadRequest) ar.userObj; |
| 1644 | if (ar.exception == null && ar.result != null) { |
| 1645 | request.result = ar.result; |
| 1646 | } else { |
| 1647 | request.result = new IllegalArgumentException( |
| 1648 | "Failed to retrieve Forbidden Plmns"); |
| 1649 | if (ar.result == null) { |
| 1650 | loge("getForbiddenPlmns: Empty response"); |
| 1651 | } else { |
| 1652 | loge("getForbiddenPlmns: Unknown exception"); |
| 1653 | } |
| 1654 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1655 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1656 | break; |
| 1657 | |
| 1658 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1659 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1660 | uiccPort = getUiccPortFromRequest(request); |
| 1661 | if (uiccPort == null) { |
| 1662 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1663 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1664 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1665 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1669 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1670 | if (uiccApp == null) { |
| 1671 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1672 | + appType); |
| 1673 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1674 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1675 | break; |
| 1676 | } else { |
| 1677 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1678 | + " specified type -- " + appType); |
| 1679 | } |
| 1680 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1681 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1682 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1683 | break; |
| 1684 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1685 | case CMD_SWITCH_SLOTS: |
| 1686 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1687 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1688 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1689 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1690 | break; |
| 1691 | |
| 1692 | case EVENT_SWITCH_SLOTS_DONE: |
| 1693 | ar = (AsyncResult) msg.obj; |
| 1694 | request = (MainThreadRequest) ar.userObj; |
| 1695 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1696 | notifyRequester(request); |
| 1697 | break; |
| 1698 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1701 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1702 | break; |
| 1703 | |
| 1704 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1705 | ar = (AsyncResult) msg.obj; |
| 1706 | request = (MainThreadRequest) ar.userObj; |
| 1707 | if (ar.exception != null) { |
| 1708 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1709 | } else { |
| 1710 | int mode = ((int[]) ar.result)[0]; |
| 1711 | if (mode == 0) { |
| 1712 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1713 | } else { |
| 1714 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1715 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1716 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1717 | notifyRequester(request); |
| 1718 | break; |
| 1719 | case CMD_GET_CDMA_ROAMING_MODE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1720 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1723 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1724 | break; |
| 1725 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1726 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1727 | ar = (AsyncResult) msg.obj; |
| 1728 | request = (MainThreadRequest) ar.userObj; |
| 1729 | if (ar.exception != null) { |
| 1730 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1731 | } else { |
| 1732 | request.result = ((int[]) ar.result)[0]; |
| 1733 | } |
| 1734 | notifyRequester(request); |
| 1735 | break; |
| 1736 | case CMD_SET_CDMA_ROAMING_MODE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1737 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1738 | request = (MainThreadRequest) msg.obj; |
| 1739 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1740 | int mode = (int) request.argument; |
| 1741 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1742 | break; |
| 1743 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1744 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1745 | ar = (AsyncResult) msg.obj; |
| 1746 | request = (MainThreadRequest) ar.userObj; |
| 1747 | request.result = ar.exception == null; |
| 1748 | notifyRequester(request); |
| 1749 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1750 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1751 | if (mFeatureFlags.cleanupCdma()) break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1752 | request = (MainThreadRequest) msg.obj; |
| 1753 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1754 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1755 | break; |
| 1756 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1757 | if (mFeatureFlags.cleanupCdma()) break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1758 | ar = (AsyncResult) msg.obj; |
| 1759 | request = (MainThreadRequest) ar.userObj; |
| 1760 | if (ar.exception != null) { |
| 1761 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1762 | } else { |
| 1763 | request.result = ((int[]) ar.result)[0]; |
| 1764 | } |
| 1765 | notifyRequester(request); |
| 1766 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1767 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1768 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1769 | request = (MainThreadRequest) msg.obj; |
| 1770 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1771 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1772 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1773 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1774 | break; |
| 1775 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 1776 | if (mFeatureFlags.cleanupCdma()) break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1777 | ar = (AsyncResult) msg.obj; |
| 1778 | request = (MainThreadRequest) ar.userObj; |
| 1779 | request.result = ar.exception == null; |
| 1780 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1781 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1782 | case CMD_GET_ALL_CELL_INFO: |
| 1783 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1784 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1785 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1786 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1787 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1788 | ar = (AsyncResult) msg.obj; |
| 1789 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1790 | // If a timeout occurs, the response will be null |
| 1791 | request.result = (ar.exception == null && ar.result != null) |
| 1792 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1793 | synchronized (request) { |
| 1794 | request.notifyAll(); |
| 1795 | } |
| 1796 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1797 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1798 | request = (MainThreadRequest) msg.obj; |
| 1799 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1800 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1801 | break; |
| 1802 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1803 | ar = (AsyncResult) msg.obj; |
| 1804 | request = (MainThreadRequest) ar.userObj; |
| 1805 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1806 | try { |
| 1807 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1808 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1809 | cb.onError( |
| 1810 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1811 | ar.exception.getClass().getName(), |
| 1812 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1813 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1814 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1815 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1816 | } else { |
| 1817 | // use the result as returned |
| 1818 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1819 | } |
| 1820 | } catch (RemoteException re) { |
| 1821 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1822 | } |
| 1823 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1824 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | WorkSource ws = (WorkSource) request.argument; |
| 1827 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1828 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1829 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1830 | } |
| 1831 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1832 | ar = (AsyncResult) msg.obj; |
| 1833 | request = (MainThreadRequest) ar.userObj; |
| 1834 | if (ar.exception == null) { |
| 1835 | request.result = ar.result; |
| 1836 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1837 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1838 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1839 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | synchronized (request) { |
| 1843 | request.notifyAll(); |
| 1844 | } |
| 1845 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1846 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1847 | case CMD_MODEM_REBOOT: |
| 1848 | request = (MainThreadRequest) msg.obj; |
Tomasz Wasilczyk | f1af36c | 2024-12-05 11:36:37 -0800 | [diff] [blame] | 1849 | onCompleted = obtainMessage(EVENT_CMD_MODEM_REBOOT_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1850 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1851 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1852 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1853 | handleNullReturnEvent(msg, "rebootModem"); |
| 1854 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1855 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1856 | request = (MainThreadRequest) msg.obj; |
| 1857 | boolean enable = (boolean) request.argument; |
| 1858 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1859 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1860 | PhoneConfigurationManager.getInstance() |
| 1861 | .enablePhone(request.phone, enable, onCompleted); |
| 1862 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1863 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1864 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1865 | ar = (AsyncResult) msg.obj; |
| 1866 | request = (MainThreadRequest) ar.userObj; |
| 1867 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1868 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1869 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1870 | if ((boolean) request.result) { |
| 1871 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1872 | updateModemStateMetrics(); |
| 1873 | } else { |
| 1874 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1875 | + ar.exception); |
| 1876 | } |
| 1877 | notifyRequester(request); |
| 1878 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1879 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1880 | case CMD_GET_MODEM_STATUS: |
| 1881 | request = (MainThreadRequest) msg.obj; |
| 1882 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1883 | PhoneConfigurationManager.getInstance() |
| 1884 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1885 | break; |
| 1886 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1887 | ar = (AsyncResult) msg.obj; |
| 1888 | request = (MainThreadRequest) ar.userObj; |
| 1889 | int id = request.phone.getPhoneId(); |
| 1890 | if (ar.exception == null && ar.result != null) { |
| 1891 | request.result = ar.result; |
| 1892 | //update the cache as modem status has changed |
| 1893 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1894 | (boolean) request.result); |
| 1895 | } else { |
| 1896 | // Return true if modem status cannot be retrieved. For most cases, |
| 1897 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1898 | // and disable modem are not supported. Modem is always on. |
| 1899 | // TODO: this should be fixed in R to support a third |
| 1900 | // status UNKNOWN b/131631629 |
| 1901 | request.result = true; |
| 1902 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1903 | + ar.exception); |
| 1904 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1905 | notifyRequester(request); |
| 1906 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1907 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1908 | request = (MainThreadRequest) msg.obj; |
| 1909 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1910 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1911 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1912 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1913 | break; |
| 1914 | } |
| 1915 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1916 | ar = (AsyncResult) msg.obj; |
| 1917 | request = (MainThreadRequest) ar.userObj; |
| 1918 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1919 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1920 | args.second.accept(ar.exception == null); |
| 1921 | notifyRequester(request); |
| 1922 | break; |
| 1923 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1924 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1925 | request = (MainThreadRequest) msg.obj; |
| 1926 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1927 | Phone phone = getPhoneFromRequest(request); |
| 1928 | if (phone != null) { |
| 1929 | phone.getSystemSelectionChannels(onCompleted); |
| 1930 | } else { |
| 1931 | loge("getSystemSelectionChannels: No phone object"); |
| 1932 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1933 | notifyRequester(request); |
| 1934 | } |
| 1935 | break; |
| 1936 | } |
| 1937 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1938 | ar = (AsyncResult) msg.obj; |
| 1939 | request = (MainThreadRequest) ar.userObj; |
| 1940 | if (ar.exception == null && ar.result != null) { |
| 1941 | request.result = ar.result; |
| 1942 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1943 | request.result = new IllegalStateException( |
| 1944 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1945 | if (ar.result == null) { |
| 1946 | loge("getSystemSelectionChannels: Empty response"); |
| 1947 | } else { |
| 1948 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1949 | } |
| 1950 | } |
| 1951 | notifyRequester(request); |
| 1952 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1953 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1954 | ar = (AsyncResult) msg.obj; |
| 1955 | request = (MainThreadRequest) ar.userObj; |
| 1956 | if (ar.exception == null && ar.result != null) { |
| 1957 | request.result = ar.result; |
| 1958 | } else { |
| 1959 | request.result = -1; |
| 1960 | loge("Failed to set Forbidden Plmns"); |
| 1961 | if (ar.result == null) { |
| 1962 | loge("setForbidenPlmns: Empty response"); |
| 1963 | } else if (ar.exception != null) { |
| 1964 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1965 | request.result = -1; |
| 1966 | } else { |
| 1967 | loge("setForbiddenPlmns: Unknown exception"); |
| 1968 | } |
| 1969 | } |
| 1970 | notifyRequester(request); |
| 1971 | break; |
| 1972 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1973 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1974 | uiccPort = getUiccPortFromRequest(request); |
| 1975 | if (uiccPort == null) { |
| 1976 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1977 | request.result = -1; |
| 1978 | notifyRequester(request); |
| 1979 | break; |
| 1980 | } |
| 1981 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1982 | (Pair<Integer, List<String>>) request.argument; |
| 1983 | appType = setFplmnsArgs.first; |
| 1984 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1985 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1986 | if (uiccApp == null) { |
| 1987 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1988 | request.result = -1; |
| 1989 | loge("Failed to get UICC App"); |
| 1990 | notifyRequester(request); |
| 1991 | } else { |
| 1992 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1993 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1994 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1995 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1996 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1997 | case CMD_ERASE_MODEM_CONFIG: |
| 1998 | request = (MainThreadRequest) msg.obj; |
| 1999 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2000 | defaultPhone.eraseModemConfig(onCompleted); |
| 2001 | break; |
| 2002 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2003 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2004 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2005 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2006 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2007 | request = (MainThreadRequest) msg.obj; |
| 2008 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2009 | notifyRequester(request); |
| 2010 | break; |
| 2011 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2012 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2013 | request = (MainThreadRequest) msg.obj; |
| 2014 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2015 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2016 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2017 | changed.first, changed.second, onCompleted); |
| 2018 | break; |
| 2019 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2020 | ar = (AsyncResult) msg.obj; |
| 2021 | request = (MainThreadRequest) ar.userObj; |
| 2022 | if (ar.exception == null) { |
| 2023 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2024 | // If the operation is successful, update the PIN storage |
| 2025 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2026 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2027 | UiccController.getInstance().getPinStorage() |
| 2028 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2029 | } else { |
| 2030 | request.result = msg.arg1; |
| 2031 | } |
| 2032 | notifyRequester(request); |
| 2033 | break; |
| 2034 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2035 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2036 | request = (MainThreadRequest) msg.obj; |
| 2037 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2038 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2039 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2040 | enabled.first, enabled.second, onCompleted); |
| 2041 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2042 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2043 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2044 | ar = (AsyncResult) msg.obj; |
| 2045 | request = (MainThreadRequest) ar.userObj; |
| 2046 | if (ar.exception == null) { |
| 2047 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2048 | // If the operation is successful, update the PIN storage |
| 2049 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2050 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2051 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2052 | UiccController.getInstance().getPinStorage() |
| 2053 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2054 | } else { |
| 2055 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2056 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2057 | } else { |
| 2058 | request.result = msg.arg1; |
| 2059 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2060 | |
| 2061 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2062 | notifyRequester(request); |
| 2063 | break; |
| 2064 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2065 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2066 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2067 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2068 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2069 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2070 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2071 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2072 | |
| 2073 | case CMD_SET_DATA_THROTTLING: { |
| 2074 | request = (MainThreadRequest) msg.obj; |
| 2075 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2076 | DataThrottlingRequest dataThrottlingRequest = |
| 2077 | (DataThrottlingRequest) request.argument; |
| 2078 | Phone phone = getPhoneFromRequest(request); |
| 2079 | if (phone != null) { |
| 2080 | phone.setDataThrottling(onCompleted, |
| 2081 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2082 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2083 | } else { |
| 2084 | loge("setDataThrottling: No phone object"); |
| 2085 | request.result = |
| 2086 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2087 | notifyRequester(request); |
| 2088 | } |
| 2089 | |
| 2090 | break; |
| 2091 | } |
| 2092 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2093 | ar = (AsyncResult) msg.obj; |
| 2094 | request = (MainThreadRequest) ar.userObj; |
| 2095 | |
| 2096 | if (ar.exception == null) { |
| 2097 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2098 | } else if (ar.exception instanceof CommandException) { |
| 2099 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2100 | CommandException.Error error = |
| 2101 | ((CommandException) (ar.exception)).getCommandError(); |
| 2102 | |
| 2103 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2104 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2105 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2106 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2107 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2108 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2109 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2110 | } else { |
| 2111 | request.result = |
| 2112 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2113 | } |
| 2114 | } else { |
| 2115 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2116 | } |
| 2117 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2118 | notifyRequester(request); |
| 2119 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2120 | |
| 2121 | case CMD_SET_SIM_POWER: { |
| 2122 | request = (MainThreadRequest) msg.obj; |
| 2123 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2124 | request = (MainThreadRequest) msg.obj; |
| 2125 | int stateToSet = |
| 2126 | ((Pair<Integer, IIntegerConsumer>) |
| 2127 | request.argument).first; |
| 2128 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2129 | break; |
| 2130 | } |
| 2131 | case EVENT_SET_SIM_POWER_DONE: { |
| 2132 | ar = (AsyncResult) msg.obj; |
| 2133 | request = (MainThreadRequest) ar.userObj; |
| 2134 | IIntegerConsumer callback = |
| 2135 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2136 | if (ar.exception != null) { |
| 2137 | loge("setSimPower exception: " + ar.exception); |
| 2138 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2139 | .RESULT_ERROR_UNKNOWN; |
| 2140 | if (ar.exception instanceof CommandException) { |
| 2141 | CommandException.Error error = |
| 2142 | ((CommandException) (ar.exception)).getCommandError(); |
| 2143 | if (error == CommandException.Error.SIM_ERR) { |
| 2144 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2145 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2146 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2147 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2148 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2149 | } else { |
| 2150 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2151 | } |
| 2152 | } |
| 2153 | try { |
| 2154 | callback.accept(errorCode); |
| 2155 | } catch (RemoteException e) { |
| 2156 | // Ignore if the remote process is no longer available to call back. |
| 2157 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2158 | } |
| 2159 | } else { |
| 2160 | try { |
| 2161 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2162 | } catch (RemoteException e) { |
| 2163 | // Ignore if the remote process is no longer available to call back. |
| 2164 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2165 | } |
| 2166 | } |
| 2167 | break; |
| 2168 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2169 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2170 | request = (MainThreadRequest) msg.obj; |
| 2171 | |
| 2172 | final Phone phone = getPhoneFromRequest(request); |
| 2173 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2174 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2175 | notifyRequester(request); |
| 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2180 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2181 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2182 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2183 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2184 | request.subId, pair.first /*callingUid*/, |
| 2185 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| 2188 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2189 | ar = (AsyncResult) msg.obj; |
| 2190 | request = (MainThreadRequest) ar.userObj; |
| 2191 | // request.result will be the exception of ar if present, true otherwise. |
| 2192 | // Be cautious not to leave result null which will wait() forever |
| 2193 | request.result = ar.exception != null ? ar.exception : true; |
| 2194 | notifyRequester(request); |
| 2195 | break; |
| 2196 | } |
| 2197 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2198 | request = (MainThreadRequest) msg.obj; |
| 2199 | |
| 2200 | Phone phone = getPhoneFromRequest(request); |
| 2201 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2202 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2203 | notifyRequester(request); |
| 2204 | break; |
| 2205 | } |
| 2206 | |
| 2207 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2208 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2209 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2210 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2211 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2212 | request.subId, pair.first /*callingUid*/, |
| 2213 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2214 | break; |
| 2215 | } |
| 2216 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2217 | ar = (AsyncResult) msg.obj; |
| 2218 | request = (MainThreadRequest) ar.userObj; |
| 2219 | request.result = ar.exception != null ? ar.exception : true; |
| 2220 | notifyRequester(request); |
| 2221 | break; |
| 2222 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2223 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2224 | case CMD_GET_SLICING_CONFIG: { |
| 2225 | request = (MainThreadRequest) msg.obj; |
| 2226 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2227 | request.phone.getSlicingConfig(onCompleted); |
| 2228 | break; |
| 2229 | } |
| 2230 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2231 | ar = (AsyncResult) msg.obj; |
| 2232 | request = (MainThreadRequest) ar.userObj; |
| 2233 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2234 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2235 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2236 | Bundle bundle = new Bundle(); |
| 2237 | int resultCode = 0; |
| 2238 | if (ar.exception != null) { |
| 2239 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2240 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2241 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2242 | } else if (ar.result == null) { |
| 2243 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2244 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2245 | } else { |
| 2246 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2247 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2248 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2252 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2253 | } |
| 2254 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2255 | result.send(resultCode, bundle); |
| 2256 | notifyRequester(request); |
| 2257 | break; |
| 2258 | } |
| 2259 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2260 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | request = (MainThreadRequest) msg.obj; |
| 2262 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2263 | PurchasePremiumCapabilityArgument arg = |
| 2264 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2265 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2266 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2267 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2268 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2269 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2270 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2271 | ar = (AsyncResult) msg.obj; |
| 2272 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2273 | PurchasePremiumCapabilityArgument arg = |
| 2274 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2275 | try { |
| 2276 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2277 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2278 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2279 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2280 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2281 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2282 | } catch (RemoteException e) { |
| 2283 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2284 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2285 | + " failed: " + e; |
| 2286 | if (DBG) log(logStr); |
| 2287 | AnomalyReporter.reportAnomaly( |
| 2288 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2289 | } |
| 2290 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2291 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2292 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2293 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2294 | request = (MainThreadRequest) msg.obj; |
| 2295 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2296 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2297 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2298 | notifyRequester(request); |
| 2299 | break; |
| 2300 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | default: |
| 2302 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2303 | break; |
| 2304 | } |
| 2305 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2306 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2307 | private void notifyRequester(MainThreadRequest request) { |
| 2308 | synchronized (request) { |
| 2309 | request.notifyAll(); |
| 2310 | } |
| 2311 | } |
| 2312 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2313 | private void handleNullReturnEvent(Message msg, String command) { |
| 2314 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2315 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2316 | if (ar.exception == null) { |
| 2317 | request.result = true; |
| 2318 | } else { |
| 2319 | request.result = false; |
| 2320 | if (ar.exception instanceof CommandException) { |
| 2321 | loge(command + ": CommandException: " + ar.exception); |
| 2322 | } else { |
| 2323 | loge(command + ": Unknown exception"); |
| 2324 | } |
| 2325 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2326 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Posts the specified command to be executed on the main thread, |
| 2332 | * waits for the request to complete, and returns the result. |
| 2333 | * @see #sendRequestAsync |
| 2334 | */ |
| 2335 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2336 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2337 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * Posts the specified command to be executed on the main thread, |
| 2342 | * waits for the request to complete, and returns the result. |
| 2343 | * @see #sendRequestAsync |
| 2344 | */ |
| 2345 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2346 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2347 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
| 2351 | * Posts the specified command to be executed on the main thread, |
| 2352 | * waits for the request to complete, and returns the result. |
| 2353 | * @see #sendRequestAsync |
| 2354 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2355 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * Posts the specified command to be executed on the main thread, |
| 2361 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2362 | * if not timeout or null otherwise. |
| 2363 | * @see #sendRequestAsync |
| 2364 | */ |
| 2365 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2366 | long timeoutInMs) { |
| 2367 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | /** |
| 2371 | * Posts the specified command to be executed on the main thread, |
| 2372 | * waits for the request to complete, and returns the result. |
| 2373 | * @see #sendRequestAsync |
| 2374 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2375 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Posts the specified command to be executed on the main thread, |
| 2381 | * waits for the request to complete, and returns the result. |
| 2382 | * @see #sendRequestAsync |
| 2383 | */ |
| 2384 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2385 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2386 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2390 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2391 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2392 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2393 | * @see #sendRequestAsync |
| 2394 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2395 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2396 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2398 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2399 | } |
| 2400 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2401 | MainThreadRequest request = null; |
| 2402 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2403 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2404 | } else if (phone != null) { |
| 2405 | request = new MainThreadRequest(argument, phone, workSource); |
| 2406 | } else { |
| 2407 | request = new MainThreadRequest(argument, subId, workSource); |
| 2408 | } |
| 2409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2411 | msg.sendToTarget(); |
| 2412 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2413 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2414 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2415 | if (timeoutInMs >= 0) { |
| 2416 | // Wait for at least timeoutInMs before returning null request result |
| 2417 | long now = SystemClock.elapsedRealtime(); |
| 2418 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2419 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2420 | try { |
| 2421 | request.wait(deadline - now); |
| 2422 | } catch (InterruptedException e) { |
| 2423 | // Do nothing, go back and check if request is completed or timeout |
| 2424 | } finally { |
| 2425 | now = SystemClock.elapsedRealtime(); |
| 2426 | } |
| 2427 | } |
| 2428 | } else { |
| 2429 | // Wait for the request to complete |
| 2430 | while (request.result == null) { |
| 2431 | try { |
| 2432 | request.wait(); |
| 2433 | } catch (InterruptedException e) { |
| 2434 | // Do nothing, go back and wait until the request is complete |
| 2435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2439 | if (request.result == null) { |
| 2440 | Log.wtf(LOG_TAG, |
| 2441 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | return request.result; |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2448 | * Posts the specified command to be executed on the main thread, and |
| 2449 | * returns immediately. |
| 2450 | * @see #sendRequest |
| 2451 | */ |
| 2452 | private void sendRequestAsync(int command) { |
| 2453 | mMainThreadHandler.sendEmptyMessage(command); |
| 2454 | } |
| 2455 | |
| 2456 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2457 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2458 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2459 | */ |
| 2460 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2461 | sendRequestAsync(command, argument, null, null); |
| 2462 | } |
| 2463 | |
| 2464 | /** |
| 2465 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2466 | * @see {@link #sendRequest(int,Object)} |
| 2467 | */ |
| 2468 | private void sendRequestAsync( |
| 2469 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2470 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2471 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2472 | msg.sendToTarget(); |
| 2473 | } |
| 2474 | |
| 2475 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2477 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2478 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2479 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | synchronized (PhoneInterfaceManager.class) { |
| 2481 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2482 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | } else { |
| 2484 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2485 | } |
| 2486 | return sInstance; |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2491 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2493 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2494 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2496 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2497 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2498 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2500 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2501 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2502 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2503 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2504 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2505 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2506 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2507 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2508 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2509 | mVendorApiLevel = SystemProperties.getInt( |
| 2510 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2511 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2512 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2514 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2515 | |
| 2516 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2517 | // entitlementStatus for satellite service. |
| 2518 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2521 | @VisibleForTesting |
| 2522 | public SharedPreferences getSharedPreferences() { |
| 2523 | return mTelephonySharedPreferences; |
| 2524 | } |
| 2525 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2526 | /** |
| 2527 | * Get the default phone for this device. |
| 2528 | */ |
| 2529 | @VisibleForTesting |
| 2530 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2531 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2532 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2533 | } |
| 2534 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | private void publish() { |
| 2536 | if (DBG) log("publish: " + this); |
| 2537 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2538 | TelephonyFrameworkInitializer |
| 2539 | .getTelephonyServiceManager() |
| 2540 | .getTelephonyServiceRegisterer() |
| 2541 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2544 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2545 | if (request.phone != null) { |
| 2546 | return request.phone; |
| 2547 | } else { |
| 2548 | return getPhoneFromSubId(request.subId); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | private Phone getPhoneFromSubId(int subId) { |
| 2553 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2554 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2555 | } |
| 2556 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2557 | /** |
| 2558 | * Get phone object associated with a subscription. |
| 2559 | * Return default phone if phone object associated with subscription is null |
| 2560 | * @param subId - subscriptionId |
| 2561 | * @return phone object associated with a subscription or default phone if null. |
| 2562 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2563 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2564 | Phone phone = getPhoneFromSubId(subId); |
| 2565 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2566 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2567 | phone = getDefaultPhone(); |
| 2568 | } |
| 2569 | return phone; |
| 2570 | } |
| 2571 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2572 | @Nullable |
| 2573 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2574 | Phone phone = getPhoneFromRequest(request); |
| 2575 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2576 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2577 | } |
| 2578 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2579 | /** |
| 2580 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2581 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2582 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2583 | * @return The Phone associated the sub Id |
| 2584 | */ |
| 2585 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2586 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2589 | private void sendEraseModemConfig(@NonNull Phone phone) { |
Tomasz Wasilczyk | f1af36c | 2024-12-05 11:36:37 -0800 | [diff] [blame] | 2590 | if (mFeatureFlags.cleanupCdma()) return; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2591 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2592 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2593 | } |
| 2594 | |
| 2595 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2596 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2597 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2600 | private boolean isImsAvailableOnDevice() { |
| 2601 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2602 | if (pm == null) { |
| 2603 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2604 | // so do not throw error and allow. |
| 2605 | return true; |
| 2606 | } |
| 2607 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2608 | } |
| 2609 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2611 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2612 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2613 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2614 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2617 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | if (DBG) log("dial: " + number); |
| 2619 | // No permission check needed here: This is just a wrapper around the |
| 2620 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2621 | // the UI before it does anything. |
| 2622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | final long identity = Binder.clearCallingIdentity(); |
| 2624 | try { |
| 2625 | String url = createTelUrl(number); |
| 2626 | if (url == null) { |
| 2627 | return; |
| 2628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2631 | PhoneConstants.State state = mCM.getState(subId); |
| 2632 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2633 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2634 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2635 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2643 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2646 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | if (DBG) log("call: " + number); |
| 2648 | |
| 2649 | // 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] | 2650 | // need to do a permission check since we're calling startActivityAsUser() |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2651 | // from the context of the phone app. |
| 2652 | enforceCallPermission(); |
| 2653 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2654 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | != AppOpsManager.MODE_ALLOWED) { |
| 2656 | return; |
| 2657 | } |
| 2658 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2659 | enforceTelephonyFeatureWithException(callingPackage, |
| 2660 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2661 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | String url = createTelUrl(number); |
| 2665 | if (url == null) { |
| 2666 | return; |
| 2667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | boolean isValid = false; |
| 2670 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2671 | if (slist != null) { |
| 2672 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2673 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2674 | isValid = true; |
| 2675 | break; |
| 2676 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2677 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | if (!isValid) { |
| 2680 | return; |
| 2681 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2684 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2685 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2686 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | } finally { |
| 2688 | Binder.restoreCallingIdentity(identity); |
| 2689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2692 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2693 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2694 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2695 | } |
| 2696 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2697 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2698 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2699 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2700 | } |
| 2701 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2702 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2705 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2706 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2707 | "supplyPinReportResultForSubscriber"); |
| 2708 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2711 | Phone phone = getPhone(subId); |
| 2712 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | checkSimPin.start(); |
| 2714 | return checkSimPin.unlockSim(null, pin); |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
| 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2720 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2723 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2724 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2728 | Phone phone = getPhone(subId); |
| 2729 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | checkSimPuk.start(); |
| 2731 | return checkSimPuk.unlockSim(puk, pin); |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
| 2734 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2738 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | * a synchronous one. |
| 2740 | */ |
| 2741 | private static class UnlockSim extends Thread { |
| 2742 | |
| 2743 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2744 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | |
| 2746 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2747 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2748 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2749 | |
| 2750 | // For replies from SimCard interface |
| 2751 | private Handler mHandler; |
| 2752 | |
| 2753 | // For async handler to identify request type |
| 2754 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2755 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2756 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2757 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2758 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2760 | UnlockSim(int phoneId, IccCard simCard) { |
| 2761 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2762 | mSimCard = simCard; |
| 2763 | } |
| 2764 | |
| 2765 | @Override |
| 2766 | public void run() { |
| 2767 | Looper.prepare(); |
| 2768 | synchronized (UnlockSim.this) { |
| 2769 | mHandler = new Handler() { |
| 2770 | @Override |
| 2771 | public void handleMessage(Message msg) { |
| 2772 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2773 | switch (msg.what) { |
| 2774 | case SUPPLY_PIN_COMPLETE: |
| 2775 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2776 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2777 | mRetryCount = msg.arg1; |
| 2778 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2779 | CommandException.Error error = null; |
| 2780 | if (ar.exception instanceof CommandException) { |
| 2781 | error = ((CommandException) (ar.exception)) |
| 2782 | .getCommandError(); |
| 2783 | } |
| 2784 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2785 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2786 | } else if (error == CommandException.Error.ABORTED) { |
| 2787 | /* When UiccCardApp dispose, handle message and return |
| 2788 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2789 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2790 | } else { |
| 2791 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2792 | } |
| 2793 | } else { |
| 2794 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2797 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | UnlockSim.this.notifyAll(); |
| 2799 | } |
| 2800 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2801 | case SUPPLY_PIN_DELAYED: |
| 2802 | if(!mDone) { |
| 2803 | String logStr = "Delay in receiving SIM PIN response "; |
| 2804 | if (DBG) log(logStr); |
| 2805 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2806 | } |
| 2807 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | }; |
| 2811 | UnlockSim.this.notifyAll(); |
| 2812 | } |
| 2813 | Looper.loop(); |
| 2814 | } |
| 2815 | |
| 2816 | /* |
| 2817 | * Use PIN or PUK to unlock SIM card |
| 2818 | * |
| 2819 | * If PUK is null, unlock SIM card with PIN |
| 2820 | * |
| 2821 | * 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] | 2822 | * |
| 2823 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2824 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2826 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | |
| 2828 | while (mHandler == null) { |
| 2829 | try { |
| 2830 | wait(); |
| 2831 | } catch (InterruptedException e) { |
| 2832 | Thread.currentThread().interrupt(); |
| 2833 | } |
| 2834 | } |
| 2835 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2836 | |
| 2837 | if (puk == null) { |
| 2838 | mSimCard.supplyPin(pin, callback); |
| 2839 | } else { |
| 2840 | mSimCard.supplyPuk(puk, pin, callback); |
| 2841 | } |
| 2842 | |
| 2843 | while (!mDone) { |
| 2844 | try { |
| 2845 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2846 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2847 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2848 | wait(); |
| 2849 | } catch (InterruptedException e) { |
| 2850 | // Restore the interrupted status |
| 2851 | Thread.currentThread().interrupt(); |
| 2852 | } |
| 2853 | } |
| 2854 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2855 | int[] resultArray = new int[2]; |
| 2856 | resultArray[0] = mResult; |
| 2857 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2858 | |
| 2859 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2860 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2861 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2862 | // This instance is no longer reused, so quit its thread's looper. |
| 2863 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2864 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2865 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2869 | /** |
| 2870 | * This method has been removed due to privacy and stability concerns. |
| 2871 | */ |
| 2872 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2874 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2875 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2878 | @Override |
| 2879 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2880 | mApp.getSystemService(AppOpsManager.class) |
| 2881 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2882 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2883 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2884 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2885 | // Callers targeting S have no business invoking this method. |
| 2886 | return; |
| 2887 | } |
| 2888 | |
| 2889 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2890 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2891 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2892 | .setCallingPackage(callingPackage) |
| 2893 | .setCallingFeatureId(null) |
| 2894 | .setCallingPid(Binder.getCallingPid()) |
| 2895 | .setCallingUid(Binder.getCallingUid()) |
| 2896 | .setMethod("updateServiceLocation") |
| 2897 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2898 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2899 | .build()); |
| 2900 | // Apps that lack location permission have no business calling this method; |
| 2901 | // however, because no permission was declared in the public API, denials must |
| 2902 | // all be "soft". |
| 2903 | switch (locationResult) { |
| 2904 | case DENIED_HARD: /* fall through */ |
| 2905 | case DENIED_SOFT: |
| 2906 | return; |
| 2907 | } |
| 2908 | |
| 2909 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2912 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | } finally { |
| 2914 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2915 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2918 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2919 | @Override |
| 2920 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2921 | return isRadioOnWithFeature(callingPackage, null); |
| 2922 | } |
| 2923 | |
| 2924 | |
| 2925 | @Override |
| 2926 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2927 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2928 | callingFeatureId); |
| 2929 | } |
| 2930 | |
| 2931 | @Deprecated |
| 2932 | @Override |
| 2933 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2934 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2937 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2938 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2939 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2940 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2941 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2942 | return false; |
| 2943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2944 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2945 | enforceTelephonyFeatureWithException(callingPackage, |
| 2946 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2947 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
| 2950 | return isRadioOnForSubscriber(subId); |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | final long identity = Binder.clearCallingIdentity(); |
| 2958 | try { |
| 2959 | final Phone phone = getPhone(subId); |
| 2960 | if (phone != null) { |
| 2961 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2962 | } else { |
| 2963 | return false; |
| 2964 | } |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2967 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2971 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2972 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2973 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2974 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2975 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2977 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2978 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
| 2982 | final Phone phone = getPhone(subId); |
| 2983 | if (phone != null) { |
| 2984 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2985 | } |
| 2986 | } finally { |
| 2987 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2988 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2992 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2995 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2996 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | |
| 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | final Phone phone = getPhone(subId); |
| 3001 | if (phone == null) { |
| 3002 | return false; |
| 3003 | } |
| 3004 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3005 | toggleRadioOnOffForSubscriber(subId); |
| 3006 | } |
| 3007 | return true; |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3011 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3012 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3013 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3014 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3015 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 3016 | if (!mApp.getResources().getBoolean( |
| 3017 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3019 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3020 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3021 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3022 | /* |
| 3023 | * If any of the Radios are available, it will need to be |
| 3024 | * shutdown. So return true if any Radio is available. |
| 3025 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
| 3028 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3029 | Phone phone = PhoneFactory.getPhone(i); |
| 3030 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3031 | } |
| 3032 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3033 | return false; |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3036 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3039 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3040 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | enforceModifyPermission(); |
| 3042 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3043 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3044 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3045 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3046 | final long identity = Binder.clearCallingIdentity(); |
| 3047 | try { |
| 3048 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3049 | logv("Shutting down Phone " + i); |
| 3050 | shutdownRadioUsingPhoneId(i); |
| 3051 | } |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3058 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3059 | if (phone != null && phone.isRadioAvailable()) { |
| 3060 | phone.shutdownRadio(); |
| 3061 | } |
| 3062 | } |
| 3063 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3064 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3065 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3066 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3067 | if (!turnOn) { |
| 3068 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3069 | } |
| 3070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3074 | if (defaultPhone != null) { |
| 3075 | defaultPhone.setRadioPower(turnOn); |
| 3076 | return true; |
| 3077 | } else { |
| 3078 | loge("There's no default phone."); |
| 3079 | return false; |
| 3080 | } |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3083 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3086 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3087 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3089 | if (!turnOn) { |
| 3090 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3091 | + ",callingPackage=" + getCurrentPackageName()); |
| 3092 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
| 3095 | final Phone phone = getPhone(subId); |
| 3096 | if (phone != null) { |
| 3097 | phone.setRadioPower(turnOn); |
| 3098 | return true; |
| 3099 | } else { |
| 3100 | return false; |
| 3101 | } |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3107 | /** |
| 3108 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3109 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3110 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3111 | * powering it off, and these radio off votes will be cleared. |
| 3112 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3113 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3114 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3115 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3116 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3117 | * check its vote. |
| 3118 | * |
| 3119 | * @param subId The subscription ID. |
| 3120 | * @param reason The reason for powering off radio. |
| 3121 | * @return true on success and false on failure. |
| 3122 | */ |
| 3123 | public boolean requestRadioPowerOffForReason(int subId, |
| 3124 | @TelephonyManager.RadioPowerReason int reason) { |
| 3125 | enforceModifyPermission(); |
| 3126 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3127 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3128 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3129 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3130 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3131 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3134 | boolean result = false; |
| 3135 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3136 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3137 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3138 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3139 | if (!result) { |
| 3140 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3141 | } |
| 3142 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3150 | * {@link requestRadioPowerOffForReason}. |
| 3151 | * |
| 3152 | * @param subId The subscription ID. |
| 3153 | * @param reason The reason for powering off radio. |
| 3154 | * @return true on success and false on failure. |
| 3155 | */ |
| 3156 | public boolean clearRadioPowerOffForReason(int subId, |
| 3157 | @TelephonyManager.RadioPowerReason int reason) { |
| 3158 | enforceModifyPermission(); |
| 3159 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3160 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3161 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3162 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3163 | final long identity = Binder.clearCallingIdentity(); |
| 3164 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3165 | boolean result = false; |
| 3166 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3167 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3168 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3169 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3170 | if (!result) { |
| 3171 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3172 | } |
| 3173 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | /** |
| 3180 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3181 | * |
| 3182 | * @param subId The subscription ID. |
| 3183 | * @param callingPackage The package making the call. |
| 3184 | * @param callingFeatureId The feature in the package. |
| 3185 | * @return List of reasons for powering off radio. |
| 3186 | */ |
| 3187 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3188 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3189 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3190 | enforceTelephonyFeatureWithException(callingPackage, |
| 3191 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3192 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3193 | final long identity = Binder.clearCallingIdentity(); |
| 3194 | List result = new ArrayList(); |
| 3195 | try { |
| 3196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3197 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3198 | return result; |
| 3199 | } |
| 3200 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3201 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3202 | if (phone != null) { |
| 3203 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3204 | } else { |
| 3205 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3206 | } |
| 3207 | } finally { |
| 3208 | Binder.restoreCallingIdentity(identity); |
| 3209 | } |
| 3210 | return result; |
| 3211 | } |
| 3212 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3213 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3214 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3215 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3217 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3218 | enforceTelephonyFeatureWithException(callingPackage, |
| 3219 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3223 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3225 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3226 | phone.getDataSettingsManager().setDataEnabled( |
| 3227 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3228 | return true; |
| 3229 | } else { |
| 3230 | return false; |
| 3231 | } |
| 3232 | } finally { |
| 3233 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3234 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3238 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3239 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3240 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3242 | enforceTelephonyFeatureWithException(callingPackage, |
| 3243 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | final long identity = Binder.clearCallingIdentity(); |
| 3246 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3247 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3249 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3250 | phone.getDataSettingsManager().setDataEnabled( |
| 3251 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | return true; |
| 3253 | } else { |
| 3254 | return false; |
| 3255 | } |
| 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3262 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3264 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3266 | final long identity = Binder.clearCallingIdentity(); |
| 3267 | try { |
| 3268 | final Phone phone = getPhone(subId); |
| 3269 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3270 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | } else { |
| 3272 | return false; |
| 3273 | } |
| 3274 | } finally { |
| 3275 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3280 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3283 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | enforceCallPermission(); |
| 3285 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3286 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3287 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3289 | final long identity = Binder.clearCallingIdentity(); |
| 3290 | try { |
| 3291 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3292 | return; |
| 3293 | } |
| 3294 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3295 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3299 | }; |
| 3300 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3301 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3304 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3305 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3310 | return false; |
| 3311 | } |
| 3312 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3318 | /** |
| 3319 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3320 | * tag on getCallState Binder call. |
| 3321 | */ |
| 3322 | @Deprecated |
| 3323 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3324 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3325 | if (CompatChanges.isChangeEnabled( |
| 3326 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3327 | Binder.getCallingUid())) { |
| 3328 | // Do not allow this API to be called on API version 31+, it should only be |
| 3329 | // called on old apps using this Binder call directly. |
| 3330 | throw new SecurityException("This method can only be used for applications " |
| 3331 | + "targeting API version 30 or less."); |
| 3332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | final long identity = Binder.clearCallingIdentity(); |
| 3334 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3335 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3336 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | @Override |
| 3343 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3344 | if (CompatChanges.isChangeEnabled( |
| 3345 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3346 | Binder.getCallingUid())) { |
| 3347 | // Check READ_PHONE_STATE for API version 31+ |
| 3348 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3349 | featureId, "getCallStateForSubscription")) { |
| 3350 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3351 | + "targeting API level 31+."); |
| 3352 | } |
| 3353 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3354 | |
| 3355 | enforceTelephonyFeatureWithException(callingPackage, |
| 3356 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3357 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3362 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
| 3365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3368 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3369 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3370 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | @Override |
| 3374 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3375 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3376 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 | final long identity = Binder.clearCallingIdentity(); |
| 3379 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3382 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | } else { |
| 3384 | return PhoneConstantConversions.convertDataState( |
| 3385 | PhoneConstants.DataState.DISCONNECTED); |
| 3386 | } |
| 3387 | } finally { |
| 3388 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3392 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3393 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3394 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3398 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3399 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3400 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3402 | final long identity = Binder.clearCallingIdentity(); |
| 3403 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3404 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3405 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3406 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | } else { |
| 3408 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3409 | } |
| 3410 | } finally { |
| 3411 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3416 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3417 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3418 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3419 | |
| 3420 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3421 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3422 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3423 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3424 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3425 | .setCallingPid(Binder.getCallingPid()) |
| 3426 | .setCallingUid(Binder.getCallingUid()) |
| 3427 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3428 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3429 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3430 | .build()); |
| 3431 | switch (locationResult) { |
| 3432 | case DENIED_HARD: |
| 3433 | throw new SecurityException("Not allowed to access cell location"); |
| 3434 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3435 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3436 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3439 | enforceTelephonyFeatureWithException(callingPackage, |
| 3440 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3441 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3446 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3447 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
| 3450 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3454 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3455 | if (!mApp.getResources().getBoolean( |
| 3456 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3457 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3458 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3459 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3460 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3461 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3462 | // registered cell info, so return a NULL country instead. |
| 3463 | final long identity = Binder.clearCallingIdentity(); |
| 3464 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3465 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3466 | // Get default phone in this case. |
| 3467 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3468 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3469 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3471 | if (phone == null) return ""; |
| 3472 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3473 | if (sst == null) return ""; |
| 3474 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3475 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3476 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3477 | } finally { |
| 3478 | Binder.restoreCallingIdentity(identity); |
| 3479 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3482 | /** |
| 3483 | * This method was removed due to potential issues caused by performing partial |
| 3484 | * updates of service state, and lack of a credible use case. |
| 3485 | * |
| 3486 | * This has the ability to break the telephony implementation by disabling notification of |
| 3487 | * changes in device connectivity. DO NOT USE THIS! |
| 3488 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3489 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3490 | public void enableLocationUpdates() { |
| 3491 | mApp.enforceCallingOrSelfPermission( |
| 3492 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3495 | /** |
| 3496 | * This method was removed due to potential issues caused by performing partial |
| 3497 | * updates of service state, and lack of a credible use case. |
| 3498 | * |
| 3499 | * This has the ability to break the telephony implementation by disabling notification of |
| 3500 | * changes in device connectivity. DO NOT USE THIS! |
| 3501 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3502 | @Override |
| 3503 | public void disableLocationUpdates() { |
| 3504 | mApp.enforceCallingOrSelfPermission( |
| 3505 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | @Override |
| 3509 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3510 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3511 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3512 | try { |
| 3513 | mApp.getSystemService(AppOpsManager.class) |
| 3514 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3515 | } catch (SecurityException e) { |
| 3516 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3517 | throw e; |
| 3518 | } |
| 3519 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3520 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3521 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3522 | throw new SecurityException( |
| 3523 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3524 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3525 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3526 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3528 | return null; |
| 3529 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3530 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3531 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3532 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3533 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3534 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3536 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3537 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3538 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3539 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3540 | for (CellInfo ci : info) { |
| 3541 | if (ci instanceof CellInfoGsm) { |
| 3542 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3543 | } else if (ci instanceof CellInfoWcdma) { |
| 3544 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3546 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3547 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3550 | private List<CellInfo> getCachedCellInfo() { |
| 3551 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3552 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3553 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3554 | if (info != null) cellInfos.addAll(info); |
| 3555 | } |
| 3556 | return cellInfos; |
| 3557 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3558 | |
| 3559 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3560 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3561 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3562 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3563 | |
| 3564 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3565 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3566 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3567 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3568 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3569 | .setCallingPid(Binder.getCallingPid()) |
| 3570 | .setCallingUid(Binder.getCallingUid()) |
| 3571 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3572 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3573 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3574 | .build()); |
| 3575 | switch (locationResult) { |
| 3576 | case DENIED_HARD: |
| 3577 | throw new SecurityException("Not allowed to access cell info"); |
| 3578 | case DENIED_SOFT: |
| 3579 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3582 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3583 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3584 | return getCachedCellInfo(); |
| 3585 | } |
| 3586 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3587 | enforceTelephonyFeatureWithException(callingPackage, |
| 3588 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3589 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3590 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3591 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3595 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3596 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3597 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3598 | if (info != null) cellInfos.addAll(info); |
| 3599 | } |
| 3600 | return cellInfos; |
| 3601 | } finally { |
| 3602 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3606 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3607 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3608 | String callingFeatureId) { |
| 3609 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3610 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3614 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3615 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3616 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3617 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3620 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3621 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3622 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3623 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3624 | |
| 3625 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3626 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3627 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3628 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3629 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3630 | .setCallingPid(Binder.getCallingPid()) |
| 3631 | .setCallingUid(Binder.getCallingUid()) |
| 3632 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3633 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3634 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3635 | .build()); |
| 3636 | switch (locationResult) { |
| 3637 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3638 | if (TelephonyPermissions |
| 3639 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3640 | // Safetynet logging for b/154934934 |
| 3641 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3642 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3643 | throw new SecurityException("Not allowed to access cell info"); |
| 3644 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3645 | if (TelephonyPermissions |
| 3646 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3647 | // Safetynet logging for b/154934934 |
| 3648 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3649 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3650 | try { |
| 3651 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3652 | } catch (RemoteException re) { |
| 3653 | // Drop without consequences |
| 3654 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3655 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3656 | } |
| 3657 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3658 | enforceTelephonyFeatureWithException(callingPackage, |
| 3659 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3660 | |
| 3661 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3662 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3663 | |
| 3664 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3665 | } |
| 3666 | |
| 3667 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3668 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3669 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3670 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | |
| 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3674 | Phone phone = getPhone(subId); |
| 3675 | if (phone == null) { |
| 3676 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3677 | } else { |
| 3678 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3679 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
| 3682 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3685 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3686 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3687 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3688 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3689 | return null; |
| 3690 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3691 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3692 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3693 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3694 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3695 | return null; |
| 3696 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | |
| 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | return phone.getImei(); |
| 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(identity); |
| 3703 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3707 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3708 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3709 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3710 | callingFeatureId, "getPrimaryImei")) { |
| 3711 | throw new SecurityException("Caller does not have permission"); |
| 3712 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3713 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3714 | final long identity = Binder.clearCallingIdentity(); |
| 3715 | try { |
| 3716 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3717 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3718 | return phone.getImei(); |
| 3719 | } |
| 3720 | } |
| 3721 | throw new UnsupportedOperationException("Operation not supported"); |
| 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(identity); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3728 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3729 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3730 | String tac = null; |
| 3731 | if (phone != null) { |
| 3732 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3733 | try { |
| 3734 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3735 | } catch (IndexOutOfBoundsException e) { |
| 3736 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3737 | return null; |
| 3738 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3739 | } |
| 3740 | return tac; |
| 3741 | } |
| 3742 | |
| 3743 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3744 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 3745 | if (mFeatureFlags.cleanupCdma()) return null; |
| 3746 | |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3747 | try { |
| 3748 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3749 | } catch (SecurityException se) { |
| 3750 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3751 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3752 | + Binder.getCallingUid()); |
| 3753 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3754 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3755 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3756 | return null; |
| 3757 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3758 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3759 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3760 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3761 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3762 | return null; |
| 3763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3765 | enforceTelephonyFeatureWithException(callingPackage, |
| 3766 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | final long identity = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | return phone.getMeid(); |
| 3771 | } finally { |
| 3772 | Binder.restoreCallingIdentity(identity); |
| 3773 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3777 | public String getManufacturerCodeForSlot(int slotIndex) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 3778 | if (mFeatureFlags.cleanupCdma()) return null; |
| 3779 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3780 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3781 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3782 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3783 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3784 | String manufacturerCode = null; |
| 3785 | if (phone != null) { |
| 3786 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3787 | try { |
| 3788 | manufacturerCode = |
| 3789 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3790 | } catch (IndexOutOfBoundsException e) { |
| 3791 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3792 | return null; |
| 3793 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3794 | } |
| 3795 | return manufacturerCode; |
| 3796 | } |
| 3797 | |
| 3798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3799 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3800 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3801 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3802 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3803 | return null; |
| 3804 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3805 | int subId = phone.getSubId(); |
| 3806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3807 | mApp, subId, callingPackage, callingFeatureId, |
| 3808 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3809 | return null; |
| 3810 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3812 | enforceTelephonyFeatureWithException(callingPackage, |
| 3813 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3815 | final long identity = Binder.clearCallingIdentity(); |
| 3816 | try { |
| 3817 | return phone.getDeviceSvn(); |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
| 3820 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3823 | @Override |
| 3824 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3825 | if (!mApp.getResources().getBoolean( |
| 3826 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3827 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3828 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3829 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3830 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | final Phone phone = getPhone(subId); |
| 3834 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3835 | } finally { |
| 3836 | Binder.restoreCallingIdentity(identity); |
| 3837 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | @Override |
| 3841 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3842 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3843 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3844 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | final Phone phone = getPhone(subId); |
| 3848 | return phone == null ? null : phone.getCarrierName(); |
| 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(identity); |
| 3851 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3852 | } |
| 3853 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3854 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3855 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3856 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3857 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3858 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3859 | final long identity = Binder.clearCallingIdentity(); |
| 3860 | try { |
| 3861 | final Phone phone = getPhone(subId); |
| 3862 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3863 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3870 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3871 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3872 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3873 | "getSubscriptionSpecificCarrierName"); |
| 3874 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3875 | final long identity = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3878 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3879 | } finally { |
| 3880 | Binder.restoreCallingIdentity(identity); |
| 3881 | } |
| 3882 | } |
| 3883 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3884 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3885 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3886 | if (!isSubscriptionMccMnc) { |
| 3887 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3888 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3889 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3890 | if (phone == null) { |
| 3891 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3892 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3893 | |
| 3894 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3895 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3896 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3900 | } finally { |
| 3901 | Binder.restoreCallingIdentity(identity); |
| 3902 | } |
| 3903 | } |
| 3904 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3905 | // |
| 3906 | // Internal helper methods. |
| 3907 | // |
| 3908 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3909 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3910 | * Make sure the caller is the calling package itself |
| 3911 | * |
| 3912 | * @throws SecurityException if the caller is not the calling package |
| 3913 | */ |
| 3914 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3915 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3916 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3917 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3918 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3919 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3920 | } catch (PackageManager.NameNotFoundException e) { |
| 3921 | // packageUid is -1 |
| 3922 | } |
| 3923 | if (packageUid != callingUid) { |
| 3924 | throw new SecurityException(message + ": Package " + callingPackage |
| 3925 | + " does not belong to " + callingUid); |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3930 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3931 | * |
| 3932 | * @throws SecurityException if the caller does not have the required permission |
| 3933 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3934 | @VisibleForTesting |
| 3935 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3936 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3937 | } |
| 3938 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3939 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3940 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3941 | * |
| 3942 | * @throws SecurityException if the caller does not have the required permission |
| 3943 | */ |
| 3944 | @VisibleForTesting |
| 3945 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3946 | enforceReadPermission(null); |
| 3947 | } |
| 3948 | |
| 3949 | /** |
| 3950 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3951 | * |
| 3952 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3953 | */ |
| 3954 | @VisibleForTesting |
| 3955 | public void enforceReadPermission(String msg) { |
| 3956 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3959 | private void enforceActiveEmergencySessionPermission() { |
| 3960 | mApp.enforceCallingOrSelfPermission( |
| 3961 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3962 | } |
| 3963 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3964 | /** |
| 3965 | * Make sure the caller has the CALL_PHONE permission. |
| 3966 | * |
| 3967 | * @throws SecurityException if the caller does not have the required permission |
| 3968 | */ |
| 3969 | private void enforceCallPermission() { |
| 3970 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3971 | } |
| 3972 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3973 | private void enforceSettingsPermission() { |
| 3974 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3977 | private void enforceRebootPermission() { |
| 3978 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3979 | } |
| 3980 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3981 | /** |
| 3982 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3983 | * @param message - log message to print. |
| 3984 | * @throws SecurityException if the caller does not have the required permission |
| 3985 | */ |
| 3986 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3987 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3988 | } |
| 3989 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3990 | /** |
| 3991 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3992 | * @param message - log message to print. |
| 3993 | * @throws SecurityException if the caller does not have the required permission |
| 3994 | */ |
| 3995 | private void enforcePackageUsageStatsPermission(String message) { |
| 3996 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3997 | } |
| 3998 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3999 | private String createTelUrl(String number) { |
| 4000 | if (TextUtils.isEmpty(number)) { |
| 4001 | return null; |
| 4002 | } |
| 4003 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4004 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4007 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 4008 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4011 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4012 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4015 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4016 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4019 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4020 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4021 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4024 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4025 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4026 | if (!mApp.getResources().getBoolean( |
| 4027 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4028 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4029 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4030 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | final long identity = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4035 | if (phone == null) { |
| 4036 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4037 | } else { |
| 4038 | return phone.getPhoneType(); |
| 4039 | } |
| 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4042 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * Returns the CDMA ERI icon index to display |
| 4047 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4048 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4049 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4050 | if (mFeatureFlags.cleanupCdma()) return -1; |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4051 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4052 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4055 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4056 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4057 | String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4058 | if (mFeatureFlags.cleanupCdma()) return -1; |
| 4059 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4061 | mApp, subId, callingPackage, callingFeatureId, |
| 4062 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4063 | return -1; |
| 4064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4065 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4066 | enforceTelephonyFeatureWithException(callingPackage, |
| 4067 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4068 | "getCdmaEriIconIndexForSubscriber"); |
| 4069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
| 4072 | final Phone phone = getPhone(subId); |
| 4073 | if (phone != null) { |
| 4074 | return phone.getCdmaEriIconIndex(); |
| 4075 | } else { |
| 4076 | return -1; |
| 4077 | } |
| 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4080 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | /** |
| 4084 | * Returns the CDMA ERI icon mode, |
| 4085 | * 0 - ON |
| 4086 | * 1 - FLASHING |
| 4087 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4088 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4089 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4090 | if (mFeatureFlags.cleanupCdma()) return -1; |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4091 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4092 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4095 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4096 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4097 | String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4098 | if (mFeatureFlags.cleanupCdma()) return -1; |
| 4099 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4100 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4101 | mApp, subId, callingPackage, callingFeatureId, |
| 4102 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4103 | return -1; |
| 4104 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | |
| 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | final Phone phone = getPhone(subId); |
| 4109 | if (phone != null) { |
| 4110 | return phone.getCdmaEriIconMode(); |
| 4111 | } else { |
| 4112 | return -1; |
| 4113 | } |
| 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4116 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Returns the CDMA ERI text, |
| 4121 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4122 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4123 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4124 | if (mFeatureFlags.cleanupCdma()) return null; |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4125 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4126 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4129 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4130 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4131 | String callingFeatureId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4132 | if (mFeatureFlags.cleanupCdma()) return null; |
| 4133 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4134 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4135 | mApp, subId, callingPackage, callingFeatureId, |
| 4136 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4137 | return null; |
| 4138 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | |
| 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | final Phone phone = getPhone(subId); |
| 4143 | if (phone != null) { |
| 4144 | return phone.getCdmaEriText(); |
| 4145 | } else { |
| 4146 | return null; |
| 4147 | } |
| 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4154 | * Returns the CDMA MDN. |
| 4155 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4156 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4157 | public String getCdmaMdn(int subId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4158 | if (mFeatureFlags.cleanupCdma()) return null; |
| 4159 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4161 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4164 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
| 4168 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4169 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4170 | return phone.getLine1Number(); |
| 4171 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4172 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4173 | return null; |
| 4174 | } |
| 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * Returns the CDMA MIN. |
| 4182 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4183 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4184 | public String getCdmaMin(int subId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 4185 | if (mFeatureFlags.cleanupCdma()) return null; |
| 4186 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4188 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4189 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4190 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4191 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4192 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | final Phone phone = getPhone(subId); |
| 4196 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4197 | return phone.getCdmaMin(); |
| 4198 | } else { |
| 4199 | return null; |
| 4200 | } |
| 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4206 | @Override |
| 4207 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4208 | INumberVerificationCallback callback, String callingPackage) { |
| 4209 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4210 | != PERMISSION_GRANTED) { |
| 4211 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4212 | } |
| 4213 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4214 | |
| 4215 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4216 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4217 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4218 | + "calling package: " + callingPackage |
| 4219 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4222 | enforceTelephonyFeatureWithException(callingPackage, |
| 4223 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4224 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4225 | if (range == null) { |
| 4226 | throw new NullPointerException("Range must be non-null"); |
| 4227 | } |
| 4228 | |
| 4229 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4230 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4231 | |
| 4232 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4233 | } |
| 4234 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4235 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4236 | * Returns true if CDMA provisioning needs to run. |
| 4237 | */ |
| 4238 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4239 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4240 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4242 | final long identity = Binder.clearCallingIdentity(); |
| 4243 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4244 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4251 | * Sets the voice mail number of a given subId. |
| 4252 | */ |
| 4253 | @Override |
| 4254 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4255 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4256 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4258 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4259 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4260 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | final long identity = Binder.clearCallingIdentity(); |
| 4262 | try { |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 4263 | Boolean success = (Boolean) sendRequest( |
| 4264 | CMD_SET_VOICEMAIL_NUMBER, |
| 4265 | new Pair<String, String>(alphaTag, number), |
| 4266 | new Integer(subId), |
| 4267 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
| 4268 | if (success == null) return false; // most likely due to a timeout |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4269 | return success; |
| 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(identity); |
| 4272 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4273 | } |
| 4274 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4275 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4276 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4277 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4278 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4279 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4280 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4281 | throw new SecurityException("caller must be system dialer"); |
| 4282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4284 | enforceTelephonyFeatureWithException(callingPackage, |
| 4285 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | final long identity = Binder.clearCallingIdentity(); |
| 4288 | try { |
| 4289 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4290 | if (phoneAccountHandle == null) { |
| 4291 | return null; |
| 4292 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4293 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4296 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4300 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4301 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4302 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4304 | mApp, subId, callingPackage, callingFeatureId, |
| 4305 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4306 | return null; |
| 4307 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4308 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4309 | enforceTelephonyFeatureWithException(callingPackage, |
| 4310 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4311 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4314 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
| 4317 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4321 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4322 | VisualVoicemailSmsFilterSettings settings) { |
| 4323 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4324 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4325 | enforceTelephonyFeatureWithException(callingPackage, |
| 4326 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | final long identity = Binder.clearCallingIdentity(); |
| 4328 | try { |
| 4329 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4330 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4331 | } finally { |
| 4332 | Binder.restoreCallingIdentity(identity); |
| 4333 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4337 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4338 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4339 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4340 | enforceTelephonyFeatureWithException(callingPackage, |
| 4341 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
| 4345 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4346 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4347 | } finally { |
| 4348 | Binder.restoreCallingIdentity(identity); |
| 4349 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4353 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4354 | String callingPackage, int subId) { |
| 4355 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4356 | |
| 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
| 4359 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4360 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | } finally { |
| 4362 | Binder.restoreCallingIdentity(identity); |
| 4363 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4367 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | |
| 4370 | final long identity = Binder.clearCallingIdentity(); |
| 4371 | try { |
| 4372 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4373 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | } finally { |
| 4375 | Binder.restoreCallingIdentity(identity); |
| 4376 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4380 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4381 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4382 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4383 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4384 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4385 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4386 | |
| 4387 | enforceTelephonyFeatureWithException(callingPackage, |
| 4388 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4389 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4390 | SmsController smsController = PhoneFactory.getSmsController(); |
Nikhil Kumar | deebd75 | 2024-08-14 14:49:06 +0100 | [diff] [blame] | 4391 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, |
| 4392 | Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number, |
| 4393 | port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4394 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4395 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4396 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4397 | * Sets the voice activation state of a given subId. |
| 4398 | */ |
| 4399 | @Override |
| 4400 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4402 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4404 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4405 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | final long identity = Binder.clearCallingIdentity(); |
| 4408 | try { |
| 4409 | final Phone phone = getPhone(subId); |
| 4410 | if (phone != null) { |
| 4411 | phone.setVoiceActivationState(activationState); |
| 4412 | } else { |
| 4413 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4414 | } |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | /** |
| 4421 | * Sets the data activation state of a given subId. |
| 4422 | */ |
| 4423 | @Override |
| 4424 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4426 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4428 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4429 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4430 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4431 | final long identity = Binder.clearCallingIdentity(); |
| 4432 | try { |
| 4433 | final Phone phone = getPhone(subId); |
| 4434 | if (phone != null) { |
| 4435 | phone.setDataActivationState(activationState); |
| 4436 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4437 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | } |
| 4439 | } finally { |
| 4440 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | |
| 4444 | /** |
| 4445 | * Returns the voice activation state of a given subId. |
| 4446 | */ |
| 4447 | @Override |
| 4448 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4449 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4451 | enforceTelephonyFeatureWithException(callingPackage, |
| 4452 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4453 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4454 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
| 4457 | if (phone != null) { |
| 4458 | return phone.getVoiceActivationState(); |
| 4459 | } else { |
| 4460 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4461 | } |
| 4462 | } finally { |
| 4463 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | /** |
| 4468 | * Returns the data activation state of a given subId. |
| 4469 | */ |
| 4470 | @Override |
| 4471 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4474 | enforceTelephonyFeatureWithException(callingPackage, |
| 4475 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4476 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4477 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
| 4480 | if (phone != null) { |
| 4481 | return phone.getDataActivationState(); |
| 4482 | } else { |
| 4483 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4484 | } |
| 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | |
| 4490 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4491 | * Returns the unread count of voicemails for a subId |
| 4492 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4493 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4494 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4495 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4496 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4497 | mApp, subId, callingPackage, callingFeatureId, |
| 4498 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4499 | return 0; |
| 4500 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4501 | final long identity = Binder.clearCallingIdentity(); |
| 4502 | try { |
| 4503 | final Phone phone = getPhone(subId); |
| 4504 | if (phone != null) { |
| 4505 | return phone.getVoiceMessageCount(); |
| 4506 | } else { |
| 4507 | return 0; |
| 4508 | } |
| 4509 | } finally { |
| 4510 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4515 | * returns true, if the device is in a state where both voice and data |
| 4516 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4517 | */ |
| 4518 | @Override |
| 4519 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4520 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4521 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4522 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4523 | final long identity = Binder.clearCallingIdentity(); |
| 4524 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4525 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
| 4528 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4532 | * Send the dialer code if called from the current default dialer or the caller has |
| 4533 | * carrier privilege. |
| 4534 | * @param inputCode The dialer code to send |
| 4535 | */ |
| 4536 | @Override |
| 4537 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4538 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4539 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4540 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4541 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4542 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4543 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4544 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4545 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4546 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4547 | enforceTelephonyFeatureWithException(callingPackage, |
| 4548 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | final long identity = Binder.clearCallingIdentity(); |
| 4551 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4552 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | } finally { |
| 4554 | Binder.restoreCallingIdentity(identity); |
| 4555 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4556 | } |
| 4557 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4558 | @Override |
| 4559 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4560 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4561 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4562 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4563 | |
| 4564 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4565 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4566 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4567 | final long identity = Binder.clearCallingIdentity(); |
| 4568 | try { |
| 4569 | if (!isActiveSubscription(subId)) { |
| 4570 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4571 | } |
| 4572 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4575 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4578 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4579 | public boolean isInEmergencySmsMode() { |
| 4580 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4581 | |
| 4582 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4583 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4584 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4585 | final long identity = Binder.clearCallingIdentity(); |
| 4586 | try { |
| 4587 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4588 | if (phone.isInEmergencySmsMode()) { |
| 4589 | return true; |
| 4590 | } |
| 4591 | } |
| 4592 | } finally { |
| 4593 | Binder.restoreCallingIdentity(identity); |
| 4594 | } |
| 4595 | return false; |
| 4596 | } |
| 4597 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4598 | /** |
| 4599 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4600 | * @param subId The subscription to use to check the configuration. |
| 4601 | * @param c The callback that will be used to send the result. |
| 4602 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4603 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4604 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4605 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4606 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4607 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4608 | |
| 4609 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4610 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4611 | "IMS not available on device."); |
| 4612 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | final long token = Binder.clearCallingIdentity(); |
| 4614 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4615 | int slotId = getSlotIndexOrException(subId); |
| 4616 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4617 | |
| 4618 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4619 | if (controller != null) { |
| 4620 | ImsManager imsManager = controller.getImsManager(subId); |
| 4621 | if (imsManager != null) { |
| 4622 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4623 | } else { |
| 4624 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4625 | } |
| 4626 | } else { |
| 4627 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4628 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4629 | } catch (ImsException e) { |
| 4630 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(token); |
| 4633 | } |
| 4634 | } |
| 4635 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4636 | /** |
| 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 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4641 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4642 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4643 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4644 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4645 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4646 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4647 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4648 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4649 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4650 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4651 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4652 | if (controller != null) { |
| 4653 | ImsManager imsManager = controller.getImsManager(subId); |
| 4654 | if (imsManager != null) { |
| 4655 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4656 | } else { |
| 4657 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4658 | + "is inactive, ignoring unregister."); |
| 4659 | // If the ImsManager is not valid, just return, since the callback |
| 4660 | // will already have been removed internally. |
| 4661 | } |
| 4662 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4663 | } finally { |
| 4664 | Binder.restoreCallingIdentity(token); |
| 4665 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4668 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4669 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4670 | * @param subId The subscription to use to check the configuration. |
| 4671 | * @param c The callback that will be used to send the result. |
| 4672 | */ |
| 4673 | @Override |
| 4674 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4675 | throws RemoteException { |
| 4676 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4677 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4678 | |
| 4679 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4681 | "IMS not available on device."); |
| 4682 | } |
| 4683 | final long token = Binder.clearCallingIdentity(); |
| 4684 | try { |
| 4685 | int slotId = getSlotIndexOrException(subId); |
| 4686 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4687 | |
| 4688 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4689 | if (controller != null) { |
| 4690 | ImsManager imsManager = controller.getImsManager(subId); |
| 4691 | if (imsManager != null) { |
| 4692 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4693 | } else { |
| 4694 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4695 | } |
| 4696 | } else { |
| 4697 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4698 | } |
| 4699 | } catch (ImsException e) { |
| 4700 | throw new ServiceSpecificException(e.getCode()); |
| 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(token); |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | /** |
| 4707 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4708 | * @param subId The subscription to use to check the configuration. |
| 4709 | * @param c The callback that will be used to send the result. |
| 4710 | */ |
| 4711 | @Override |
| 4712 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4713 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4714 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4715 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4716 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4717 | } |
| 4718 | final long token = Binder.clearCallingIdentity(); |
| 4719 | |
| 4720 | try { |
| 4721 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4722 | if (controller != null) { |
| 4723 | ImsManager imsManager = controller.getImsManager(subId); |
| 4724 | if (imsManager != null) { |
| 4725 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4726 | } else { |
| 4727 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4728 | + "is inactive, ignoring unregister."); |
| 4729 | // If the ImsManager is not valid, just return, since the callback |
| 4730 | // will already have been removed internally. |
| 4731 | } |
| 4732 | } |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(token); |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4739 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4740 | */ |
| 4741 | @Override |
| 4742 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4743 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4744 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4746 | "IMS not available on device."); |
| 4747 | } |
| 4748 | final long token = Binder.clearCallingIdentity(); |
| 4749 | try { |
| 4750 | Phone phone = getPhone(subId); |
| 4751 | if (phone == null) { |
| 4752 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4753 | + subId + "'"); |
| 4754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4755 | } |
| 4756 | phone.getImsRegistrationState(regState -> { |
| 4757 | try { |
| 4758 | consumer.accept((regState == null) |
| 4759 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4760 | } catch (RemoteException e) { |
| 4761 | // Ignore if the remote process is no longer available to call back. |
| 4762 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4763 | } |
| 4764 | }); |
| 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(token); |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | /** |
| 4771 | * Get the transport type for the IMS service registration state. |
| 4772 | */ |
| 4773 | @Override |
| 4774 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4775 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4776 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4777 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4778 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4779 | "IMS not available on device."); |
| 4780 | } |
| 4781 | final long token = Binder.clearCallingIdentity(); |
| 4782 | try { |
| 4783 | Phone phone = getPhone(subId); |
| 4784 | if (phone == null) { |
| 4785 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4786 | + subId + "'"); |
| 4787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4788 | } |
| 4789 | phone.getImsRegistrationTech(regTech -> { |
| 4790 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4791 | int regTechConverted = (regTech == null) |
| 4792 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4793 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4794 | regTechConverted); |
| 4795 | try { |
| 4796 | consumer.accept(regTechConverted); |
| 4797 | } catch (RemoteException e) { |
| 4798 | // Ignore if the remote process is no longer available to call back. |
| 4799 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4800 | } |
| 4801 | }); |
| 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(token); |
| 4804 | } |
| 4805 | } |
| 4806 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4807 | /** |
| 4808 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4809 | * @param subId The subscription to use to check the configuration. |
| 4810 | * @param c The callback that will be used to send the result. |
| 4811 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4812 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4813 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4814 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4815 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4816 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4817 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4818 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4819 | "IMS not available on device."); |
| 4820 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4821 | final long token = Binder.clearCallingIdentity(); |
| 4822 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4823 | int slotId = getSlotIndexOrException(subId); |
| 4824 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4825 | |
| 4826 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4827 | if (controller != null) { |
| 4828 | ImsManager imsManager = controller.getImsManager(subId); |
| 4829 | if (imsManager != null) { |
| 4830 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4831 | } else { |
| 4832 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4833 | } |
| 4834 | } else { |
| 4835 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4836 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4837 | } catch (ImsException e) { |
| 4838 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(token); |
| 4841 | } |
| 4842 | } |
| 4843 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4844 | /** |
| 4845 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4846 | * @param subId The subscription to use to check the configuration. |
| 4847 | * @param c The callback that will be used to send the result. |
| 4848 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4849 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4850 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4851 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4852 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4853 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4854 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4855 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4856 | |
| 4857 | final long token = Binder.clearCallingIdentity(); |
| 4858 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4859 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4860 | if (controller != null) { |
| 4861 | ImsManager imsManager = controller.getImsManager(subId); |
| 4862 | if (imsManager != null) { |
| 4863 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4864 | } else { |
| 4865 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4866 | + " is inactive, ignoring unregister."); |
| 4867 | // If the ImsManager is not valid, just return, since the callback |
| 4868 | // will already have been removed internally. |
| 4869 | } |
| 4870 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(token); |
| 4873 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4877 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4878 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4879 | |
| 4880 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4881 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4882 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | final long token = Binder.clearCallingIdentity(); |
| 4884 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4885 | int slotId = getSlotIndexOrException(subId); |
| 4886 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4887 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4888 | } catch (com.android.ims.ImsException e) { |
| 4889 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4890 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4891 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4892 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4893 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4894 | } finally { |
| 4895 | Binder.restoreCallingIdentity(token); |
| 4896 | } |
| 4897 | } |
| 4898 | |
| 4899 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4900 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4901 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4902 | |
| 4903 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4904 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4905 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4906 | final long token = Binder.clearCallingIdentity(); |
| 4907 | try { |
| 4908 | Phone phone = getPhone(subId); |
| 4909 | if (phone == null) return false; |
| 4910 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4911 | } catch (com.android.ims.ImsException e) { |
| 4912 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4913 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4914 | } finally { |
| 4915 | Binder.restoreCallingIdentity(token); |
| 4916 | } |
| 4917 | } |
| 4918 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4919 | /** |
| 4920 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4921 | * subscription. |
| 4922 | * @param subId The subscription to use to check the configuration. |
| 4923 | * @param callback The callback that will be used to send the result. |
| 4924 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4925 | * @param transportType The transport type of the MmTelFeature capability. |
| 4926 | */ |
| 4927 | @Override |
| 4928 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4929 | int transportType) { |
| 4930 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4931 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4932 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4933 | "IMS not available on device."); |
| 4934 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4935 | final long token = Binder.clearCallingIdentity(); |
| 4936 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4937 | int slotId = getSlotIndex(subId); |
| 4938 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4939 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4940 | + subId + "'"); |
| 4941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4942 | } |
| 4943 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4944 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4945 | transportType, aBoolean -> { |
| 4946 | try { |
| 4947 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4948 | } catch (RemoteException e) { |
| 4949 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4950 | + "running. Ignore"); |
| 4951 | } |
| 4952 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4953 | } catch (ImsException e) { |
| 4954 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4955 | } finally { |
| 4956 | Binder.restoreCallingIdentity(token); |
| 4957 | } |
| 4958 | } |
| 4959 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4960 | /** |
| 4961 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4962 | * @param subId The subscription to use to check the configuration. |
| 4963 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | @Override |
| 4965 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4966 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4967 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4968 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4969 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4970 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4971 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | final long token = Binder.clearCallingIdentity(); |
| 4973 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4974 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4975 | // 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] | 4976 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4977 | } catch (ImsException e) { |
| 4978 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4979 | } finally { |
| 4980 | Binder.restoreCallingIdentity(token); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4985 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4987 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4988 | |
| 4989 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4990 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4991 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4992 | final long identity = Binder.clearCallingIdentity(); |
| 4993 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4994 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4995 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4996 | // 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] | 4997 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4998 | } catch (ImsException e) { |
| 4999 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5000 | } finally { |
| 5001 | Binder.restoreCallingIdentity(identity); |
| 5002 | } |
| 5003 | } |
| 5004 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5005 | /** |
| 5006 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5007 | * @param subId The subscription to use to check the configuration. |
| 5008 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5009 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5010 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5011 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5012 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5013 | |
| 5014 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5015 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 5016 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5017 | final long identity = Binder.clearCallingIdentity(); |
| 5018 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5019 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5020 | // 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] | 5021 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5022 | } catch (ImsException e) { |
| 5023 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5030 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5032 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5033 | |
| 5034 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5035 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5036 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5039 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5040 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5041 | // 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] | 5042 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5043 | } catch (ImsException e) { |
| 5044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
| 5047 | } |
| 5048 | } |
| 5049 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5050 | /** |
| 5051 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5052 | * @param subId The subscription to use to check the configuration. |
| 5053 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5054 | @Override |
| 5055 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5056 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5057 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5058 | |
| 5059 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5060 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5061 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5062 | final long identity = Binder.clearCallingIdentity(); |
| 5063 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5064 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5065 | // 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] | 5066 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5067 | } catch (ImsException e) { |
| 5068 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5075 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5077 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5078 | |
| 5079 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5080 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5081 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5084 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5085 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5086 | // 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] | 5087 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5088 | } catch (ImsException e) { |
| 5089 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
| 5093 | } |
| 5094 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5095 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5096 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5097 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5098 | * @param subId The subscription to use to check the configuration. |
| 5099 | */ |
| 5100 | @Override |
| 5101 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5102 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5103 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5104 | |
| 5105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5106 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5107 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5108 | final long identity = Binder.clearCallingIdentity(); |
| 5109 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5110 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5111 | // 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] | 5112 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5113 | } catch (ImsException e) { |
| 5114 | throw new ServiceSpecificException(e.getCode()); |
| 5115 | } finally { |
| 5116 | Binder.restoreCallingIdentity(identity); |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | /** |
| 5121 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5122 | * Requires MODIFY_PHONE_STATE permission. |
| 5123 | * @param subId The subscription to use to check the configuration. |
| 5124 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5125 | * false otherwise |
| 5126 | */ |
| 5127 | @Override |
| 5128 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5130 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5131 | |
| 5132 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5133 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5134 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5137 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5138 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5139 | // 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] | 5140 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5141 | } catch (ImsException e) { |
| 5142 | throw new ServiceSpecificException(e.getCode()); |
| 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5149 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5150 | * @param subId The subscription to use to check the configuration. |
| 5151 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5152 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5153 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5154 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5155 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5156 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5157 | |
| 5158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5159 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5160 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5161 | final long identity = Binder.clearCallingIdentity(); |
| 5162 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5163 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5164 | // 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] | 5165 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5166 | } catch (ImsException e) { |
| 5167 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5168 | } finally { |
| 5169 | Binder.restoreCallingIdentity(identity); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5174 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5176 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5177 | |
| 5178 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5179 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5180 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5183 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5184 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5185 | // 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] | 5186 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5187 | } catch (ImsException e) { |
| 5188 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
| 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | @Override |
| 5195 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5197 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5198 | |
| 5199 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5200 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5201 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5204 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5205 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5206 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5207 | } catch (ImsException e) { |
| 5208 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
| 5212 | } |
| 5213 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5214 | /** |
| 5215 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5216 | * @param subId The subscription to use to check the configuration. |
| 5217 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5218 | @Override |
| 5219 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5220 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5221 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5222 | |
| 5223 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5224 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5225 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5226 | final long identity = Binder.clearCallingIdentity(); |
| 5227 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5228 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5229 | // 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] | 5230 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5231 | } catch (ImsException e) { |
| 5232 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5233 | } finally { |
| 5234 | Binder.restoreCallingIdentity(identity); |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | @Override |
| 5239 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5241 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5242 | |
| 5243 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5244 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5245 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5246 | final long identity = Binder.clearCallingIdentity(); |
| 5247 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5248 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5249 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5250 | // 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] | 5251 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5252 | } catch (ImsException e) { |
| 5253 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | @Override |
| 5260 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5261 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5262 | |
| 5263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5264 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5265 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5266 | final long identity = Binder.clearCallingIdentity(); |
| 5267 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5268 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5269 | // 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] | 5270 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5271 | } catch (ImsException e) { |
| 5272 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | @Override |
| 5279 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5280 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5281 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5282 | |
| 5283 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5284 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5285 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5288 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5289 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5290 | // 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] | 5291 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5292 | } catch (ImsException e) { |
| 5293 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | @Override |
| 5300 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5301 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5302 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5303 | |
| 5304 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5305 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5306 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5307 | final long identity = Binder.clearCallingIdentity(); |
| 5308 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5309 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5310 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5311 | // 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] | 5312 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5313 | } catch (ImsException e) { |
| 5314 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5315 | } finally { |
| 5316 | Binder.restoreCallingIdentity(identity); |
| 5317 | } |
| 5318 | } |
| 5319 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5320 | /** |
| 5321 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5322 | * @param subId The subscription to use to check the configuration. |
| 5323 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5324 | @Override |
| 5325 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5326 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5327 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5328 | |
| 5329 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5330 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5331 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5332 | final long identity = Binder.clearCallingIdentity(); |
| 5333 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5334 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5335 | // 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] | 5336 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5337 | } catch (ImsException e) { |
| 5338 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
| 5342 | } |
| 5343 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5344 | @Override |
| 5345 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5346 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5347 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5350 | if (!isImsAvailableOnDevice()) { |
| 5351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5352 | "IMS not available on device."); |
| 5353 | } |
| 5354 | int slotId = getSlotIndexOrException(subId); |
| 5355 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5356 | |
| 5357 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5358 | if (controller != null) { |
| 5359 | ImsManager imsManager = controller.getImsManager(subId); |
| 5360 | if (imsManager != null) { |
| 5361 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5362 | } else { |
| 5363 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5364 | } |
| 5365 | } else { |
| 5366 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5367 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5368 | } catch (ImsException e) { |
| 5369 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5370 | } finally { |
| 5371 | Binder.restoreCallingIdentity(identity); |
| 5372 | } |
| 5373 | } |
| 5374 | |
| 5375 | @Override |
| 5376 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5377 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5378 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5380 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5381 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5382 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5383 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5384 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5385 | if (controller != null) { |
| 5386 | ImsManager imsManager = controller.getImsManager(subId); |
| 5387 | if (imsManager != null) { |
| 5388 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5389 | } else { |
| 5390 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5391 | + " is inactive, ignoring unregister."); |
| 5392 | // If the ImsManager is not valid, just return, since the callback will already |
| 5393 | // have been removed internally. |
| 5394 | } |
| 5395 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
| 5399 | } |
| 5400 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5401 | @Override |
| 5402 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5403 | IFeatureProvisioningCallback callback) { |
| 5404 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5405 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5406 | |
| 5407 | final long identity = Binder.clearCallingIdentity(); |
| 5408 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5409 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5410 | } |
| 5411 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5412 | try { |
| 5413 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5414 | if (controller == null) { |
| 5415 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5416 | "Device does not support IMS"); |
| 5417 | } |
| 5418 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5419 | } finally { |
| 5420 | Binder.restoreCallingIdentity(identity); |
| 5421 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | @Override |
| 5425 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5426 | IFeatureProvisioningCallback callback) { |
| 5427 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5428 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5429 | |
| 5430 | final long identity = Binder.clearCallingIdentity(); |
| 5431 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5432 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5433 | } |
| 5434 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5435 | try { |
| 5436 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5437 | if (controller == null) { |
| 5438 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5439 | return; |
| 5440 | } |
| 5441 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
| 5444 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5445 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5446 | |
| 5447 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5449 | message); |
| 5450 | } |
| 5451 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5452 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5453 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5454 | boolean isProvisioned) { |
| 5455 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5456 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5457 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5458 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5459 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5460 | final long identity = Binder.clearCallingIdentity(); |
| 5461 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5462 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5463 | if (controller == null) { |
| 5464 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5465 | return; |
| 5466 | } |
| 5467 | controller.setRcsProvisioningStatusForCapability( |
| 5468 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5469 | } finally { |
| 5470 | Binder.restoreCallingIdentity(identity); |
| 5471 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5476 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5477 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5478 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5479 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5480 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5481 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5482 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5485 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5486 | if (controller == null) { |
| 5487 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5488 | |
| 5489 | // device does not support IMS, this method will return true always. |
| 5490 | return true; |
| 5491 | } |
| 5492 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
| 5495 | } |
| 5496 | } |
| 5497 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5498 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5499 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5500 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5501 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5502 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5503 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5504 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5505 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5506 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5509 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5510 | if (controller == null) { |
| 5511 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5512 | return; |
| 5513 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5514 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5515 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5516 | } finally { |
| 5517 | Binder.restoreCallingIdentity(identity); |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | @Override |
| 5522 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5523 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5524 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5525 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5526 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5527 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5528 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5529 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5530 | final long identity = Binder.clearCallingIdentity(); |
| 5531 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5532 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5533 | if (controller == null) { |
| 5534 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5535 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5536 | // device does not support IMS, this method will return true always. |
| 5537 | return true; |
| 5538 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5539 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5540 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5541 | } finally { |
| 5542 | Binder.restoreCallingIdentity(identity); |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5547 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5548 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5549 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5550 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5551 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5552 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5553 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5554 | final long identity = Binder.clearCallingIdentity(); |
| 5555 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5556 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5557 | if (controller == null) { |
| 5558 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5559 | |
| 5560 | // device does not support IMS, this method will return false |
| 5561 | return false; |
| 5562 | } |
| 5563 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5564 | } finally { |
| 5565 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5566 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5570 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5571 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5572 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5573 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5574 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5575 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5576 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5577 | final long identity = Binder.clearCallingIdentity(); |
| 5578 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5579 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5580 | if (controller == null) { |
| 5581 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5582 | |
| 5583 | // device does not support IMS, this method will return false |
| 5584 | return false; |
| 5585 | } |
| 5586 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5587 | } finally { |
| 5588 | Binder.restoreCallingIdentity(identity); |
| 5589 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5590 | } |
| 5591 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5592 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5593 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5594 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5595 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5596 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5597 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5598 | mApp, subId, "getImsProvisioningInt"); |
| 5599 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5600 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5601 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5602 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5603 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5604 | final long identity = Binder.clearCallingIdentity(); |
| 5605 | try { |
| 5606 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5607 | int slotId = getSlotIndex(subId); |
| 5608 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5609 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5610 | + subId + "' for key:" + key); |
| 5611 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5612 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5613 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5614 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5615 | if (controller == null) { |
| 5616 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5617 | |
| 5618 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5619 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5620 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5621 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5622 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5623 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5624 | return retVal; |
| 5625 | } |
| 5626 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5627 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5628 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5629 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5630 | + subId + "' for key:" + key); |
| 5631 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | @Override |
| 5638 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5639 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5640 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5641 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5642 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5643 | mApp, subId, "getImsProvisioningString"); |
| 5644 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5645 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5646 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5647 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5648 | final long identity = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5651 | int slotId = getSlotIndex(subId); |
| 5652 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5653 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5654 | + subId + "' for key:" + key); |
| 5655 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5656 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5657 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5658 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5659 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5660 | + subId + "' for key:" + key); |
| 5661 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | @Override |
| 5668 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5669 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5670 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5671 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5673 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5674 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5675 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5676 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5677 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5678 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5679 | final long identity = Binder.clearCallingIdentity(); |
| 5680 | try { |
| 5681 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5682 | int slotId = getSlotIndex(subId); |
| 5683 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5684 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5685 | + subId + "' for key:" + key); |
| 5686 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5687 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5688 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5689 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5690 | if (controller == null) { |
| 5691 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5692 | |
| 5693 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5694 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5695 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5696 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5697 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5698 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5699 | return retVal; |
| 5700 | } |
| 5701 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5702 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5703 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5704 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5705 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5706 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5707 | } finally { |
| 5708 | Binder.restoreCallingIdentity(identity); |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | @Override |
| 5713 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5714 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5715 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5716 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5718 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5719 | |
| 5720 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5721 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5722 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5726 | int slotId = getSlotIndex(subId); |
| 5727 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5728 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5729 | + subId + "' for key:" + key); |
| 5730 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5731 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5732 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5733 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5734 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5735 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5736 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
| 5740 | } |
| 5741 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5742 | /** |
| 5743 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5744 | * for the given slot ID or no ImsResolver instance has been created. |
| 5745 | * @param slotId The slot ID that the IMS service is created for. |
| 5746 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5747 | */ |
| 5748 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5749 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5750 | ImsFeature.FEATURE_MMTEL)) { |
| 5751 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5752 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5753 | } |
| 5754 | } |
| 5755 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5756 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5757 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5758 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5759 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5760 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5761 | } |
| 5762 | return slotId; |
| 5763 | } |
| 5764 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5765 | private int getSlotIndex(int subId) { |
| 5766 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5767 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5768 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5769 | } |
| 5770 | return slotId; |
| 5771 | } |
| 5772 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5773 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5774 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5775 | */ |
| 5776 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5777 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5778 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5779 | try { |
| 5780 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5781 | } catch (SecurityException se) { |
| 5782 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5783 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5784 | + Binder.getCallingUid()); |
| 5785 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5786 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5787 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5788 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5789 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5790 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5791 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5792 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5793 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5794 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5795 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5796 | enforceTelephonyFeatureWithException(callingPackage, |
| 5797 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | final Phone phone = getPhone(subId); |
| 5802 | if (phone != null) { |
| 5803 | return phone.getServiceState().getDataNetworkType(); |
| 5804 | } else { |
| 5805 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5806 | } |
| 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | /** |
| 5813 | * Returns the data network type |
| 5814 | */ |
| 5815 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5816 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5817 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5818 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | /** |
| 5822 | * Returns the data network type for a subId |
| 5823 | */ |
| 5824 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5825 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5826 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5827 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5828 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5829 | mApp, functionName)) { |
| 5830 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5831 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5832 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5833 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5836 | enforceTelephonyFeatureWithException(callingPackage, |
| 5837 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
| 5841 | final Phone phone = getPhone(subId); |
| 5842 | if (phone != null) { |
| 5843 | return phone.getServiceState().getDataNetworkType(); |
| 5844 | } else { |
| 5845 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5846 | } |
| 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5849 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5853 | * Returns the Voice network type for a subId |
| 5854 | */ |
| 5855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5856 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5857 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5858 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5859 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5860 | mApp, functionName)) { |
| 5861 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5862 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5863 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5864 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5865 | } |
| 5866 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5867 | enforceTelephonyFeatureWithException(callingPackage, |
| 5868 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | final long identity = Binder.clearCallingIdentity(); |
| 5871 | try { |
| 5872 | final Phone phone = getPhone(subId); |
| 5873 | if (phone != null) { |
| 5874 | return phone.getServiceState().getVoiceNetworkType(); |
| 5875 | } else { |
| 5876 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5877 | } |
| 5878 | } finally { |
| 5879 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5880 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * @return true if a ICC card is present |
| 5885 | */ |
| 5886 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5887 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5888 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5889 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5893 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5894 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5895 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5896 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5897 | if (!mApp.getResources().getBoolean( |
| 5898 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5899 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5900 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5901 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | final long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5906 | if (phone != null) { |
| 5907 | return phone.getIccCard().hasIccCard(); |
| 5908 | } else { |
| 5909 | return false; |
| 5910 | } |
| 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5913 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | /** |
| 5917 | * Return if the current radio is LTE on CDMA. This |
| 5918 | * is a tri-state return value as for a period of time |
| 5919 | * the mode may be unknown. |
| 5920 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5921 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5922 | * @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] | 5923 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5924 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5925 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5926 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5927 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5928 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5929 | } |
| 5930 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5931 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5932 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5933 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5934 | try { |
| 5935 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5936 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5937 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5938 | } |
| 5939 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5940 | enforceTelephonyFeatureWithException(callingPackage, |
| 5941 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | final long identity = Binder.clearCallingIdentity(); |
| 5944 | try { |
| 5945 | final Phone phone = getPhone(subId); |
| 5946 | if (phone == null) { |
| 5947 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5948 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5949 | return TelephonyProperties.lte_on_cdma_device() |
| 5950 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | } |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5954 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5957 | /** |
| 5958 | * {@hide} |
| 5959 | * Returns Default subId, 0 in the case of single standby. |
| 5960 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5961 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5962 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5965 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5966 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5967 | } |
| 5968 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5969 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5970 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5971 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5972 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5973 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5974 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5975 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5978 | /** |
| 5979 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5980 | */ |
| 5981 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | final long identity = Binder.clearCallingIdentity(); |
| 5983 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5984 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5986 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5987 | } finally { |
| 5988 | Binder.restoreCallingIdentity(identity); |
| 5989 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | /** |
| 5993 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5994 | */ |
| 5995 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | final long identity = Binder.clearCallingIdentity(); |
| 5997 | try { |
| 5998 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5999 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
| 6003 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 6006 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 6007 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 6008 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 6009 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 6010 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6011 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 6012 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 6013 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6014 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6015 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6016 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6017 | } |
| 6018 | return PhoneFactory.getPhone(phoneId); |
| 6019 | } |
| 6020 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6021 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6022 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6023 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6024 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6025 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6026 | /*message=*/ "iccOpenLogicalChannel"); |
| 6027 | |
| 6028 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 6029 | // Verify that the callingPackage in the request belongs to the calling UID |
| 6030 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 6031 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6032 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6033 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 6034 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6035 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6036 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6037 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6038 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6039 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6040 | Phone phone; |
| 6041 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6043 | mApp, request.subId, message); |
| 6044 | phone = getPhoneFromSubId(request.subId); |
| 6045 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6046 | enforceModifyPermission(); |
| 6047 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6048 | } else { |
| 6049 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6050 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6051 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6055 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | final long identity = Binder.clearCallingIdentity(); |
| 6057 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6058 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6059 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6060 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6061 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6062 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6063 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6064 | loge("The calling package is not allowed to access ISD-R."); |
| 6065 | throw new SecurityException( |
| 6066 | "The calling package is not allowed to access ISD-R."); |
| 6067 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6068 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6071 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6072 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | return response; |
| 6074 | } finally { |
| 6075 | Binder.restoreCallingIdentity(identity); |
| 6076 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6080 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6081 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6082 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6083 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6084 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6085 | /*message=*/"iccCloseLogicalChannel"); |
| 6086 | |
| 6087 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6088 | |
| 6089 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6090 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6091 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6092 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6093 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6094 | // before this feature is enabled, this API should only return false if |
| 6095 | // the operation fails instead of throwing runtime exception for |
| 6096 | // backward-compatibility. |
| 6097 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6098 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | final long identity = Binder.clearCallingIdentity(); |
| 6100 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6101 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6102 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6103 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6104 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6105 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6106 | Boolean success = false; |
| 6107 | if (result instanceof RuntimeException) { |
| 6108 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6109 | if (shouldThrowExceptionOnFailure) { |
| 6110 | throw (RuntimeException) result; |
| 6111 | } else { |
| 6112 | return false; |
| 6113 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6114 | } else if (result instanceof Boolean) { |
| 6115 | success = (Boolean) result; |
| 6116 | } else { |
| 6117 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6118 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6119 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | return success; |
| 6121 | } finally { |
| 6122 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6123 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6127 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6128 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6130 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6131 | |
| 6132 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6133 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6134 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6135 | if (DBG) { |
| 6136 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6137 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6138 | + p3 + " data=" + data); |
| 6139 | } |
| 6140 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6141 | command, p1, p2, p3, data); |
| 6142 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6143 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6144 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6145 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6146 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6147 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6148 | |
| 6149 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6150 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6151 | "iccTransmitApduLogicalChannelBySlot"); |
| 6152 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6153 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6154 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6155 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6156 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6157 | } |
| 6158 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6159 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6160 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6164 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | final long identity = Binder.clearCallingIdentity(); |
| 6166 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6167 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | return ""; |
| 6169 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6172 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6173 | null /* workSource */); |
| 6174 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6176 | // Append the returned status code to the end of the response payload. |
| 6177 | String s = Integer.toHexString( |
| 6178 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6179 | if (response.payload != null) { |
| 6180 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6181 | } |
| 6182 | return s; |
| 6183 | } finally { |
| 6184 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6185 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6186 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6187 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6188 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6189 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6190 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6192 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6194 | |
| 6195 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6196 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6197 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6198 | if (DBG) { |
| 6199 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6200 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6201 | } |
| 6202 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6203 | cla, command, p1, p2, p3, data); |
| 6204 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6205 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6206 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6207 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6208 | 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] | 6209 | enforceModifyPermission(); |
| 6210 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6211 | |
| 6212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6213 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6214 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6215 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6216 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6217 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6218 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6222 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6223 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6227 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6228 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | final long identity = Binder.clearCallingIdentity(); |
| 6230 | try { |
| 6231 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6232 | && TextUtils.equals(ISDR_AID, data)) { |
| 6233 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6234 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6235 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6236 | if (bestComponent == null |
| 6237 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6238 | loge("The calling package is not allowed to select ISD-R."); |
| 6239 | throw new SecurityException( |
| 6240 | "The calling package is not allowed to select ISD-R."); |
| 6241 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6242 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6245 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6246 | null /* workSource */); |
| 6247 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6248 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 | // Append the returned status code to the end of the response payload. |
| 6250 | String s = Integer.toHexString( |
| 6251 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6252 | if (response.payload != null) { |
| 6253 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6254 | } |
| 6255 | return s; |
| 6256 | } finally { |
| 6257 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6258 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6262 | 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] | 6263 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6265 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6266 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6267 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6268 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | final long identity = Binder.clearCallingIdentity(); |
| 6271 | try { |
| 6272 | if (DBG) { |
| 6273 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6274 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6275 | } |
| 6276 | |
| 6277 | IccIoResult response = |
| 6278 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6279 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6280 | subId); |
| 6281 | |
| 6282 | if (DBG) { |
| 6283 | log("Exchange SIM_IO [R]" + response); |
| 6284 | } |
| 6285 | |
| 6286 | byte[] result = null; |
| 6287 | int length = 2; |
| 6288 | if (response.payload != null) { |
| 6289 | length = 2 + response.payload.length; |
| 6290 | result = new byte[length]; |
| 6291 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6292 | } else { |
| 6293 | result = new byte[length]; |
| 6294 | } |
| 6295 | |
| 6296 | result[length - 1] = (byte) response.sw2; |
| 6297 | result[length - 2] = (byte) response.sw1; |
| 6298 | return result; |
| 6299 | } finally { |
| 6300 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6301 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6302 | } |
| 6303 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6304 | /** |
| 6305 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6306 | * on a particular subscription |
| 6307 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6308 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6309 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6311 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6312 | return null; |
| 6313 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6314 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6315 | enforceTelephonyFeatureWithException(callingPackage, |
| 6316 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | final long identity = Binder.clearCallingIdentity(); |
| 6319 | try { |
| 6320 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6321 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6322 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6323 | return null; |
| 6324 | } |
| 6325 | Object response = sendRequest( |
| 6326 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6327 | if (response instanceof String[]) { |
| 6328 | return (String[]) response; |
| 6329 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6330 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6332 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6335 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6336 | } |
| 6337 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6338 | /** |
| 6339 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6340 | * subscription. |
| 6341 | * |
| 6342 | * @param subId the id of the subscription. |
| 6343 | * @param appType the uicc app type, must be USIM or SIM. |
| 6344 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6345 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6346 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6347 | * @return number of fplmns that is successfully written to the SIM. |
| 6348 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6349 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6350 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6352 | mApp, subId, "setForbiddenPlmns"); |
| 6353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6354 | enforceTelephonyFeatureWithException(callingPackage, |
| 6355 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6356 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6357 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6358 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6359 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6360 | } |
| 6361 | if (fplmns == null) { |
| 6362 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6363 | } |
| 6364 | for (String fplmn : fplmns) { |
| 6365 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6366 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6367 | } |
| 6368 | } |
| 6369 | final long identity = Binder.clearCallingIdentity(); |
| 6370 | try { |
| 6371 | Object response = sendRequest( |
| 6372 | CMD_SET_FORBIDDEN_PLMNS, |
| 6373 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6374 | subId); |
| 6375 | return (int) response; |
| 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
| 6379 | } |
| 6380 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6381 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6382 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6383 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6384 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6385 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6386 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6387 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | final long identity = Binder.clearCallingIdentity(); |
| 6390 | try { |
| 6391 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6392 | if (response.payload == null) { |
| 6393 | return ""; |
| 6394 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6395 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6396 | // Append the returned status code to the end of the response payload. |
| 6397 | String s = Integer.toHexString( |
| 6398 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6399 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6400 | return s; |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6404 | } |
| 6405 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6406 | /** |
| 6407 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6408 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6409 | * |
| 6410 | * @param itemID the ID of the item to read |
| 6411 | * @return the NV item as a String, or null on error. |
| 6412 | */ |
| 6413 | @Override |
| 6414 | public String nvReadItem(int itemID) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 6415 | if (mFeatureFlags.cleanupCdma()) return null; |
| 6416 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6417 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6418 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6419 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | |
| 6421 | final long identity = Binder.clearCallingIdentity(); |
| 6422 | try { |
| 6423 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6424 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6425 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6426 | return value; |
| 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | /** |
| 6433 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6434 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6435 | * |
| 6436 | * @param itemID the ID of the item to read |
| 6437 | * @param itemValue the value to write, as a String |
| 6438 | * @return true on success; false on any failure |
| 6439 | */ |
| 6440 | @Override |
| 6441 | public boolean nvWriteItem(int itemID, String itemValue) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 6442 | if (mFeatureFlags.cleanupCdma()) return false; |
| 6443 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6444 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6446 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6451 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6452 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6453 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6454 | return success; |
| 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
| 6457 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | /** |
| 6461 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6462 | * Used for device configuration by some CDMA operators. |
| 6463 | * |
| 6464 | * @param preferredRoamingList byte array containing the new PRL |
| 6465 | * @return true on success; false on any failure |
| 6466 | */ |
| 6467 | @Override |
| 6468 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 6469 | if (mFeatureFlags.cleanupCdma()) return false; |
| 6470 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6471 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6472 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6473 | |
| 6474 | final long identity = Binder.clearCallingIdentity(); |
| 6475 | try { |
| 6476 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6477 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6478 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6479 | return success; |
| 6480 | } finally { |
| 6481 | Binder.restoreCallingIdentity(identity); |
| 6482 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6486 | * 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] | 6487 | * Used for device configuration by some CDMA operators. |
| 6488 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6489 | * @param slotIndex - device slot. |
| 6490 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6491 | * @return true on success; false on any failure |
| 6492 | */ |
| 6493 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6494 | public boolean resetModemConfig(int slotIndex) { |
Tomasz Wasilczyk | f1af36c | 2024-12-05 11:36:37 -0800 | [diff] [blame] | 6495 | if (mFeatureFlags.cleanupCdma()) return false; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6496 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6497 | if (phone != null) { |
| 6498 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6499 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6500 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6501 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6502 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6503 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6504 | final long identity = Binder.clearCallingIdentity(); |
| 6505 | try { |
| 6506 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6507 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6508 | return success; |
| 6509 | } finally { |
| 6510 | Binder.restoreCallingIdentity(identity); |
| 6511 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6512 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6513 | return false; |
| 6514 | } |
| 6515 | |
| 6516 | /** |
| 6517 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6518 | * |
| 6519 | * @param slotIndex - device slot. |
| 6520 | * |
| 6521 | * @return true on success; false on any failure |
| 6522 | */ |
| 6523 | @Override |
| 6524 | public boolean rebootModem(int slotIndex) { |
| 6525 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6526 | if (phone != null) { |
| 6527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6528 | mApp, phone.getSubId(), "rebootModem"); |
| 6529 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6530 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6531 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6532 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
| 6535 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6536 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6537 | return success; |
| 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
| 6540 | } |
| 6541 | } |
| 6542 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6543 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6544 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6545 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6546 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6547 | * {@link #disableIms(int)}. |
| 6548 | * @param slotIndex device slot. |
| 6549 | */ |
| 6550 | public void resetIms(int slotIndex) { |
| 6551 | enforceModifyPermission(); |
| 6552 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6553 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6554 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6555 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6556 | final long identity = Binder.clearCallingIdentity(); |
| 6557 | try { |
| 6558 | if (mImsResolver == null) { |
| 6559 | // may happen if the does not support IMS. |
| 6560 | return; |
| 6561 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6562 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6569 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6570 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6571 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6572 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -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 | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6578 | // may happen if the device does not support IMS. |
| 6579 | return; |
| 6580 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6581 | mImsResolver.enableIms(slotId); |
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 | } |
| 6586 | |
| 6587 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6588 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6589 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6590 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6591 | public void disableIms(int slotId) { |
| 6592 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | |
| 6594 | final long identity = Binder.clearCallingIdentity(); |
| 6595 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6596 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6597 | // may happen if the device does not support IMS. |
| 6598 | return; |
| 6599 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6600 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6601 | } finally { |
| 6602 | Binder.restoreCallingIdentity(identity); |
| 6603 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6607 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6608 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6609 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6610 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6611 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6612 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6613 | |
| 6614 | final long identity = Binder.clearCallingIdentity(); |
| 6615 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6616 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6617 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6618 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6619 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6620 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6621 | } finally { |
| 6622 | Binder.restoreCallingIdentity(identity); |
| 6623 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6624 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6625 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6626 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6627 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6628 | @Override |
| 6629 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6630 | enforceModifyPermission(); |
| 6631 | |
| 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6635 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6636 | } finally { |
| 6637 | Binder.restoreCallingIdentity(identity); |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6642 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6643 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6644 | */ |
| 6645 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6646 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6647 | |
| 6648 | final long identity = Binder.clearCallingIdentity(); |
| 6649 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6651 | // may happen if the device does not support IMS. |
| 6652 | return null; |
| 6653 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6655 | } finally { |
| 6656 | Binder.restoreCallingIdentity(identity); |
| 6657 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6658 | } |
| 6659 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6660 | /** |
| 6661 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6662 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6663 | */ |
| 6664 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6665 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6666 | |
| 6667 | final long identity = Binder.clearCallingIdentity(); |
| 6668 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6669 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6670 | // may happen if the device does not support IMS. |
| 6671 | return null; |
| 6672 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6673 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6674 | } finally { |
| 6675 | Binder.restoreCallingIdentity(identity); |
| 6676 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6677 | } |
| 6678 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6679 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6680 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6681 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6682 | * @param slotIndex the slot ID that the ImsService should bind for. |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6683 | * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL} |
| 6684 | * if there is no preference. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6685 | * @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] | 6686 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6687 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6688 | * @param packageName The name of the package that the current configuration will be replaced |
| 6689 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6690 | * @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] | 6691 | */ |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6692 | public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService, |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6693 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6694 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6696 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | final long identity = Binder.clearCallingIdentity(); |
| 6699 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6700 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6701 | // may happen if the device does not support IMS. |
| 6702 | return false; |
| 6703 | } |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6704 | return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId, |
| 6705 | isCarrierService, featureTypes); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | } finally { |
| 6707 | Binder.restoreCallingIdentity(identity); |
| 6708 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6709 | } |
| 6710 | |
| 6711 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6712 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6713 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6714 | * |
| 6715 | * This should only be used for testing. |
| 6716 | * |
| 6717 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6718 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6719 | */ |
| 6720 | @Override |
| 6721 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6722 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6723 | "clearCarrierImsServiceOverride"); |
| 6724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6725 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6726 | |
| 6727 | final long identity = Binder.clearCallingIdentity(); |
| 6728 | try { |
| 6729 | if (mImsResolver == null) { |
| 6730 | // may happen if the device does not support IMS. |
| 6731 | return false; |
| 6732 | } |
| 6733 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6734 | } finally { |
| 6735 | Binder.restoreCallingIdentity(identity); |
| 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6740 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6741 | * |
| 6742 | * @param slotId The slot that the ImsService is associated with. |
| 6743 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6744 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6745 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6746 | * @return the package name of the ImsService configuration. |
| 6747 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6748 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6749 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6750 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6751 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6752 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6754 | final long identity = Binder.clearCallingIdentity(); |
| 6755 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6756 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6757 | // may happen if the device does not support IMS. |
| 6758 | return ""; |
| 6759 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6760 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6761 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6762 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6763 | } finally { |
| 6764 | Binder.restoreCallingIdentity(identity); |
| 6765 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6768 | /** |
| 6769 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6770 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6771 | * @param callback A callback with an integer containing the |
| 6772 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6773 | */ |
| 6774 | @Override |
| 6775 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6776 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6777 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6778 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6779 | "IMS not available on device."); |
| 6780 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6781 | final long token = Binder.clearCallingIdentity(); |
| 6782 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6783 | int slotId = getSlotIndex(subId); |
| 6784 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6785 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6786 | + subId + "'"); |
| 6787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6788 | } |
| 6789 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6790 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6791 | try { |
| 6792 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6793 | } catch (RemoteException e) { |
| 6794 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6795 | + "Ignore"); |
| 6796 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6797 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6798 | } catch (ImsException e) { |
| 6799 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6800 | } finally { |
| 6801 | Binder.restoreCallingIdentity(token); |
| 6802 | } |
| 6803 | } |
| 6804 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6805 | /** |
| 6806 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6807 | */ |
| 6808 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6809 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6810 | |
| 6811 | final long identity = Binder.clearCallingIdentity(); |
| 6812 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6813 | // NOTE: Before S, this method only set the default phone. |
| 6814 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6815 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6816 | phone.setImsRegistrationState(registered); |
| 6817 | } |
| 6818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6819 | } finally { |
| 6820 | Binder.restoreCallingIdentity(identity); |
| 6821 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6822 | } |
| 6823 | |
| 6824 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6825 | * Set the network selection mode to automatic. |
| 6826 | * |
| 6827 | */ |
| 6828 | @Override |
| 6829 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6831 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6833 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6834 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6835 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | final long identity = Binder.clearCallingIdentity(); |
| 6837 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6838 | if (!isActiveSubscription(subId)) { |
| 6839 | return; |
| 6840 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6842 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 6843 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | } finally { |
| 6845 | Binder.restoreCallingIdentity(identity); |
| 6846 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6847 | } |
| 6848 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6849 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6850 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6851 | * |
| 6852 | * @param subId the id of the subscription. |
| 6853 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6854 | * the operator to attach to. |
| 6855 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6856 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6857 | * normal network selection next time. |
| 6858 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6859 | */ |
| 6860 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6861 | public boolean setNetworkSelectionModeManual( |
| 6862 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6864 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6865 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6866 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6867 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6868 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6869 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6870 | if (!isActiveSubscription(subId)) { |
| 6871 | return false; |
| 6872 | } |
| 6873 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6875 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6877 | if (DBG) { |
| 6878 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6879 | + " operator: " + operatorInfo); |
| 6880 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6881 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6882 | } finally { |
| 6883 | Binder.restoreCallingIdentity(identity); |
| 6884 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6885 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6886 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6887 | * Get the manual network selection |
| 6888 | * |
| 6889 | * @param subId the id of the subscription. |
| 6890 | * |
| 6891 | * @return the previously saved user selected PLMN |
| 6892 | */ |
| 6893 | @Override |
| 6894 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6895 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6896 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6897 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6898 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6899 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6900 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6901 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6902 | final long identity = Binder.clearCallingIdentity(); |
| 6903 | try { |
| 6904 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6905 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | final Phone phone = getPhone(subId); |
| 6909 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6910 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6911 | } |
| 6912 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6913 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6914 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6915 | } finally { |
| 6916 | Binder.restoreCallingIdentity(identity); |
| 6917 | } |
| 6918 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6919 | |
| 6920 | /** |
| 6921 | * Scans for available networks. |
| 6922 | */ |
| 6923 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6924 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6925 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6927 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6928 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6929 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6930 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6931 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6932 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6933 | .setCallingPid(Binder.getCallingPid()) |
| 6934 | .setCallingUid(Binder.getCallingUid()) |
| 6935 | .setMethod("getCellNetworkScanResults") |
| 6936 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6937 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6938 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6939 | .build()); |
| 6940 | switch (locationResult) { |
| 6941 | case DENIED_HARD: |
| 6942 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6943 | case DENIED_SOFT: |
| 6944 | return null; |
| 6945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6946 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6947 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6948 | try { |
| 6949 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6950 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6951 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | } finally { |
| 6953 | Binder.restoreCallingIdentity(identity); |
| 6954 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6958 | * Get the call forwarding info, given the call forwarding reason. |
| 6959 | */ |
| 6960 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6961 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6962 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6963 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6964 | |
| 6965 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6966 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6967 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6968 | long identity = Binder.clearCallingIdentity(); |
| 6969 | try { |
| 6970 | if (DBG) { |
| 6971 | log("getCallForwarding: subId " + subId |
| 6972 | + " callForwardingReason" + callForwardingReason); |
| 6973 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6974 | |
| 6975 | Phone phone = getPhone(subId); |
| 6976 | if (phone == null) { |
| 6977 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6978 | callback.onError( |
| 6979 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6980 | } catch (RemoteException e) { |
| 6981 | // ignore |
| 6982 | } |
| 6983 | return; |
| 6984 | } |
| 6985 | |
| 6986 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6987 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6988 | @Override |
| 6989 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6990 | try { |
| 6991 | callback.onCallForwardingInfoAvailable(info); |
| 6992 | } catch (RemoteException e) { |
| 6993 | // ignore |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | @Override |
| 6998 | public void onError(int error) { |
| 6999 | try { |
| 7000 | callback.onError(error); |
| 7001 | } catch (RemoteException e) { |
| 7002 | // ignore |
| 7003 | } |
| 7004 | } |
| 7005 | }); |
| 7006 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
| 7009 | } |
| 7010 | } |
| 7011 | |
| 7012 | /** |
| 7013 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 7014 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 7015 | */ |
| 7016 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7017 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 7018 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7019 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7020 | |
| 7021 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7022 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 7023 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7024 | long identity = Binder.clearCallingIdentity(); |
| 7025 | try { |
| 7026 | if (DBG) { |
| 7027 | log("setCallForwarding: subId " + subId |
| 7028 | + " callForwardingInfo" + callForwardingInfo); |
| 7029 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7030 | |
| 7031 | Phone phone = getPhone(subId); |
| 7032 | if (phone == null) { |
| 7033 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 7034 | callback.accept( |
| 7035 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7036 | } catch (RemoteException e) { |
| 7037 | // ignore |
| 7038 | } |
| 7039 | return; |
| 7040 | } |
| 7041 | |
| 7042 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7043 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7044 | |
| 7045 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
| 7048 | } |
| 7049 | } |
| 7050 | |
| 7051 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7052 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7053 | */ |
| 7054 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7055 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7056 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7057 | |
| 7058 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7059 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7060 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7061 | long identity = Binder.clearCallingIdentity(); |
| 7062 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7063 | Phone phone = getPhone(subId); |
| 7064 | if (phone == null) { |
| 7065 | try { |
| 7066 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7067 | } catch (RemoteException e) { |
| 7068 | // ignore |
| 7069 | } |
| 7070 | return; |
| 7071 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7072 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7073 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7074 | boolean requireUssd = c.getBoolean( |
| 7075 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7076 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7077 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7078 | if (requireUssd) { |
| 7079 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7080 | getSubscriptionCarrierId(subId)); |
| 7081 | String newUssdCommand = ""; |
| 7082 | try { |
| 7083 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7084 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7085 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7086 | } catch (NullPointerException e) { |
| 7087 | loge("Failed to generate USSD number" + e); |
| 7088 | } |
| 7089 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7090 | mMainThreadHandler, callback, carrierXmlParser, |
| 7091 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7092 | final String ussdCommand = newUssdCommand; |
| 7093 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7094 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7095 | }); |
| 7096 | } else { |
| 7097 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7098 | callback::accept); |
| 7099 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7100 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7101 | } finally { |
| 7102 | Binder.restoreCallingIdentity(identity); |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7107 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7108 | */ |
| 7109 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7110 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7111 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7112 | |
| 7113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7114 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7115 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7116 | long identity = Binder.clearCallingIdentity(); |
| 7117 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7118 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7119 | |
| 7120 | Phone phone = getPhone(subId); |
| 7121 | if (phone == null) { |
| 7122 | try { |
| 7123 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7124 | } catch (RemoteException e) { |
| 7125 | // ignore |
| 7126 | } |
| 7127 | return; |
| 7128 | } |
| 7129 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7130 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7131 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7132 | boolean requireUssd = c.getBoolean( |
| 7133 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7134 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7135 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7136 | if (requireUssd) { |
| 7137 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7138 | getSubscriptionCarrierId(subId)); |
| 7139 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7140 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7141 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7142 | String newUssdCommand = ""; |
| 7143 | try { |
| 7144 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7145 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7146 | .makeCommand(ssAction, null); |
| 7147 | } catch (NullPointerException e) { |
| 7148 | loge("Failed to generate USSD number" + e); |
| 7149 | } |
| 7150 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7151 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7152 | final String ussdCommand = newUssdCommand; |
| 7153 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7154 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7155 | }); |
| 7156 | } else { |
| 7157 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7158 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7159 | |
| 7160 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7161 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7162 | } finally { |
| 7163 | Binder.restoreCallingIdentity(identity); |
| 7164 | } |
| 7165 | } |
| 7166 | |
| 7167 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7168 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7169 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7170 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7171 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7172 | * location related information which will be sent if the caller already possess |
| 7173 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7174 | * @param request contains the radio access networks with bands/channels to scan |
| 7175 | * @param messenger callback messenger for scan results or errors |
| 7176 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7177 | * @return the id of the requested scan which can be used to stop the scan. |
| 7178 | */ |
| 7179 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7180 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7181 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7182 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7184 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7185 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7186 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7187 | if (!renounceFineLocationAccess) { |
| 7188 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7189 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7190 | .setCallingPackage(callingPackage) |
| 7191 | .setCallingFeatureId(callingFeatureId) |
| 7192 | .setCallingPid(Binder.getCallingPid()) |
| 7193 | .setCallingUid(Binder.getCallingUid()) |
| 7194 | .setMethod("requestNetworkScan") |
| 7195 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7196 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7197 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7198 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7199 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7200 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7201 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7202 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7203 | if (e != null) { |
| 7204 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7205 | throw e; |
| 7206 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7207 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7208 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7209 | } |
| 7210 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7211 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7212 | |
| 7213 | enforceTelephonyFeatureWithException(callingPackage, |
| 7214 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7215 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7216 | int callingUid = Binder.getCallingUid(); |
| 7217 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7218 | final long identity = Binder.clearCallingIdentity(); |
| 7219 | try { |
| 7220 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7221 | renounceFineLocationAccess, request, messenger, binder, |
| 7222 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7223 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7224 | } finally { |
| 7225 | Binder.restoreCallingIdentity(identity); |
| 7226 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7227 | } |
| 7228 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7229 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7230 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7231 | boolean hasCarrierPriv; |
| 7232 | final long identity = Binder.clearCallingIdentity(); |
| 7233 | try { |
| 7234 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7235 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
| 7238 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7239 | boolean hasNetworkScanPermission = |
| 7240 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7241 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7242 | |
| 7243 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7244 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7245 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7249 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7250 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7251 | return new SecurityException("Specific channels must not be" |
| 7252 | + " scanned without location access."); |
| 7253 | } |
| 7254 | } |
| 7255 | } |
| 7256 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7257 | return null; |
| 7258 | } |
| 7259 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7260 | /** |
| 7261 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7262 | * |
| 7263 | * @param subId id of the subscription |
| 7264 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7265 | */ |
| 7266 | @Override |
| 7267 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7269 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7271 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | final long identity = Binder.clearCallingIdentity(); |
| 7273 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7274 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7275 | } finally { |
| 7276 | Binder.restoreCallingIdentity(identity); |
| 7277 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7278 | } |
| 7279 | |
| 7280 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7281 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7282 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7283 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7284 | */ |
| 7285 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7286 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7287 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7288 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7289 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7291 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7292 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7294 | final long identity = Binder.clearCallingIdentity(); |
| 7295 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7296 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7297 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7298 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7299 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7300 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7301 | } finally { |
| 7302 | Binder.restoreCallingIdentity(identity); |
| 7303 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7304 | } |
| 7305 | |
| 7306 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7307 | * Get the allowed network types for certain reason. |
| 7308 | * |
| 7309 | * @param subId the id of the subscription. |
| 7310 | * @param reason the reason the allowed network type change is taking place |
| 7311 | * @return the allowed network types. |
| 7312 | */ |
| 7313 | @Override |
| 7314 | public long getAllowedNetworkTypesForReason(int subId, |
| 7315 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7316 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7317 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7318 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7319 | if (!mApp.getResources().getBoolean( |
| 7320 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7321 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7322 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7323 | "getAllowedNetworkTypesForReason"); |
| 7324 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7325 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7326 | final long identity = Binder.clearCallingIdentity(); |
| 7327 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7328 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7329 | } finally { |
| 7330 | Binder.restoreCallingIdentity(identity); |
| 7331 | } |
| 7332 | } |
| 7333 | |
| 7334 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7335 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7336 | * @param subId subscription id of the sim card |
| 7337 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7338 | * This can be passed following states |
| 7339 | * <ol> |
| 7340 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7341 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7342 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7343 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7344 | * </ol> |
| 7345 | * @return operation result. |
| 7346 | */ |
| 7347 | @Override |
| 7348 | public int setNrDualConnectivityState(int subId, |
| 7349 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7351 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7352 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7353 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7354 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7355 | } |
| 7356 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7357 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7358 | final long identity = Binder.clearCallingIdentity(); |
| 7359 | try { |
| 7360 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7361 | nrDualConnectivityState, subId, |
| 7362 | workSource); |
| 7363 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7364 | return result; |
| 7365 | } finally { |
| 7366 | Binder.restoreCallingIdentity(identity); |
| 7367 | } |
| 7368 | } |
| 7369 | |
| 7370 | /** |
| 7371 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7372 | * @return true if dual connectivity is enabled else false |
| 7373 | */ |
| 7374 | @Override |
| 7375 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7376 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7377 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7378 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7379 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7380 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7381 | return false; |
| 7382 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7383 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7384 | final long identity = Binder.clearCallingIdentity(); |
| 7385 | try { |
| 7386 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7387 | null, subId, workSource); |
| 7388 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7389 | return isEnabled; |
| 7390 | } finally { |
| 7391 | Binder.restoreCallingIdentity(identity); |
| 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7396 | * Set the allowed network types of the device and |
| 7397 | * provide the reason triggering the allowed network change. |
| 7398 | * |
| 7399 | * @param subId the id of the subscription. |
| 7400 | * @param reason the reason the allowed network type change is taking place |
| 7401 | * @param allowedNetworkTypes the allowed network types. |
| 7402 | * @return true on success; false on any failure. |
| 7403 | */ |
| 7404 | @Override |
| 7405 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7406 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7407 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7409 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7410 | // If the caller only has carrier privileges, then they should not be able to override |
| 7411 | // any network types which were set for security reasons. |
| 7412 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7413 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7414 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7415 | throw new SecurityException( |
| 7416 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7417 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7418 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7419 | |
| 7420 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7421 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7422 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7423 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7424 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7425 | return false; |
| 7426 | } |
| 7427 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7428 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7429 | return false; |
| 7430 | } |
| 7431 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7432 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7433 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7434 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7435 | Phone phone = getPhone(subId); |
| 7436 | if (phone == null) { |
| 7437 | return false; |
| 7438 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7439 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7440 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7441 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7442 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7443 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7444 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7445 | final long identity = Binder.clearCallingIdentity(); |
| 7446 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7447 | Boolean success = (Boolean) sendRequest( |
| 7448 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7449 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7450 | |
| 7451 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7452 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
| 7455 | } |
| 7456 | } |
| 7457 | |
| 7458 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7459 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7460 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7461 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7462 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7463 | * @hide |
| 7464 | */ |
| 7465 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7466 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7467 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7468 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7469 | if (!mApp.getResources().getBoolean( |
| 7470 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7471 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7472 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7473 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7475 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7476 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7477 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7478 | if (phone != null) { |
| 7479 | return phone.hasMatchedTetherApnSetting(); |
| 7480 | } else { |
| 7481 | return false; |
| 7482 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | } finally { |
| 7484 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7485 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7489 | * Get the user enabled state of Mobile Data. |
| 7490 | * |
| 7491 | * TODO: remove and use isUserDataEnabled. |
| 7492 | * This can't be removed now because some vendor codes |
| 7493 | * calls through ITelephony directly while they should |
| 7494 | * use TelephonyManager. |
| 7495 | * |
| 7496 | * @return true on enabled |
| 7497 | */ |
| 7498 | @Override |
| 7499 | public boolean getDataEnabled(int subId) { |
| 7500 | return isUserDataEnabled(subId); |
| 7501 | } |
| 7502 | |
| 7503 | /** |
| 7504 | * Get whether mobile data is enabled per user setting. |
| 7505 | * |
| 7506 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7507 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7508 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7509 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7510 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7511 | * |
| 7512 | * @return {@code true} if data is enabled else {@code false} |
| 7513 | */ |
| 7514 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7515 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7516 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7517 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7518 | try { |
| 7519 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7520 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7521 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7522 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7523 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7524 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7526 | mApp, subId, functionName); |
| 7527 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | |
| 7530 | final long identity = Binder.clearCallingIdentity(); |
| 7531 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7532 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7533 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7534 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7535 | if (phone != null) { |
| 7536 | boolean retVal = phone.isUserDataEnabled(); |
| 7537 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7538 | return retVal; |
| 7539 | } else { |
| 7540 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7541 | return false; |
| 7542 | } |
| 7543 | } finally { |
| 7544 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7545 | } |
| 7546 | } |
| 7547 | |
| 7548 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7549 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7550 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7551 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7552 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7553 | * @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] | 7554 | */ |
| 7555 | @Override |
| 7556 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7557 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7558 | try { |
| 7559 | try { |
| 7560 | mApp.enforceCallingOrSelfPermission( |
| 7561 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7562 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7563 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7564 | try { |
| 7565 | mApp.enforceCallingOrSelfPermission( |
| 7566 | android.Manifest.permission.READ_PHONE_STATE, |
| 7567 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7568 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7569 | mApp.enforceCallingOrSelfPermission( |
| 7570 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7571 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7572 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7573 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7574 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7575 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7576 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7577 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7578 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7579 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7582 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7584 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7585 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7586 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7587 | return retVal; |
| 7588 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7589 | if (DBG) { |
| 7590 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7591 | + subId + " retVal=false"); |
| 7592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | return false; |
| 7594 | } |
| 7595 | } finally { |
| 7596 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7597 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7598 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7599 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7600 | /** |
| 7601 | * Check if data is enabled for a specific reason |
| 7602 | * @param subId Subscription index |
| 7603 | * @param reason the reason the data enable change is taking place |
| 7604 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7605 | */ |
| 7606 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7607 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7608 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7609 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7610 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7611 | try { |
| 7612 | mApp.enforceCallingOrSelfPermission( |
| 7613 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7614 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7615 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7616 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7617 | functionName); |
| 7618 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7619 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7620 | try { |
| 7621 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7622 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7623 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7625 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7626 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7627 | } |
| 7628 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7629 | if (!mApp.getResources().getBoolean( |
| 7630 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7631 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7632 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7633 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7634 | |
| 7635 | final long identity = Binder.clearCallingIdentity(); |
| 7636 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7637 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7638 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7639 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7640 | + " reason=" + reason); |
| 7641 | } |
| 7642 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7643 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7644 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7645 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7646 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7647 | return retVal; |
| 7648 | } else { |
| 7649 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7650 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7651 | + subId + " retVal=false"); |
| 7652 | } |
| 7653 | return false; |
| 7654 | } |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
| 7657 | } |
| 7658 | } |
| 7659 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7660 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7661 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7662 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7663 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7664 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7665 | // No permission needed; this only lets the caller inspect their own status. |
| 7666 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7667 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7668 | |
| 7669 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7670 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7671 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7672 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7673 | if (!mApp.getResources().getBoolean( |
| 7674 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7675 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7676 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7677 | "getCarrierPrivilegeStatusForUid"); |
| 7678 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7679 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7680 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7681 | } |
| 7682 | |
| 7683 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7684 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7685 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7686 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7687 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7688 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7689 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7690 | if (cpt == null) { |
| 7691 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7692 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7693 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7694 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7695 | } |
| 7696 | |
| 7697 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7698 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7699 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7700 | |
| 7701 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7702 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7703 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7704 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7705 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7706 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7707 | Phone phone = getPhone(subId); |
| 7708 | if (phone == null) { |
| 7709 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7710 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7711 | } |
| 7712 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7713 | if (cpt == null) { |
| 7714 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7715 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7716 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7717 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | @Override |
| 7721 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7722 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7723 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7724 | if (!mApp.getResources().getBoolean( |
| 7725 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7726 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7727 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7728 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7729 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7730 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7731 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7732 | } |
| 7733 | |
| 7734 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7735 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7736 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7737 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7738 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7739 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7740 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7741 | if (phone == null) { |
| 7742 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7743 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7744 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7745 | if (cpt == null) { |
| 7746 | continue; |
| 7747 | } |
| 7748 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7749 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7750 | break; |
| 7751 | } |
| 7752 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7753 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7754 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7755 | |
| 7756 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7757 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7758 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7759 | |
| 7760 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7761 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7762 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7763 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7764 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7765 | if (phone == null) { |
| 7766 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7767 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7768 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7769 | if (cpt == null) { |
| 7770 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7771 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7772 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7775 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7776 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7777 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Yan Yan | 965c84f | 2024-09-24 18:14:17 -0700 | [diff] [blame] | 7778 | |
| 7779 | enforceTelephonyFeatureWithException( |
| 7780 | getCurrentPackageName(), |
| 7781 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7782 | "getPackagesWithCarrierPrivileges"); |
| 7783 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7784 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7785 | if (phone == null) { |
| 7786 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7787 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7788 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7789 | if (cpt == null) { |
| 7790 | return Collections.emptyList(); |
| 7791 | } |
| 7792 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7793 | } |
| 7794 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7795 | @Override |
| 7796 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7797 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7798 | |
| 7799 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7800 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7801 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7802 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7803 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7804 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7805 | try { |
| 7806 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7807 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7808 | } |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7811 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7812 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7813 | } |
| 7814 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7815 | @Override |
| 7816 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7817 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7818 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7819 | if (!mApp.getResources().getBoolean( |
| 7820 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7821 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7822 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7823 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7824 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7825 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7826 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7827 | if (phone == null) { |
| 7828 | return null; |
| 7829 | } |
| 7830 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7831 | if (cpt == null) { |
| 7832 | return null; |
| 7833 | } |
| 7834 | return cpt.getCarrierServicePackageName(); |
| 7835 | } |
| 7836 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7837 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7838 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7839 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7840 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7841 | return null; |
| 7842 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7843 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7844 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7845 | return null; |
| 7846 | } |
| 7847 | return iccId; |
| 7848 | } |
| 7849 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7850 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7851 | public void setCallComposerStatus(int subId, int status) { |
| 7852 | enforceModifyPermission(); |
| 7853 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7854 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7855 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7856 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7857 | final long identity = Binder.clearCallingIdentity(); |
| 7858 | try { |
| 7859 | Phone phone = getPhone(subId); |
| 7860 | if (phone != null) { |
| 7861 | Phone defaultPhone = phone.getImsPhone(); |
| 7862 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7863 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7864 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7865 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7866 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7867 | } |
| 7868 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7869 | } catch (ImsException e) { |
| 7870 | throw new ServiceSpecificException(e.getCode()); |
| 7871 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7872 | Binder.restoreCallingIdentity(identity); |
| 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | @Override |
| 7877 | public int getCallComposerStatus(int subId) { |
| 7878 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7879 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7880 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7881 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7882 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7883 | final long identity = Binder.clearCallingIdentity(); |
| 7884 | try { |
| 7885 | Phone phone = getPhone(subId); |
| 7886 | if (phone != null) { |
| 7887 | Phone defaultPhone = phone.getImsPhone(); |
| 7888 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7889 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7890 | return imsPhone.getCallComposerStatus(); |
| 7891 | } |
| 7892 | } |
| 7893 | } finally { |
| 7894 | Binder.restoreCallingIdentity(identity); |
| 7895 | } |
| 7896 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7897 | } |
| 7898 | |
| 7899 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7900 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7901 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7902 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7903 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7904 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7905 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7906 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7907 | "setLine1NumberForDisplayForSubscriber"); |
| 7908 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7909 | final long identity = Binder.clearCallingIdentity(); |
| 7910 | try { |
| 7911 | final String iccId = getIccId(subId); |
| 7912 | final Phone phone = getPhone(subId); |
| 7913 | if (phone == null) { |
| 7914 | return false; |
| 7915 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7916 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7917 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7918 | return false; |
| 7919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7920 | final String subscriberId = phone.getSubscriberId(); |
| 7921 | |
| 7922 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7923 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7924 | + subscriberId + " to " + number); |
| 7925 | } |
| 7926 | |
| 7927 | if (TextUtils.isEmpty(iccId)) { |
| 7928 | return false; |
| 7929 | } |
| 7930 | |
| 7931 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7932 | |
| 7933 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7934 | if (alphaTag == null) { |
| 7935 | editor.remove(alphaTagPrefKey); |
| 7936 | } else { |
| 7937 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7938 | } |
| 7939 | |
| 7940 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7941 | // track all merged IMSIs based on line number |
| 7942 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7943 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7944 | if (number == null) { |
| 7945 | editor.remove(numberPrefKey); |
| 7946 | editor.remove(subscriberPrefKey); |
| 7947 | } else { |
| 7948 | editor.putString(numberPrefKey, number); |
| 7949 | editor.putString(subscriberPrefKey, subscriberId); |
| 7950 | } |
| 7951 | |
| 7952 | editor.commit(); |
| 7953 | return true; |
| 7954 | } finally { |
| 7955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7956 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7957 | } |
| 7958 | |
| 7959 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7960 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7961 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7962 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7964 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7965 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7966 | return null; |
| 7967 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7968 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7969 | if (!mApp.getResources().getBoolean( |
| 7970 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7971 | enforceTelephonyFeatureWithException(callingPackage, |
| 7972 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7973 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
| 7977 | String iccId = getIccId(subId); |
| 7978 | if (iccId != null) { |
| 7979 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7980 | if (DBG_MERGE) { |
| 7981 | log("getLine1NumberForDisplay returning " |
| 7982 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7983 | } |
| 7984 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7987 | return null; |
| 7988 | } finally { |
| 7989 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7990 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7991 | } |
| 7992 | |
| 7993 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7994 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7995 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7996 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7997 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7998 | return null; |
| 7999 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | final long identity = Binder.clearCallingIdentity(); |
| 8002 | try { |
| 8003 | String iccId = getIccId(subId); |
| 8004 | if (iccId != null) { |
| 8005 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 8006 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 8007 | } |
| 8008 | return null; |
| 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8011 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8012 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8013 | |
| 8014 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8015 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 8016 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8017 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 8018 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8019 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8020 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8021 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8022 | return null; |
| 8023 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8024 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 8025 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 8026 | // the process, where TelephonyManager was instantiated. |
| 8027 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8028 | final long identity = Binder.clearCallingIdentity(); |
| 8029 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8030 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8031 | final TelephonyManager tele = TelephonyManager.from(context); |
| 8032 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 8033 | |
| 8034 | // Figure out what subscribers are currently active |
| 8035 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 8037 | // Only consider subs which match the current subId |
| 8038 | // This logic can be simplified. See b/131189269 for progress. |
| 8039 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8040 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8042 | |
| 8043 | // First pass, find a number override for an active subscriber |
| 8044 | String mergeNumber = null; |
| 8045 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8046 | for (String key : prefs.keySet()) { |
| 8047 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8048 | final String subscriberId = (String) prefs.get(key); |
| 8049 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8050 | final String iccId = key.substring( |
| 8051 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8052 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8053 | mergeNumber = (String) prefs.get(numberKey); |
| 8054 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8055 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | + " for active subscriber " + subscriberId); |
| 8057 | } |
| 8058 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8059 | break; |
| 8060 | } |
| 8061 | } |
| 8062 | } |
| 8063 | } |
| 8064 | |
| 8065 | // Shortcut when no active merged subscribers |
| 8066 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8067 | return null; |
| 8068 | } |
| 8069 | |
| 8070 | // Second pass, find all subscribers under that line override |
| 8071 | final ArraySet<String> result = new ArraySet<>(); |
| 8072 | for (String key : prefs.keySet()) { |
| 8073 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8074 | final String number = (String) prefs.get(key); |
| 8075 | if (mergeNumber.equals(number)) { |
| 8076 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8077 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8078 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8079 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8080 | result.add(subscriberId); |
| 8081 | } |
| 8082 | } |
| 8083 | } |
| 8084 | } |
| 8085 | |
| 8086 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8087 | Arrays.sort(resultArray); |
| 8088 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8089 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8090 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8091 | } |
| 8092 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8093 | } finally { |
| 8094 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8095 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8096 | } |
| 8097 | |
| 8098 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8099 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8100 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8101 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8102 | enforceTelephonyFeatureWithException(callingPackage, |
| 8103 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8104 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8105 | final long identity = Binder.clearCallingIdentity(); |
| 8106 | try { |
| 8107 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8108 | TelephonyManager.class); |
| 8109 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8110 | if (subscriberId == null) { |
| 8111 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8112 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8113 | + subId); |
| 8114 | } |
| 8115 | return null; |
| 8116 | } |
| 8117 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8118 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8119 | .getSubscriptionInfo(subId); |
| 8120 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8121 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8122 | if (groupUuid == null) { |
| 8123 | return new String[]{subscriberId}; |
| 8124 | } |
| 8125 | |
| 8126 | // Get all subscriberIds from the group. |
| 8127 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8128 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8129 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8130 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8131 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8132 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8133 | if (subscriberId != null) { |
| 8134 | mergedSubscriberIds.add(subscriberId); |
| 8135 | } |
| 8136 | } |
| 8137 | |
| 8138 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8139 | } finally { |
| 8140 | Binder.restoreCallingIdentity(identity); |
| 8141 | |
| 8142 | } |
| 8143 | } |
| 8144 | |
| 8145 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8146 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8147 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8148 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8150 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8151 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8152 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
| 8155 | final Phone phone = getPhone(subId); |
| 8156 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8157 | } finally { |
| 8158 | Binder.restoreCallingIdentity(identity); |
| 8159 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8160 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8161 | |
| 8162 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8163 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8164 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8165 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8166 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8167 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8168 | |
| 8169 | final long identity = Binder.clearCallingIdentity(); |
| 8170 | try { |
| 8171 | final Phone phone = getPhone(subId); |
| 8172 | if (phone == null) { |
| 8173 | return false; |
| 8174 | } |
| 8175 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8176 | cdmaNonRoamingList); |
| 8177 | } finally { |
| 8178 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8179 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8183 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8184 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8185 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8186 | if (phone == null) { |
| 8187 | return raf; |
| 8188 | } |
| 8189 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8190 | try { |
| 8191 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8192 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8193 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8194 | } catch (SecurityException e) { |
| 8195 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8196 | throw e; |
| 8197 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8198 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8199 | if (!mApp.getResources().getBoolean( |
| 8200 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8201 | enforceTelephonyFeatureWithException(callingPackage, |
| 8202 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8203 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8205 | final long identity = Binder.clearCallingIdentity(); |
| 8206 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8207 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8208 | } finally { |
| 8209 | Binder.restoreCallingIdentity(identity); |
| 8210 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8211 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8212 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8213 | |
| 8214 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8215 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8216 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8217 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8218 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8219 | enforceTelephonyFeatureWithException(callingPackage, |
| 8220 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8221 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8222 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8223 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8224 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8225 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8226 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8227 | throw new SecurityException("App must be the dialer role holder to" |
| 8228 | + " upload a call composer pic"); |
| 8229 | } |
| 8230 | |
| 8231 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8232 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8233 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8234 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8235 | boolean readUntilEnd = false; |
| 8236 | int totalBytesRead = 0; |
| 8237 | byte[] buffer = new byte[16 * 1024]; |
| 8238 | while (true) { |
| 8239 | int numRead; |
| 8240 | try { |
| 8241 | numRead = input.read(buffer); |
| 8242 | } catch (IOException e) { |
| 8243 | try { |
| 8244 | fd.checkError(); |
| 8245 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8246 | null); |
| 8247 | } catch (IOException e1) { |
| 8248 | // This means that the other side closed explicitly with an error. If this |
| 8249 | // happens, log and ignore. |
| 8250 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8251 | } |
| 8252 | break; |
| 8253 | } |
| 8254 | if (numRead == -1) { |
| 8255 | readUntilEnd = true; |
| 8256 | break; |
| 8257 | } |
| 8258 | totalBytesRead += numRead; |
| 8259 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8260 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8261 | try { |
| 8262 | input.close(); |
| 8263 | } catch (IOException e) { |
| 8264 | // ignore |
| 8265 | } |
| 8266 | break; |
| 8267 | } |
| 8268 | output.write(buffer, 0, numRead); |
| 8269 | } |
| 8270 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8271 | // close is above, where the picture size is too big. |
| 8272 | |
| 8273 | try { |
| 8274 | fd.checkError(); |
| 8275 | } catch (IOException e) { |
| 8276 | loge("Remote end for call composer closed with an error: " + e); |
| 8277 | return; |
| 8278 | } |
| 8279 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8280 | if (!readUntilEnd) { |
| 8281 | loge("Did not finish reading entire image; aborting"); |
| 8282 | return; |
| 8283 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8284 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8285 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8286 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8287 | new CallComposerPictureTransfer.Factory() {}, |
| 8288 | imageData, |
| 8289 | (result) -> { |
| 8290 | if (result.first != null) { |
| 8291 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8292 | Bundle outputResult = new Bundle(); |
| 8293 | outputResult.putParcelable( |
| 8294 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8295 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8296 | outputResult); |
| 8297 | } else { |
| 8298 | callback.send(result.second, null); |
| 8299 | } |
| 8300 | } |
| 8301 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8302 | }); |
| 8303 | } |
| 8304 | |
| 8305 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8306 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8307 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8308 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8310 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8311 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8315 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8316 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8323 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8324 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8326 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8327 | return false; |
| 8328 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8329 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8330 | enforceTelephonyFeatureWithException(callingPackage, |
| 8331 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8332 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
| 8335 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8336 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8337 | // In the long run, we may instead need to check if there exists a connection service |
| 8338 | // which can support video calling. |
| 8339 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8340 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | return imsManager.isVtEnabledByPlatform() |
| 8342 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8343 | && imsManager.isVtEnabledByUser(); |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8347 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8348 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8349 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8350 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8351 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8352 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8353 | mApp, subId, callingPackage, callingFeatureId, |
| 8354 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8355 | return false; |
| 8356 | } |
| 8357 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8358 | enforceTelephonyFeatureWithException(callingPackage, |
| 8359 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8361 | final long identity = Binder.clearCallingIdentity(); |
| 8362 | try { |
| 8363 | CarrierConfigManager configManager = |
| 8364 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8365 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8366 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
| 8369 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8370 | } |
| 8371 | |
| 8372 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8373 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8375 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8376 | return false; |
| 8377 | } |
| 8378 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8379 | enforceTelephonyFeatureWithException(callingPackage, |
| 8380 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8382 | final long identity = Binder.clearCallingIdentity(); |
| 8383 | try { |
| 8384 | CarrierConfigManager configManager = |
| 8385 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8386 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8388 | } finally { |
| 8389 | Binder.restoreCallingIdentity(identity); |
| 8390 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8391 | } |
| 8392 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8393 | @Override |
| 8394 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8395 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8396 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8397 | } |
| 8398 | |
| 8399 | @Override |
| 8400 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8401 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8402 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8404 | final long identity = Binder.clearCallingIdentity(); |
| 8405 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8406 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | } finally { |
| 8408 | Binder.restoreCallingIdentity(identity); |
| 8409 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8410 | } |
| 8411 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8412 | /** |
| 8413 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8414 | * support for the feature and device firmware support. |
| 8415 | * |
| 8416 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8417 | */ |
| 8418 | @Override |
| 8419 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8420 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8421 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8424 | final Phone phone = getPhone(subscriptionId); |
| 8425 | if (phone == null) { |
| 8426 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8427 | return false; |
| 8428 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8429 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8430 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8431 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8432 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8433 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8434 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | return isCarrierSupported && isDeviceSupported; |
| 8436 | } finally { |
| 8437 | Binder.restoreCallingIdentity(identity); |
| 8438 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8439 | } |
| 8440 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8441 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8442 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8443 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8444 | * 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] | 8445 | */ |
| 8446 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | final long identity = Binder.clearCallingIdentity(); |
| 8448 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8449 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8450 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8451 | return false; |
| 8452 | } |
| 8453 | } |
| 8454 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8455 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8456 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8457 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8458 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8459 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8460 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8464 | } |
| 8465 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8466 | @Deprecated |
| 8467 | @Override |
| 8468 | public String getDeviceId(String callingPackage) { |
| 8469 | return getDeviceIdWithFeature(callingPackage, null); |
| 8470 | } |
| 8471 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8472 | /** |
| 8473 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8474 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8475 | * |
| 8476 | * <p>Requires Permission: |
| 8477 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8478 | */ |
| 8479 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8480 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8481 | try { |
| 8482 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8483 | } catch (SecurityException se) { |
| 8484 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8485 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8486 | + Binder.getCallingUid()); |
| 8487 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8488 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8489 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8490 | return null; |
| 8491 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8492 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8493 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8494 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8495 | return null; |
| 8496 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8497 | |
| 8498 | final long identity = Binder.clearCallingIdentity(); |
| 8499 | try { |
| 8500 | return phone.getDeviceId(); |
| 8501 | } finally { |
| 8502 | Binder.restoreCallingIdentity(identity); |
| 8503 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8504 | } |
| 8505 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8506 | /** |
| 8507 | * {@hide} |
| 8508 | * Returns the IMS Registration Status on a particular subid |
| 8509 | * |
| 8510 | * @param subId |
| 8511 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8512 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8513 | Phone phone = getPhone(subId); |
| 8514 | if (phone != null) { |
| 8515 | return phone.isImsRegistered(); |
| 8516 | } else { |
| 8517 | return false; |
| 8518 | } |
| 8519 | } |
| 8520 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8521 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8522 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8523 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8524 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8525 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8526 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8527 | } |
| 8528 | final long identity = Binder.clearCallingIdentity(); |
| 8529 | try { |
| 8530 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8531 | } finally { |
| 8532 | Binder.restoreCallingIdentity(identity); |
| 8533 | } |
| 8534 | } |
| 8535 | |
| 8536 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8537 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8538 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8539 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8540 | mApp, |
| 8541 | subscriptionId, |
| 8542 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8543 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8544 | |
| 8545 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8546 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8547 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8548 | final long identity = Binder.clearCallingIdentity(); |
| 8549 | try { |
| 8550 | Phone phone = getPhone(subscriptionId); |
| 8551 | if (phone == null) { |
| 8552 | return null; |
| 8553 | } |
| 8554 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8555 | } finally { |
| 8556 | Binder.restoreCallingIdentity(identity); |
| 8557 | } |
| 8558 | } |
| 8559 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8560 | /** |
| 8561 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8562 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8563 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8564 | final long identity = Binder.clearCallingIdentity(); |
| 8565 | try { |
| 8566 | Phone phone = getPhone(subId); |
| 8567 | if (phone != null) { |
| 8568 | return phone.isWifiCallingEnabled(); |
| 8569 | } else { |
| 8570 | return false; |
| 8571 | } |
| 8572 | } finally { |
| 8573 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8574 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8575 | } |
| 8576 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8577 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8578 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8579 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8580 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8581 | final long identity = Binder.clearCallingIdentity(); |
| 8582 | try { |
| 8583 | Phone phone = getPhone(subId); |
| 8584 | if (phone != null) { |
| 8585 | return phone.isVideoEnabled(); |
| 8586 | } else { |
| 8587 | return false; |
| 8588 | } |
| 8589 | } finally { |
| 8590 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8591 | } |
| 8592 | } |
| 8593 | |
| 8594 | /** |
| 8595 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8596 | * defined in {@link ImsRegistrationImplBase}. |
| 8597 | */ |
| 8598 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8599 | final long identity = Binder.clearCallingIdentity(); |
| 8600 | try { |
| 8601 | Phone phone = getPhone(subId); |
| 8602 | if (phone != null) { |
| 8603 | return phone.getImsRegistrationTech(); |
| 8604 | } else { |
| 8605 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8606 | } |
| 8607 | } finally { |
| 8608 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8609 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8610 | } |
| 8611 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8612 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8613 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8614 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8615 | |
| 8616 | enforceTelephonyFeatureWithException(callingPackage, |
| 8617 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8618 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8619 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8620 | return; |
| 8621 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8622 | Phone defaultPhone = getDefaultPhone(); |
| 8623 | if (defaultPhone != null) { |
| 8624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8625 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8626 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8627 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8628 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8629 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8630 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8631 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8632 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8633 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8634 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8635 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8636 | cleanUpAllowedNetworkTypes(phone, subId); |
TAKAHASHI Uichiro | c4b0745 | 2022-08-29 16:03:11 +0900 | [diff] [blame] | 8637 | |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8638 | setDataRoamingEnabled(subId, phone == null ? false |
| 8639 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
TAKAHASHI Uichiro | c4b0745 | 2022-08-29 16:03:11 +0900 | [diff] [blame] | 8640 | getPhone(subId).resetCarrierKeysForImsiEncryption(true); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8641 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8642 | // There has been issues when Sms raw table somehow stores orphan |
| 8643 | // fragments. They lead to garbled message when new fragments come |
| 8644 | // in and combined with those stale ones. In case this happens again, |
| 8645 | // user can reset all network settings which will clean up this table. |
| 8646 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8647 | // Clean up IMS settings as well here. |
| 8648 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8649 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8650 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8651 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8652 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8653 | if (defaultPhone == null) { |
| 8654 | return; |
| 8655 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8656 | // Erase modem config if erase modem on network setting is enabled. |
| 8657 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8658 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8659 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8660 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8661 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8662 | |
| 8663 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8664 | } finally { |
| 8665 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8666 | } |
| 8667 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8668 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8669 | @VisibleForTesting |
| 8670 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8671 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8672 | return; |
| 8673 | } |
| 8674 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8675 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8676 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8677 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8678 | "user=" + defaultNetworkType); |
| 8679 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8680 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8681 | defaultNetworkType, null); |
| 8682 | } |
| 8683 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8684 | private void cleanUpSmsRawTable(Context context) { |
| 8685 | ContentResolver resolver = context.getContentResolver(); |
| 8686 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8687 | resolver.delete(uri, null, null); |
| 8688 | } |
| 8689 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8690 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8691 | public String getSimLocaleForSubscriber(int subId) { |
| 8692 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8693 | |
| 8694 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8695 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8696 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8697 | final Phone phone = getPhone(subId); |
| 8698 | if (phone == null) { |
| 8699 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8700 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8702 | final long identity = Binder.clearCallingIdentity(); |
| 8703 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8704 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8705 | phone.getContext().getOpPackageName(), |
| 8706 | phone.getContext().getAttributionTag()); |
| 8707 | if (info == null) { |
| 8708 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8709 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8711 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8712 | // preferences (EF-PL and EF-LI)... |
| 8713 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8714 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8715 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8716 | if (localeFromDefaultSim != null) { |
| 8717 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8718 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8719 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8720 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8721 | } else { |
| 8722 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8723 | } |
| 8724 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8726 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8727 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8728 | // the SIM and carrier preferences does not include a country we add the country |
| 8729 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8730 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8731 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8732 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8733 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8734 | } |
| 8735 | |
| 8736 | if (DBG) log("No locale found - returning null"); |
| 8737 | return null; |
| 8738 | } finally { |
| 8739 | Binder.restoreCallingIdentity(identity); |
| 8740 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8741 | } |
| 8742 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8743 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8744 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8745 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8746 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8747 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8748 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8749 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8750 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8751 | return localeTag; |
| 8752 | } |
| 8753 | } |
| 8754 | return inputLocale.toLanguageTag(); |
| 8755 | } |
| 8756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8757 | /** |
| 8758 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8759 | */ |
| 8760 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8761 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8762 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8763 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8764 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8765 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8766 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8767 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8768 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8769 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8770 | * representing the state of the modem. |
| 8771 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8772 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8773 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8774 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8775 | */ |
| 8776 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8777 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8778 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8779 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8780 | if (!mApp.getResources().getBoolean( |
| 8781 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8782 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8783 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8784 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8785 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8786 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8787 | |
| 8788 | final long identity = Binder.clearCallingIdentity(); |
| 8789 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8790 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8791 | } finally { |
| 8792 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8793 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8794 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8795 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8796 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8797 | // less than total activity duration. |
| 8798 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8799 | if (info == null) { |
| 8800 | return false; |
| 8801 | } |
| 8802 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8803 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8804 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8805 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8806 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8807 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8808 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8809 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8810 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8811 | } |
| 8812 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8813 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8814 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8815 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8816 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8817 | |
| 8818 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8819 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8820 | } |
| 8821 | |
| 8822 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8823 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8824 | rat, |
| 8825 | freq, |
| 8826 | info.getReceiveTimeMillis(rat, freq) |
| 8827 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8828 | } |
| 8829 | |
| 8830 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8831 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8832 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8833 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8834 | |
| 8835 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8836 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8837 | } |
| 8838 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8839 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8840 | rat, |
| 8841 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8842 | } |
| 8843 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8844 | /** |
| 8845 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8846 | * @param info recent ModemActivityInfo |
| 8847 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8848 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8849 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8850 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8851 | boolean matched; |
| 8852 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8853 | matched = false; |
| 8854 | int rat = info.getSpecificInfoRat(i); |
| 8855 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8856 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8857 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8858 | //if it already exists |
| 8859 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8860 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8861 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8862 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8863 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8864 | updateLastModemActivityInfo(info, rat, freq); |
| 8865 | matched = true; |
| 8866 | } |
| 8867 | } else { |
| 8868 | updateLastModemActivityInfo(info, rat); |
| 8869 | matched = true; |
| 8870 | } |
| 8871 | } |
| 8872 | } |
| 8873 | |
| 8874 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8875 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8876 | new ActivityStatsTechSpecificInfo( |
| 8877 | rat, |
| 8878 | freq, |
| 8879 | info.getTransmitTimeMillis(rat, freq), |
| 8880 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8881 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8882 | } |
| 8883 | } |
| 8884 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8885 | mLastModemActivitySpecificInfo = |
| 8886 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8887 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8888 | |
| 8889 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8890 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8891 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8892 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8893 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8894 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8895 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8896 | |
| 8897 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8898 | new ModemActivityInfo( |
| 8899 | mLastModemActivityInfo.getTimestampMillis(), |
| 8900 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8901 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8902 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8903 | } |
| 8904 | |
| 8905 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8906 | ActivityStatsTechSpecificInfo[] info) { |
| 8907 | int infoSize = info.length; |
| 8908 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8909 | for (int i = 0; i < infoSize; i++) { |
| 8910 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8911 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8912 | info[i].getTransmitTimeMillis(), |
| 8913 | (int) info[i].getReceiveTimeMillis()); |
| 8914 | } |
| 8915 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8916 | } |
| 8917 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8918 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8919 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8920 | */ |
| 8921 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8922 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8923 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8924 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8925 | if (phone == null) { |
| 8926 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8927 | return null; |
| 8928 | } |
| 8929 | |
| 8930 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8931 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8932 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8933 | return null; |
| 8934 | } |
| 8935 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8936 | enforceTelephonyFeatureWithException(callingPackage, |
| 8937 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8938 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8939 | boolean hasFinePermission = false; |
| 8940 | boolean hasCoarsePermission = false; |
| 8941 | if (!renounceFineLocationAccess) { |
| 8942 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8943 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8944 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8945 | .setCallingPackage(callingPackage) |
| 8946 | .setCallingFeatureId(callingFeatureId) |
| 8947 | .setCallingPid(Binder.getCallingPid()) |
| 8948 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8949 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8950 | .setLogAsInfo(true) |
| 8951 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8952 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8953 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8954 | .build()); |
| 8955 | hasFinePermission = |
| 8956 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8957 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8958 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8959 | if (!renounceCoarseLocationAccess) { |
| 8960 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8961 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8962 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8963 | .setCallingPackage(callingPackage) |
| 8964 | .setCallingFeatureId(callingFeatureId) |
| 8965 | .setCallingPid(Binder.getCallingPid()) |
| 8966 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8967 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8968 | .setLogAsInfo(true) |
| 8969 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8970 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8971 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8972 | .build()); |
| 8973 | hasCoarsePermission = |
| 8974 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8975 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8976 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8977 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8979 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8980 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8981 | if (subInfo != null && !subInfo.isActive()) { |
| 8982 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8983 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8984 | } |
| 8985 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8986 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8987 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8988 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8989 | |
| 8990 | // Scrub out the location info in ServiceState depending on what level of access |
| 8991 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8992 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8993 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8994 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8995 | } finally { |
| 8996 | Binder.restoreCallingIdentity(identity); |
| 8997 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8998 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8999 | |
| 9000 | /** |
| 9001 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 9002 | * |
| 9003 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9004 | * voicemail ringtone. |
| 9005 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 9006 | * PhoneAccount. |
| 9007 | */ |
| 9008 | @Override |
| 9009 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9010 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9011 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 9012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9013 | final long identity = Binder.clearCallingIdentity(); |
| 9014 | try { |
| 9015 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9016 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9017 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9018 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9020 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9027 | * Sets the per-account voicemail ringtone. |
| 9028 | * |
| 9029 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9030 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9031 | * |
| 9032 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9033 | * voicemail ringtone. |
| 9034 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 9035 | * PhoneAccount. |
| 9036 | */ |
| 9037 | @Override |
| 9038 | public void setVoicemailRingtoneUri(String callingPackage, |
| 9039 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9040 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9041 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9042 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9043 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9045 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9046 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9048 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9049 | enforceTelephonyFeatureWithException(callingPackage, |
| 9050 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9052 | final long identity = Binder.clearCallingIdentity(); |
| 9053 | try { |
| 9054 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9055 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9056 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9057 | } |
| 9058 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9059 | } finally { |
| 9060 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9061 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9062 | } |
| 9063 | |
| 9064 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9065 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9066 | * |
| 9067 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9068 | * voicemail vibration setting. |
| 9069 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9070 | */ |
| 9071 | @Override |
| 9072 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9073 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9074 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9075 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9076 | final long identity = Binder.clearCallingIdentity(); |
| 9077 | try { |
| 9078 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9079 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9080 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9081 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9083 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9084 | } finally { |
| 9085 | Binder.restoreCallingIdentity(identity); |
| 9086 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9087 | } |
| 9088 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9089 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9090 | * Sets the per-account voicemail vibration. |
| 9091 | * |
| 9092 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9093 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9094 | * |
| 9095 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9096 | * voicemail vibration setting. |
| 9097 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9098 | * specific PhoneAccount. |
| 9099 | */ |
| 9100 | @Override |
| 9101 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9102 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9103 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9104 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9105 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9106 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9108 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9109 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9110 | } |
| 9111 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9112 | enforceTelephonyFeatureWithException(callingPackage, |
| 9113 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9115 | final long identity = Binder.clearCallingIdentity(); |
| 9116 | try { |
| 9117 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9118 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9119 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9120 | } |
| 9121 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9122 | } finally { |
| 9123 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9124 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9125 | } |
| 9126 | |
| 9127 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9128 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9129 | * |
| 9130 | * @throws SecurityException if the caller does not have the required permission |
| 9131 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9132 | @VisibleForTesting |
| 9133 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9134 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9135 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9136 | } |
| 9137 | |
| 9138 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9139 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9140 | * permission. |
| 9141 | * |
| 9142 | * @throws SecurityException if the caller does not have the required permission |
| 9143 | */ |
| 9144 | private void enforceSendSmsPermission() { |
| 9145 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9146 | } |
| 9147 | |
| 9148 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9149 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9150 | * users permission. |
| 9151 | * |
| 9152 | * @throws SecurityException if the caller does not have the required permission |
| 9153 | */ |
| 9154 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9155 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9156 | } |
| 9157 | |
| 9158 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9159 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9160 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9161 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9162 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9163 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9164 | final long identity = Binder.clearCallingIdentity(); |
| 9165 | try { |
| 9166 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9167 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9168 | if (componentName == null) { |
| 9169 | throw new SecurityException( |
| 9170 | "Caller not current active visual voicemail package[null]"); |
| 9171 | } |
| 9172 | String vvmPackage = componentName.getPackageName(); |
| 9173 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9174 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9175 | } |
| 9176 | } finally { |
| 9177 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9178 | } |
| 9179 | } |
| 9180 | |
| 9181 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9182 | * Return the application ID for the app type. |
| 9183 | * |
| 9184 | * @param subId the subscription ID that this request applies to. |
| 9185 | * @param appType the uicc app type. |
| 9186 | * @return Application ID for specificied app type, or null if no uicc. |
| 9187 | */ |
| 9188 | @Override |
| 9189 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9190 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9191 | |
| 9192 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9193 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9194 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9195 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9196 | |
| 9197 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9198 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9199 | if (phone == null) { |
| 9200 | return null; |
| 9201 | } |
| 9202 | String aid = null; |
| 9203 | try { |
Tomasz Wasilczyk | 58e46ca | 2024-12-06 12:09:51 -0800 | [diff] [blame] | 9204 | UiccCardApplication app = UiccController.getInstance() |
| 9205 | .getUiccPort(phone.getPhoneId()).getApplicationByType(appType); |
| 9206 | if (app == null) return null; |
| 9207 | aid = app.getAid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9208 | } catch (Exception e) { |
Tomasz Wasilczyk | 58e46ca | 2024-12-06 12:09:51 -0800 | [diff] [blame] | 9209 | Log.e(LOG_TAG, "Not getting aid", e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9210 | } |
| 9211 | return aid; |
| 9212 | } finally { |
| 9213 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9214 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9215 | } |
| 9216 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9217 | /** |
| 9218 | * Return the Electronic Serial Number. |
| 9219 | * |
| 9220 | * @param subId the subscription ID that this request applies to. |
| 9221 | * @return ESN or null if error. |
| 9222 | */ |
| 9223 | @Override |
| 9224 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9225 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9226 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9227 | |
| 9228 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9229 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9230 | if (phone == null) { |
| 9231 | return null; |
| 9232 | } |
| 9233 | String esn = null; |
| 9234 | try { |
| 9235 | esn = phone.getEsn(); |
| 9236 | } catch (Exception e) { |
Tomasz Wasilczyk | 58e46ca | 2024-12-06 12:09:51 -0800 | [diff] [blame] | 9237 | Log.e(LOG_TAG, "Not getting ESN", e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9238 | } |
| 9239 | return esn; |
| 9240 | } finally { |
| 9241 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9242 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9243 | } |
| 9244 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9245 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9246 | * Return the Preferred Roaming List Version. |
| 9247 | * |
| 9248 | * @param subId the subscription ID that this request applies to. |
| 9249 | * @return PRLVersion or null if error. |
| 9250 | */ |
| 9251 | @Override |
| 9252 | public String getCdmaPrlVersion(int subId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 9253 | if (mFeatureFlags.cleanupCdma()) return null; |
| 9254 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9255 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9256 | |
| 9257 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9258 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9259 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9260 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9261 | |
| 9262 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9263 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9264 | if (phone == null) { |
| 9265 | return null; |
| 9266 | } |
| 9267 | String cdmaPrlVersion = null; |
| 9268 | try { |
| 9269 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9270 | } catch (Exception e) { |
| 9271 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9272 | } |
| 9273 | return cdmaPrlVersion; |
| 9274 | } finally { |
| 9275 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9276 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9280 | * Get snapshot of Telephony histograms |
| 9281 | * @return List of Telephony histograms |
| 9282 | * @hide |
| 9283 | */ |
| 9284 | @Override |
| 9285 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9287 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9288 | |
| 9289 | final long identity = Binder.clearCallingIdentity(); |
| 9290 | try { |
| 9291 | return RIL.getTelephonyRILTimingHistograms(); |
| 9292 | } finally { |
| 9293 | Binder.restoreCallingIdentity(identity); |
| 9294 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9295 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9296 | |
| 9297 | /** |
| 9298 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9299 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9300 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9301 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9302 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9303 | * @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] | 9304 | */ |
| 9305 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9306 | @TelephonyManager.SetCarrierRestrictionResult |
| 9307 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9308 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9309 | |
| 9310 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9311 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9312 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9313 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9314 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9315 | if (carrierRestrictionRules == null) { |
| 9316 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9317 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9319 | final long identity = Binder.clearCallingIdentity(); |
| 9320 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9321 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9322 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9323 | } finally { |
| 9324 | Binder.restoreCallingIdentity(identity); |
| 9325 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | /** |
| 9329 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9330 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9331 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9332 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9333 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9334 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9335 | */ |
| 9336 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9337 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9338 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9339 | |
| 9340 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9341 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9342 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9344 | |
| 9345 | final long identity = Binder.clearCallingIdentity(); |
| 9346 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9347 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9348 | if (response instanceof CarrierRestrictionRules) { |
| 9349 | return (CarrierRestrictionRules) response; |
| 9350 | } |
| 9351 | // Response is an Exception of some kind, |
| 9352 | // which is signalled to the user as a NULL retval |
| 9353 | return null; |
| 9354 | } catch (Exception e) { |
| 9355 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9356 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9357 | } finally { |
| 9358 | Binder.restoreCallingIdentity(identity); |
| 9359 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9360 | } |
| 9361 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9362 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9363 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9364 | * through the callback. |
| 9365 | * |
| 9366 | * @param callback The callback that will be used to send the result. |
| 9367 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9368 | * the caller is not allowlisted. |
| 9369 | */ |
| 9370 | @Override |
| 9371 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9372 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9373 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9374 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9375 | try { |
| 9376 | mApp.enforceCallingOrSelfPermission( |
| 9377 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9378 | functionName); |
| 9379 | } catch (SecurityException e) { |
| 9380 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9381 | functionName); |
| 9382 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9383 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9384 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9385 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9386 | throw new SecurityException("Not an authorized caller"); |
| 9387 | } |
| 9388 | final long identity = Binder.clearCallingIdentity(); |
| 9389 | try { |
| 9390 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9391 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9392 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9393 | } finally { |
| 9394 | Binder.restoreCallingIdentity(identity); |
| 9395 | } |
| 9396 | } |
| 9397 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9398 | @Override |
| 9399 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9400 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9401 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9402 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9403 | } |
| 9404 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9405 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9406 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9407 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9408 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9409 | } |
| 9410 | |
| 9411 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9412 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9413 | * @param subId the subscription ID that this action applies to. |
| 9414 | * @param enabled control enable or disable radio. |
| 9415 | * {@hide} |
| 9416 | */ |
| 9417 | @Override |
| 9418 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9419 | enforceModifyPermission(); |
| 9420 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9421 | |
| 9422 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9423 | if (phone == null) { |
| 9424 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9425 | return; |
| 9426 | } |
| 9427 | try { |
| 9428 | phone.carrierActionSetRadioEnabled(enabled); |
| 9429 | } catch (Exception e) { |
| 9430 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9431 | } finally { |
| 9432 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9433 | } |
| 9434 | } |
| 9435 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9436 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9437 | * Enable or disable Voice over NR (VoNR) |
| 9438 | * @param subId the subscription ID that this action applies to. |
| 9439 | * @param enabled enable or disable VoNR. |
| 9440 | * @return operation result. |
| 9441 | */ |
| 9442 | @Override |
| 9443 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9444 | enforceModifyPermission(); |
| 9445 | final Phone phone = getPhone(subId); |
| 9446 | |
| 9447 | final long identity = Binder.clearCallingIdentity(); |
| 9448 | if (phone == null) { |
| 9449 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9450 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9451 | } |
| 9452 | |
| 9453 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9454 | try { |
| 9455 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9456 | workSource); |
| 9457 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9458 | |
| 9459 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9460 | if (DBG) { |
| 9461 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9462 | } |
| 9463 | SubscriptionManager.setSubscriptionProperty( |
| 9464 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9465 | (enabled ? "1" : "0")); |
| 9466 | } |
| 9467 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9468 | return result; |
| 9469 | } finally { |
| 9470 | Binder.restoreCallingIdentity(identity); |
| 9471 | } |
| 9472 | } |
| 9473 | |
| 9474 | /** |
| 9475 | * Is voice over NR enabled |
| 9476 | * @return true if VoNR is enabled else false |
| 9477 | */ |
| 9478 | @Override |
| 9479 | public boolean isVoNrEnabled(int subId) { |
| 9480 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9481 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9482 | final long identity = Binder.clearCallingIdentity(); |
| 9483 | try { |
| 9484 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9485 | null, subId, workSource); |
| 9486 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9487 | return isEnabled; |
| 9488 | } finally { |
| 9489 | Binder.restoreCallingIdentity(identity); |
| 9490 | } |
| 9491 | } |
| 9492 | |
| 9493 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9494 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9495 | * network status based on which carrier apps could apply actions accordingly, |
| 9496 | * enable/disable default url handler for example. |
| 9497 | * |
| 9498 | * @param subId the subscription ID that this action applies to. |
| 9499 | * @param report control start/stop reporting the default network status. |
| 9500 | * {@hide} |
| 9501 | */ |
| 9502 | @Override |
| 9503 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9504 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9505 | |
| 9506 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9507 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9508 | "carrierActionReportDefaultNetworkStatus"); |
| 9509 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9510 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9511 | |
| 9512 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9513 | if (phone == null) { |
| 9514 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9515 | return; |
| 9516 | } |
| 9517 | try { |
| 9518 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9519 | } catch (Exception e) { |
| 9520 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9521 | } finally { |
| 9522 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9523 | } |
| 9524 | } |
| 9525 | |
| 9526 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9527 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9528 | * @param subId the subscription ID that this action applies to. |
| 9529 | * {@hide} |
| 9530 | */ |
| 9531 | @Override |
| 9532 | public void carrierActionResetAll(int subId) { |
| 9533 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9534 | |
| 9535 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9536 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9537 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9538 | final Phone phone = getPhone(subId); |
| 9539 | if (phone == null) { |
| 9540 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9541 | return; |
| 9542 | } |
| 9543 | try { |
| 9544 | phone.carrierActionResetAll(); |
| 9545 | } catch (Exception e) { |
| 9546 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9547 | } |
| 9548 | } |
| 9549 | |
| 9550 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9551 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9552 | * bug report is being generated. |
| 9553 | */ |
| 9554 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9555 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9556 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9557 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9558 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9559 | + Binder.getCallingPid() |
| 9560 | + ", uid=" + Binder.getCallingUid() |
| 9561 | + "without permission " |
| 9562 | + android.Manifest.permission.DUMP); |
| 9563 | return; |
| 9564 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9565 | try { |
| 9566 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9567 | } catch (Exception e) { |
| 9568 | writer.println("Failed to dump phone information: " + e); |
| 9569 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9570 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9571 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9572 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9573 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9574 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9575 | @NonNull String[] args) { |
| 9576 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9577 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9578 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9579 | } |
| 9580 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9581 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9582 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9583 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9584 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9585 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9586 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9587 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9588 | */ |
| 9589 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9590 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9591 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9592 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9593 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9594 | try { |
| 9595 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9596 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9597 | } catch (SecurityException se) { |
| 9598 | enforceModifyPermission(); |
| 9599 | } |
| 9600 | } else { |
| 9601 | enforceModifyPermission(); |
| 9602 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9603 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9604 | enforceTelephonyFeatureWithException(callingPackage, |
| 9605 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9606 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9607 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9608 | final long identity = Binder.clearCallingIdentity(); |
| 9609 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9610 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9611 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9612 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9613 | callingUid, callingPackage, null, null); |
| 9614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9615 | Phone phone = getPhone(subId); |
| 9616 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9617 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9618 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9619 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9620 | phone.getDataSettingsManager().setDataEnabled( |
| 9621 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9623 | } |
| 9624 | } finally { |
| 9625 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9626 | } |
| 9627 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9628 | |
| 9629 | /** |
| 9630 | * Get Client request stats |
| 9631 | * @return List of Client Request Stats |
| 9632 | * @hide |
| 9633 | */ |
| 9634 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9635 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9636 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9637 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9638 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9639 | return null; |
| 9640 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9641 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9643 | final long identity = Binder.clearCallingIdentity(); |
| 9644 | try { |
| 9645 | if (phone != null) { |
| 9646 | return phone.getClientRequestStats(); |
| 9647 | } |
| 9648 | |
| 9649 | return null; |
| 9650 | } finally { |
| 9651 | Binder.restoreCallingIdentity(identity); |
| 9652 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9653 | } |
| 9654 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9655 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9656 | PackageManager pm; |
| 9657 | if (mFeatureFlags.hsumPackageManager()) { |
| 9658 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9659 | .getPackageManager(); |
| 9660 | } else { |
| 9661 | pm = mApp.getPackageManager(); |
| 9662 | } |
| 9663 | |
| 9664 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9665 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9666 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9667 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9668 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9669 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9670 | // commands that plumb through the RIL as root, like so: |
| 9671 | // $ adb root |
| 9672 | // $ adb shell cmd phone ... |
| 9673 | packageName = "root"; |
| 9674 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9675 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9676 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9677 | |
| 9678 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9679 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9680 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9681 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9682 | * @param state State of SIM (power down, power up, pass through) |
| 9683 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9684 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9685 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9686 | * |
| 9687 | **/ |
| 9688 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9689 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9690 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9691 | |
| 9692 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9693 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9694 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9695 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9696 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9697 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9699 | final long identity = Binder.clearCallingIdentity(); |
| 9700 | try { |
| 9701 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9702 | phone.setSimPowerState(state, null, workSource); |
| 9703 | } |
| 9704 | } finally { |
| 9705 | Binder.restoreCallingIdentity(identity); |
| 9706 | } |
| 9707 | } |
| 9708 | |
| 9709 | /** |
| 9710 | * Set SIM card power state. |
| 9711 | * |
| 9712 | * @param slotIndex SIM slot id. |
| 9713 | * @param state State of SIM (power down, power up, pass through) |
| 9714 | * @param callback callback to trigger after success or failure |
| 9715 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9716 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9717 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9718 | * |
| 9719 | **/ |
| 9720 | @Override |
| 9721 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9722 | IIntegerConsumer callback) { |
| 9723 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9724 | |
| 9725 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9726 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9727 | "setSimPowerStateForSlotWithCallback"); |
| 9728 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9729 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9730 | |
| 9731 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9732 | |
| 9733 | final long identity = Binder.clearCallingIdentity(); |
| 9734 | try { |
| 9735 | if (phone != null) { |
| 9736 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9737 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9738 | } |
| 9739 | } finally { |
| 9740 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9741 | } |
| 9742 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9743 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9744 | private boolean isUssdApiAllowed(int subId) { |
| 9745 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9746 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9747 | if (configManager == null) { |
| 9748 | return false; |
| 9749 | } |
| 9750 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9751 | if (pb == null) { |
| 9752 | return false; |
| 9753 | } |
| 9754 | return pb.getBoolean( |
| 9755 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9756 | } |
| 9757 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9758 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9759 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9760 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9761 | * @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] | 9762 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9763 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9764 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9765 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9766 | |
| 9767 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9768 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9769 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9770 | final long identity = Binder.clearCallingIdentity(); |
| 9771 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9772 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9773 | } finally { |
| 9774 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9775 | } |
| 9776 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9777 | |
| 9778 | /** |
| 9779 | * Get the current signal strength information for the given subscription. |
| 9780 | * Because this information is not updated when the device is in a low power state |
| 9781 | * it should not be relied-upon to be current. |
| 9782 | * @param subId Subscription index |
| 9783 | * @return the most recent cached signal strength info from the modem |
| 9784 | */ |
| 9785 | @Override |
| 9786 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9787 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9788 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9789 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9790 | final long identity = Binder.clearCallingIdentity(); |
| 9791 | try { |
| 9792 | Phone p = getPhone(subId); |
| 9793 | if (p == null) { |
| 9794 | return null; |
| 9795 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9797 | return p.getSignalStrength(); |
| 9798 | } finally { |
| 9799 | Binder.restoreCallingIdentity(identity); |
| 9800 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9801 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9802 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9803 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9804 | * Get the current modem radio state for the given slot. |
| 9805 | * @param slotIndex slot index. |
| 9806 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9807 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9808 | * @return the current radio power state from the modem |
| 9809 | */ |
| 9810 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9811 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9812 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9813 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9814 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9815 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9816 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9817 | } |
| 9818 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9819 | enforceTelephonyFeatureWithException(callingPackage, |
| 9820 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9821 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9822 | final long identity = Binder.clearCallingIdentity(); |
| 9823 | try { |
| 9824 | return phone.getRadioPowerState(); |
| 9825 | } finally { |
| 9826 | Binder.restoreCallingIdentity(identity); |
| 9827 | } |
| 9828 | } |
| 9829 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9830 | } |
| 9831 | |
| 9832 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9833 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9834 | * |
| 9835 | * <p>Requires one of the following permissions: |
| 9836 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9837 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9838 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9839 | * privileges. |
| 9840 | * |
| 9841 | * @param subId subscription id |
| 9842 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9843 | * {@code false}. |
| 9844 | */ |
| 9845 | @Override |
| 9846 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9847 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9848 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9849 | try { |
| 9850 | mApp.enforceCallingOrSelfPermission( |
| 9851 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9852 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9853 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9854 | mApp.enforceCallingOrSelfPermission( |
| 9855 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9856 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9857 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9858 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9859 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9860 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9861 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9862 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9863 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9864 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9865 | boolean isEnabled = false; |
| 9866 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9867 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9868 | Phone phone = getPhone(subId); |
| 9869 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9870 | } finally { |
| 9871 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9872 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9873 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9874 | } |
| 9875 | |
| 9876 | |
| 9877 | /** |
| 9878 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9879 | * |
| 9880 | * <p> Requires permission: |
| 9881 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9882 | * privileges. |
| 9883 | * |
| 9884 | * @param subId subscription id |
| 9885 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9886 | */ |
| 9887 | @Override |
| 9888 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9889 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9890 | mApp, subId, "setDataRoamingEnabled"); |
| 9891 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9892 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9893 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9894 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9895 | final long identity = Binder.clearCallingIdentity(); |
| 9896 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9897 | Phone phone = getPhone(subId); |
| 9898 | if (phone != null) { |
| 9899 | phone.setDataRoamingEnabled(isEnabled); |
| 9900 | } |
| 9901 | } finally { |
| 9902 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9903 | } |
| 9904 | } |
| 9905 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9906 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9907 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9908 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9909 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9910 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9911 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9912 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9913 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9914 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9915 | boolean isAllowed = true; |
| 9916 | final long identity = Binder.clearCallingIdentity(); |
| 9917 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9918 | Phone phone = getPhone(subId); |
| 9919 | if (phone != null) { |
| 9920 | isAllowed = phone.isCspPlmnEnabled(); |
| 9921 | } |
| 9922 | } finally { |
| 9923 | Binder.restoreCallingIdentity(identity); |
| 9924 | } |
| 9925 | return isAllowed; |
| 9926 | } |
| 9927 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9928 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9929 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9930 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9931 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9932 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9933 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9934 | if (phone == null) { |
| 9935 | return false; |
| 9936 | } |
| 9937 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9938 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9939 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9940 | } |
| 9941 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9942 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9943 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9944 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9945 | mApp.getSystemService(AppOpsManager.class) |
| 9946 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9947 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9948 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9949 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9950 | try { |
| 9951 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9952 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9953 | } catch (SecurityException e) { |
| 9954 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9955 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9956 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9957 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9958 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9959 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9960 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9961 | |
| 9962 | enforceTelephonyFeatureWithException(callingPackage, |
| 9963 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9964 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9965 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9966 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9967 | Binder.getCallingUid())) { |
| 9968 | isIccIdAccessRestricted = true; |
| 9969 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9970 | final long identity = Binder.clearCallingIdentity(); |
| 9971 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9972 | UiccController uiccController = UiccController.getInstance(); |
| 9973 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9974 | if (hasReadPermission) { |
| 9975 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9976 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9977 | |
| 9978 | // Remove private info if the caller doesn't have access |
| 9979 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9980 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9981 | //setting the value after compatibility check |
| 9982 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9983 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9984 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9985 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9986 | if (card == null) { |
| 9987 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9988 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9989 | continue; |
| 9990 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9991 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9992 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9993 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9994 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9995 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9996 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9997 | for (UiccPortInfo portInfo : portInfos) { |
| 9998 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9999 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 10000 | if (port == null) { |
| 10001 | // assume no access if port is null |
| 10002 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 10003 | continue; |
| 10004 | } |
| 10005 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10006 | uiccPortInfos.add(portInfo); |
| 10007 | } else { |
| 10008 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 10009 | } |
| 10010 | } |
| 10011 | filteredInfos.add(new UiccCardInfo( |
| 10012 | cardInfo.isEuicc(), |
| 10013 | cardInfo.getCardId(), |
| 10014 | null, |
| 10015 | cardInfo.getPhysicalSlotIndex(), |
| 10016 | cardInfo.isRemovable(), |
| 10017 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10018 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10019 | } |
| 10020 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 10021 | } finally { |
| 10022 | Binder.restoreCallingIdentity(identity); |
| 10023 | } |
| 10024 | } |
| 10025 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10026 | /** |
| 10027 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 10028 | * generally private and require carrier privileges to view. |
| 10029 | * |
| 10030 | * @hide |
| 10031 | */ |
| 10032 | @NonNull |
| 10033 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 10034 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 10035 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 10036 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 10037 | } |
| 10038 | return new UiccCardInfo( |
| 10039 | cardInfo.isEuicc(), |
| 10040 | cardInfo.getCardId(), |
| 10041 | null, |
| 10042 | cardInfo.getPhysicalSlotIndex(), |
| 10043 | cardInfo.isRemovable(), |
| 10044 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10045 | portinfo |
| 10046 | ); |
| 10047 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10048 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10049 | /** |
| 10050 | * @hide |
| 10051 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10052 | * These values are generally private and require carrier privileges to view. |
| 10053 | */ |
| 10054 | @NonNull |
| 10055 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10056 | return new UiccPortInfo( |
| 10057 | UiccPortInfo.ICCID_REDACTED, |
| 10058 | portInfo.getPortIndex(), |
| 10059 | portInfo.getLogicalSlotIndex(), |
| 10060 | portInfo.isActive() |
| 10061 | ); |
| 10062 | } |
| 10063 | @Override |
| 10064 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10065 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10066 | mApp.getSystemService(AppOpsManager.class) |
| 10067 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10068 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10069 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10070 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10071 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10072 | // we are reading iccId which is PII data. |
| 10073 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10074 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10075 | enforceTelephonyFeatureWithException(callingPackage, |
| 10076 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10077 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10078 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10079 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10080 | Binder.getCallingUid())) { |
| 10081 | isLogicalSlotAccessRestricted = true; |
| 10082 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10083 | final long identity = Binder.clearCallingIdentity(); |
| 10084 | try { |
| 10085 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10086 | if (slots == null || slots.length == 0) { |
| 10087 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10088 | return null; |
| 10089 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10090 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10091 | for (int i = 0; i < slots.length; i++) { |
| 10092 | UiccSlot slot = slots[i]; |
| 10093 | if (slot == null) { |
| 10094 | continue; |
| 10095 | } |
| 10096 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10097 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10098 | UiccCard card = slot.getUiccCard(); |
| 10099 | if (card != null) { |
| 10100 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10101 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10102 | cardId = slot.getEid(); |
| 10103 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10104 | // If cardId is null, use iccId of default port as cardId. |
| 10105 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10107 | } |
| 10108 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10109 | if (cardId != null) { |
| 10110 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10111 | // if cardId is an EID, it's all digits so this is fine |
| 10112 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10113 | } |
| 10114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10115 | int cardState = 0; |
| 10116 | switch (slot.getCardState()) { |
| 10117 | case CARDSTATE_ABSENT: |
| 10118 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10119 | break; |
| 10120 | case CARDSTATE_PRESENT: |
| 10121 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10122 | break; |
| 10123 | case CARDSTATE_ERROR: |
| 10124 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10125 | break; |
| 10126 | case CARDSTATE_RESTRICTED: |
| 10127 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10128 | break; |
| 10129 | default: |
| 10130 | break; |
| 10131 | |
| 10132 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10133 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10134 | int[] portIndexes = slot.getPortList(); |
| 10135 | for (int portIdx : portIndexes) { |
| 10136 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10137 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10138 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10139 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10141 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10142 | slot.isEuicc(), |
| 10143 | cardId, |
| 10144 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10145 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10146 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10147 | //setting the value after compatibility check |
| 10148 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10149 | } |
| 10150 | return infos; |
| 10151 | } finally { |
| 10152 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10153 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10154 | } |
| 10155 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10156 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10157 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10158 | boolean hasReadPermission) { |
| 10159 | String iccId = slot.getIccId(portIndex); |
| 10160 | if (hasReadPermission) { // if has read permission |
| 10161 | return iccId; |
| 10162 | } else { |
| 10163 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10164 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10165 | // if no read permission, checking carrier privilege access |
| 10166 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10167 | return iccId; |
| 10168 | } |
| 10169 | } |
| 10170 | } |
| 10171 | // No read permission or carrier privilege access. |
| 10172 | return UiccPortInfo.ICCID_REDACTED; |
| 10173 | } |
| 10174 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10175 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10176 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10177 | public boolean switchSlots(int[] physicalSlots) { |
| 10178 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10179 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10180 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10181 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10183 | final long identity = Binder.clearCallingIdentity(); |
| 10184 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10185 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10186 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10187 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10188 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10189 | physicalSlots[i], i)); |
| 10190 | } |
| 10191 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10192 | } finally { |
| 10193 | Binder.restoreCallingIdentity(identity); |
| 10194 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10195 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10196 | |
| 10197 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10198 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10199 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10200 | enforceModifyPermission(); |
| 10201 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10202 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10203 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10204 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10205 | final long identity = Binder.clearCallingIdentity(); |
| 10206 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10207 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10208 | } finally { |
| 10209 | Binder.restoreCallingIdentity(identity); |
| 10210 | } |
| 10211 | } |
| 10212 | |
| 10213 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10214 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10215 | enforceTelephonyFeatureWithException(callingPackage, |
| 10216 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10217 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10218 | final long identity = Binder.clearCallingIdentity(); |
| 10219 | try { |
| 10220 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10221 | } finally { |
| 10222 | Binder.restoreCallingIdentity(identity); |
| 10223 | } |
| 10224 | } |
| 10225 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10226 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10227 | * A test API to reload the UICC profile. |
| 10228 | * |
| 10229 | * <p>Requires that the calling app has permission |
| 10230 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10231 | * @hide |
| 10232 | */ |
| 10233 | @Override |
| 10234 | public void refreshUiccProfile(int subId) { |
| 10235 | enforceModifyPermission(); |
| 10236 | |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | Phone phone = getPhone(subId); |
| 10240 | if (phone == null) { |
| 10241 | return; |
| 10242 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10243 | UiccPort uiccPort = phone.getUiccPort(); |
| 10244 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10245 | return; |
| 10246 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10247 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10248 | if (uiccProfile == null) { |
| 10249 | return; |
| 10250 | } |
| 10251 | uiccProfile.refresh(); |
| 10252 | } finally { |
| 10253 | Binder.restoreCallingIdentity(identity); |
| 10254 | } |
| 10255 | } |
| 10256 | |
| 10257 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10258 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10259 | */ |
| 10260 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10261 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10262 | } |
| 10263 | |
| 10264 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10265 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10266 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10267 | */ |
| 10268 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10269 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10270 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10271 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10272 | return list.get(phoneId); |
| 10273 | } |
| 10274 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10275 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10276 | |
| 10277 | @Override |
| 10278 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10279 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10281 | |
| 10282 | final long identity = Binder.clearCallingIdentity(); |
| 10283 | try { |
| 10284 | final Phone phone = getPhone(subId); |
| 10285 | if (phone == null) { |
| 10286 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10287 | return; |
| 10288 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10289 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10290 | if (cpt != null) { |
| 10291 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10292 | } |
| 10293 | // 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] | 10294 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10295 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10296 | if (carrierPrivilegeRules == null) { |
| 10297 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10298 | } else { |
| 10299 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10300 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10301 | } finally { |
| 10302 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10303 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10304 | } |
| 10305 | |
| 10306 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10307 | public void setCarrierServicePackageOverride( |
| 10308 | int subId, String carrierServicePackage, String callingPackage) { |
| 10309 | TelephonyPermissions.enforceShellOnly( |
| 10310 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10311 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10312 | final long identity = Binder.clearCallingIdentity(); |
| 10313 | try { |
| 10314 | final Phone phone = getPhone(subId); |
| 10315 | if (phone == null || phone.getSubId() != subId) { |
| 10316 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10317 | throw new IllegalArgumentException("No phone for subid"); |
| 10318 | } |
| 10319 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10320 | if (cpt == null) { |
| 10321 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10322 | throw new IllegalStateException("No CPT for phone"); |
| 10323 | } |
| 10324 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10325 | } finally { |
| 10326 | Binder.restoreCallingIdentity(identity); |
| 10327 | } |
| 10328 | } |
| 10329 | |
| 10330 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10331 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10332 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10333 | |
| 10334 | final long identity = Binder.clearCallingIdentity(); |
| 10335 | try { |
| 10336 | final Phone phone = getPhone(subId); |
| 10337 | if (phone == null) { |
| 10338 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10339 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10340 | } |
| 10341 | return phone.getCarrierIdListVersion(); |
| 10342 | } finally { |
| 10343 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10344 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10345 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10346 | |
| 10347 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10348 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10349 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10350 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10351 | mApp, subId, callingPackage, callingFeatureId, |
| 10352 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10353 | return -1; |
| 10354 | } |
| 10355 | |
| 10356 | final long identity = Binder.clearCallingIdentity(); |
| 10357 | try { |
| 10358 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10359 | } finally { |
| 10360 | Binder.restoreCallingIdentity(identity); |
| 10361 | } |
| 10362 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10363 | |
| 10364 | @Override |
| 10365 | public int getCdmaRoamingMode(int subId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 10366 | if (mFeatureFlags.cleanupCdma()) return TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 10367 | |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10368 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10369 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10370 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10371 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10372 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10373 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10374 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10375 | final long identity = Binder.clearCallingIdentity(); |
| 10376 | try { |
| 10377 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10378 | } finally { |
| 10379 | Binder.restoreCallingIdentity(identity); |
| 10380 | } |
| 10381 | } |
| 10382 | |
| 10383 | @Override |
| 10384 | public boolean setCdmaRoamingMode(int subId, int mode) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 10385 | if (mFeatureFlags.cleanupCdma()) return false; |
| 10386 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10388 | mApp, subId, "setCdmaRoamingMode"); |
| 10389 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10390 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10391 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10392 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10393 | final long identity = Binder.clearCallingIdentity(); |
| 10394 | try { |
| 10395 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10396 | } finally { |
| 10397 | Binder.restoreCallingIdentity(identity); |
| 10398 | } |
| 10399 | } |
| 10400 | |
| 10401 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10402 | public int getCdmaSubscriptionMode(int subId) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 10403 | if (mFeatureFlags.cleanupCdma()) return TelephonyManager.CDMA_SUBSCRIPTION_UNKNOWN; |
| 10404 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10405 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10406 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10407 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10408 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10409 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10410 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10411 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10412 | final long identity = Binder.clearCallingIdentity(); |
| 10413 | try { |
| 10414 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10415 | } finally { |
| 10416 | Binder.restoreCallingIdentity(identity); |
| 10417 | } |
| 10418 | } |
| 10419 | |
| 10420 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10421 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
Tomasz Wasilczyk | f5858b9 | 2024-12-05 15:07:01 -0800 | [diff] [blame] | 10422 | if (mFeatureFlags.cleanupCdma()) return false; |
| 10423 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10425 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10426 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10427 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10428 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10429 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10430 | final long identity = Binder.clearCallingIdentity(); |
| 10431 | try { |
| 10432 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10433 | } finally { |
| 10434 | Binder.restoreCallingIdentity(identity); |
| 10435 | } |
| 10436 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10437 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10438 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10439 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10440 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10442 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10443 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10444 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10445 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10446 | |
| 10447 | enforceTelephonyFeatureWithException(callingPackage, |
| 10448 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10449 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10450 | final long identity = Binder.clearCallingIdentity(); |
| 10451 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10452 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10453 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10454 | if (phone.getEmergencyNumberTracker() != null |
| 10455 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10456 | emergencyNumberListInternal.put( |
| 10457 | phone.getSubId(), |
| 10458 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10459 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10460 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10461 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10462 | } finally { |
| 10463 | Binder.restoreCallingIdentity(identity); |
| 10464 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10465 | } |
| 10466 | |
| 10467 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10468 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10469 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10470 | if (!exactMatch) { |
| 10471 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10472 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10473 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10474 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10475 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10476 | if (!mApp.getResources().getBoolean( |
| 10477 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10478 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10479 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10480 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10481 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10482 | final long identity = Binder.clearCallingIdentity(); |
| 10483 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10484 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10485 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10486 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10487 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10488 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10489 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10490 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10491 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10492 | } |
| 10493 | return false; |
| 10494 | } finally { |
| 10495 | Binder.restoreCallingIdentity(identity); |
| 10496 | } |
| 10497 | } |
| 10498 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10499 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10500 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10501 | */ |
| 10502 | @Override |
| 10503 | public void startEmergencyCallbackMode() { |
| 10504 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10505 | "startEmergencyCallbackMode"); |
| 10506 | enforceModifyPermission(); |
| 10507 | final long identity = Binder.clearCallingIdentity(); |
| 10508 | try { |
| 10509 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10510 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10511 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10512 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10513 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10514 | gsmCdmaPhone.obtainMessage( |
| 10515 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10516 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10517 | } |
| 10518 | } |
| 10519 | } finally { |
| 10520 | Binder.restoreCallingIdentity(identity); |
| 10521 | } |
| 10522 | } |
| 10523 | |
| 10524 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10525 | * Update emergency number list for test mode. |
| 10526 | */ |
| 10527 | @Override |
| 10528 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10529 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10530 | "updateEmergencyNumberListTestMode"); |
| 10531 | |
| 10532 | final long identity = Binder.clearCallingIdentity(); |
| 10533 | try { |
| 10534 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10535 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10536 | if (tracker != null) { |
| 10537 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10538 | } |
| 10539 | } |
| 10540 | } finally { |
| 10541 | Binder.restoreCallingIdentity(identity); |
| 10542 | } |
| 10543 | } |
| 10544 | |
| 10545 | /** |
| 10546 | * Get the full emergency number list for test mode. |
| 10547 | */ |
| 10548 | @Override |
| 10549 | public List<String> getEmergencyNumberListTestMode() { |
| 10550 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10551 | "getEmergencyNumberListTestMode"); |
| 10552 | |
| 10553 | final long identity = Binder.clearCallingIdentity(); |
| 10554 | try { |
| 10555 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10556 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10557 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10558 | if (tracker != null) { |
| 10559 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10560 | emergencyNumbers.add(num.getNumber()); |
| 10561 | } |
| 10562 | } |
| 10563 | } |
| 10564 | return new ArrayList<>(emergencyNumbers); |
| 10565 | } finally { |
| 10566 | Binder.restoreCallingIdentity(identity); |
| 10567 | } |
| 10568 | } |
| 10569 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10570 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10571 | public int getEmergencyNumberDbVersion(int subId) { |
| 10572 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10573 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10574 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10575 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10576 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10577 | final long identity = Binder.clearCallingIdentity(); |
| 10578 | try { |
| 10579 | final Phone phone = getPhone(subId); |
| 10580 | if (phone == null) { |
| 10581 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10582 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10583 | } |
| 10584 | return phone.getEmergencyNumberDbVersion(); |
| 10585 | } finally { |
| 10586 | Binder.restoreCallingIdentity(identity); |
| 10587 | } |
| 10588 | } |
| 10589 | |
| 10590 | @Override |
| 10591 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10592 | enforceModifyPermission(); |
| 10593 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10594 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10595 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10596 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10597 | final long identity = Binder.clearCallingIdentity(); |
| 10598 | try { |
| 10599 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10600 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10601 | if (tracker != null) { |
| 10602 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10603 | } |
| 10604 | } |
| 10605 | } finally { |
| 10606 | Binder.restoreCallingIdentity(identity); |
| 10607 | } |
| 10608 | } |
| 10609 | |
| 10610 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10611 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10612 | enforceActiveEmergencySessionPermission(); |
| 10613 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10614 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10615 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10616 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10617 | final long identity = Binder.clearCallingIdentity(); |
| 10618 | try { |
| 10619 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10620 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10621 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10622 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10623 | } |
| 10624 | } |
| 10625 | } finally { |
| 10626 | Binder.restoreCallingIdentity(identity); |
| 10627 | } |
| 10628 | } |
| 10629 | |
| 10630 | @Override |
| 10631 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10632 | enforceActiveEmergencySessionPermission(); |
| 10633 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10634 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10635 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10636 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10637 | final long identity = Binder.clearCallingIdentity(); |
| 10638 | try { |
| 10639 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10640 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10641 | if (tracker != null) { |
| 10642 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10643 | } |
| 10644 | } |
| 10645 | } finally { |
| 10646 | Binder.restoreCallingIdentity(identity); |
| 10647 | } |
| 10648 | } |
| 10649 | |
| 10650 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10651 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10652 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10653 | Phone phone = getPhone(subId); |
| 10654 | if (phone == null) { |
| 10655 | return null; |
| 10656 | } |
| 10657 | final long identity = Binder.clearCallingIdentity(); |
| 10658 | try { |
| 10659 | UiccProfile profile = UiccController.getInstance() |
| 10660 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10661 | if (profile != null) { |
| 10662 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10663 | } |
| 10664 | } finally { |
| 10665 | Binder.restoreCallingIdentity(identity); |
| 10666 | } |
| 10667 | return null; |
| 10668 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10669 | |
| 10670 | /** |
| 10671 | * Enable or disable a modem stack. |
| 10672 | */ |
| 10673 | @Override |
| 10674 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10675 | enforceModifyPermission(); |
| 10676 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10677 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10678 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10679 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10680 | final long identity = Binder.clearCallingIdentity(); |
| 10681 | try { |
| 10682 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10683 | if (phone == null) { |
| 10684 | return false; |
| 10685 | } else { |
| 10686 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10687 | } |
| 10688 | } finally { |
| 10689 | Binder.restoreCallingIdentity(identity); |
| 10690 | } |
| 10691 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10692 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10693 | /** |
| 10694 | * Whether a modem stack is enabled or not. |
| 10695 | */ |
| 10696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10697 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10698 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10699 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10700 | if (phone == null) return false; |
| 10701 | |
| 10702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10703 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10704 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10705 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10706 | } |
| 10707 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10708 | enforceTelephonyFeatureWithException(callingPackage, |
| 10709 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10710 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10711 | final long identity = Binder.clearCallingIdentity(); |
| 10712 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10713 | try { |
| 10714 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10715 | } catch (NoSuchElementException ex) { |
| 10716 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10717 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10718 | } finally { |
| 10719 | Binder.restoreCallingIdentity(identity); |
| 10720 | } |
| 10721 | } |
| 10722 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10723 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10724 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10725 | enforceModifyPermission(); |
| 10726 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10727 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10728 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10729 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10730 | final long identity = Binder.clearCallingIdentity(); |
| 10731 | try { |
| 10732 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10733 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10734 | .commit(); |
| 10735 | } finally { |
| 10736 | Binder.restoreCallingIdentity(identity); |
| 10737 | } |
| 10738 | } |
| 10739 | |
| 10740 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10741 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10742 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10744 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10745 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10746 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10747 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10748 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10749 | enforceTelephonyFeatureWithException(callingPackage, |
| 10750 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10751 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10752 | final long identity = Binder.clearCallingIdentity(); |
| 10753 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10754 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10755 | } finally { |
| 10756 | Binder.restoreCallingIdentity(identity); |
| 10757 | } |
| 10758 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10759 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10760 | @TelephonyManager.IsMultiSimSupportedResult |
| 10761 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10762 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10763 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10764 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10765 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10766 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10767 | } |
| 10768 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10769 | // supported by the modem, indicate that it is restricted. |
| 10770 | PhoneCapability staticCapability = |
| 10771 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10772 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10773 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10774 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10775 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10776 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10777 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10778 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10779 | } |
| 10780 | // Check if support of multiple SIMs is restricted by carrier |
| 10781 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10782 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10783 | } |
| 10784 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10785 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10786 | } |
| 10787 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10788 | /** |
| 10789 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10790 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10791 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10792 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10793 | * @param numOfSims number of active sims we want to switch to |
| 10794 | */ |
| 10795 | @Override |
| 10796 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10797 | if (numOfSims == 1) { |
| 10798 | enforceModifyPermission(); |
| 10799 | } else { |
| 10800 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10801 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10802 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10803 | |
| 10804 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10805 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10806 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10807 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10808 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10809 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10810 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10811 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10812 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10813 | return; |
| 10814 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10815 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10816 | } finally { |
| 10817 | Binder.restoreCallingIdentity(identity); |
| 10818 | } |
| 10819 | } |
| 10820 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10821 | @Override |
| 10822 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10823 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10824 | |
| 10825 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10826 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10827 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10828 | Phone phone = getPhone(subId); |
| 10829 | if (phone == null) { |
| 10830 | return false; |
| 10831 | } |
| 10832 | final long identity = Binder.clearCallingIdentity(); |
| 10833 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10834 | UiccPort uiccPort = phone.getUiccPort(); |
| 10835 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10836 | return false; |
| 10837 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10838 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10839 | if (uiccProfile == null) { |
| 10840 | return false; |
| 10841 | } |
| 10842 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10843 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10844 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10845 | } |
| 10846 | return false; |
| 10847 | } finally { |
| 10848 | Binder.restoreCallingIdentity(identity); |
| 10849 | } |
| 10850 | } |
| 10851 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10852 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10853 | * Get whether making changes to modem configurations will trigger reboot. |
| 10854 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10855 | */ |
| 10856 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10857 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10858 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10859 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10860 | mApp, subId, callingPackage, callingFeatureId, |
| 10861 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10862 | return false; |
| 10863 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10864 | |
| 10865 | enforceTelephonyFeatureWithException(callingPackage, |
| 10866 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10867 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10868 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10869 | final long identity = Binder.clearCallingIdentity(); |
| 10870 | try { |
| 10871 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10872 | } finally { |
| 10873 | Binder.restoreCallingIdentity(identity); |
| 10874 | } |
| 10875 | } |
| 10876 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10877 | private void updateModemStateMetrics() { |
| 10878 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10879 | // TODO: check the state for each modem if the api is ready. |
| 10880 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10881 | } |
| 10882 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10883 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10884 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10885 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10886 | // Verify that the callingPackage belongs to the calling UID |
| 10887 | mApp.getSystemService(AppOpsManager.class) |
| 10888 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10889 | |
| 10890 | enforceTelephonyFeatureWithException(callingPackage, |
| 10891 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10892 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10893 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10894 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10895 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10896 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10897 | if (slotInfos != null) { |
| 10898 | for (int i = 0; i < slotInfos.length; i++) { |
| 10899 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10900 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10901 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10902 | portInfo.getLogicalSlotIndex())); |
| 10903 | } |
| 10904 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10905 | } |
| 10906 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10907 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10908 | } finally { |
| 10909 | Binder.restoreCallingIdentity(identity); |
| 10910 | } |
| 10911 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10912 | |
| 10913 | /** |
| 10914 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10915 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10916 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10917 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10918 | @Override |
| 10919 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10920 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10921 | } |
| 10922 | |
| 10923 | /** |
| 10924 | * Get the HAL Version of a specific service |
| 10925 | */ |
| 10926 | @Override |
| 10927 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10928 | Phone phone = getDefaultPhone(); |
| 10929 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10930 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10931 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10932 | return hv.major * 100 + hv.minor; |
| 10933 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10934 | |
| 10935 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10936 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10937 | * |
| 10938 | * @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] | 10939 | */ |
| 10940 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10941 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10942 | if (mFeatureFlags.hsumPackageManager()) { |
| 10943 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10944 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10945 | if (pm == null) return null; |
| 10946 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10947 | return (callingUids == null) ? null : callingUids[0]; |
| 10948 | } |
| 10949 | if (mPackageManager == null) return null; |
| 10950 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10951 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10952 | } |
| 10953 | |
| 10954 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10955 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10956 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10957 | * actually always the caller. |
| 10958 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10959 | */ |
| 10960 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10961 | PackageManager pm; |
| 10962 | if (mFeatureFlags.hsumPackageManager()) { |
| 10963 | pm = mApp.getBaseContext().createContextAsUser( |
| 10964 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10965 | } else { |
| 10966 | pm = mApp.getPackageManager(); |
| 10967 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10968 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10969 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10970 | return getCurrentPackageName(); |
| 10971 | } |
| 10972 | |
| 10973 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10974 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10975 | * corresponding network requests on a subId. |
| 10976 | * |
| 10977 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10978 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10979 | * 2) APN is un-metered for this subscription, or |
| 10980 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10981 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10982 | * |
| 10983 | * @return whether data is allowed for a apn type. |
| 10984 | * |
| 10985 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10986 | */ |
| 10987 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10988 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10989 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10990 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10991 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10992 | enforceTelephonyFeatureWithException(callingPackage, |
| 10993 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10994 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10995 | // Now that all security checks passes, perform the operation as ourselves. |
| 10996 | final long identity = Binder.clearCallingIdentity(); |
| 10997 | try { |
| 10998 | Phone phone = getPhone(subId); |
| 10999 | if (phone == null) return false; |
| 11000 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 11001 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 11002 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 11003 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 11004 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 11005 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11006 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 11007 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 11008 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 11009 | } finally { |
| 11010 | Binder.restoreCallingIdentity(identity); |
| 11011 | } |
| 11012 | } |
| 11013 | |
| 11014 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 11015 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 11016 | enforceReadPrivilegedPermission("isApnMetered"); |
| 11017 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11019 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 11020 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 11021 | // Now that all security checks passes, perform the operation as ourselves. |
| 11022 | final long identity = Binder.clearCallingIdentity(); |
| 11023 | try { |
| 11024 | Phone phone = getPhone(subId); |
| 11025 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 11026 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 11027 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 11028 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 11029 | } finally { |
| 11030 | Binder.restoreCallingIdentity(identity); |
| 11031 | } |
| 11032 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11033 | |
| 11034 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 11035 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 11036 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 11037 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11038 | |
| 11039 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11040 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 11041 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 11042 | long token = Binder.clearCallingIdentity(); |
| 11043 | try { |
| 11044 | Phone phone = getPhone(subscriptionId); |
| 11045 | if (phone == null) { |
| 11046 | try { |
| 11047 | if (resultCallback != null) { |
| 11048 | resultCallback.accept(false); |
| 11049 | } |
| 11050 | } catch (RemoteException e) { |
| 11051 | // ignore |
| 11052 | } |
| 11053 | return; |
| 11054 | } |
| 11055 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11056 | Pair.create(specifiers, (x) -> { |
| 11057 | try { |
| 11058 | if (resultCallback != null) { |
| 11059 | resultCallback.accept(x); |
| 11060 | } |
| 11061 | } catch (RemoteException e) { |
| 11062 | // ignore |
| 11063 | } |
| 11064 | }); |
| 11065 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11066 | } finally { |
| 11067 | Binder.restoreCallingIdentity(token); |
| 11068 | } |
| 11069 | } |
| 11070 | |
| 11071 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11072 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11073 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11074 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11075 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11076 | |
| 11077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11078 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11079 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11080 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11081 | final long identity = Binder.clearCallingIdentity(); |
| 11082 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11083 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11084 | if (result instanceof IllegalStateException) { |
| 11085 | throw (IllegalStateException) result; |
| 11086 | } |
| 11087 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11088 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11089 | return specifiers; |
| 11090 | } finally { |
| 11091 | Binder.restoreCallingIdentity(identity); |
| 11092 | } |
| 11093 | } |
| 11094 | |
| 11095 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11096 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11097 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11098 | |
| 11099 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11100 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11101 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11102 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11103 | } |
| 11104 | |
| 11105 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11106 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11107 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11108 | if (callingPackage == null) { |
| 11109 | callingPackage = getCurrentPackageName(); |
| 11110 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11111 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11112 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11113 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11114 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11115 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11116 | } |
| 11117 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11118 | Intent intent = new Intent(); |
| 11119 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11120 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11121 | // Bring up choose default SMS subscription dialog right now |
| 11122 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11123 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11124 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11125 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11126 | |
| 11127 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11128 | public void showSwitchToManagedProfileDialog() { |
| 11129 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11130 | try { |
| 11131 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11132 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11133 | // for work telephony. |
| 11134 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11135 | intent.setData(Uri.parse("smsto:")); |
| 11136 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11137 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11138 | } catch (ActivityNotFoundException e) { |
| 11139 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11140 | Intent intent = new Intent(); |
| 11141 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11142 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11143 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11144 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11145 | } |
| 11146 | |
| 11147 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11148 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11149 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11150 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11151 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11152 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11153 | final long identity = Binder.clearCallingIdentity(); |
| 11154 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11155 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11156 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11157 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11158 | return carrierUAProfUrl; |
| 11159 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11160 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11161 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11162 | } finally { |
| 11163 | Binder.restoreCallingIdentity(identity); |
| 11164 | } |
| 11165 | } |
| 11166 | |
| 11167 | @Override |
| 11168 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11169 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11170 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11171 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11172 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11173 | final long identity = Binder.clearCallingIdentity(); |
| 11174 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11175 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11176 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11177 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11178 | return carrierUserAgent; |
| 11179 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11180 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11181 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11182 | } finally { |
| 11183 | Binder.restoreCallingIdentity(identity); |
| 11184 | } |
| 11185 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11186 | |
| 11187 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11188 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11189 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11190 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11191 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11192 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11193 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11194 | final long identity = Binder.clearCallingIdentity(); |
| 11195 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11196 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11197 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11198 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11199 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11200 | } finally { |
| 11201 | Binder.restoreCallingIdentity(identity); |
| 11202 | } |
| 11203 | } |
| 11204 | |
| 11205 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11206 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11207 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11208 | enforceModifyPermission(); |
| 11209 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11210 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11211 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11212 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11213 | final long identity = Binder.clearCallingIdentity(); |
| 11214 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11215 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11216 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11217 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11218 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11219 | } finally { |
| 11220 | Binder.restoreCallingIdentity(identity); |
| 11221 | } |
| 11222 | } |
| 11223 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11224 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11225 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11226 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11227 | * otherwise. |
| 11228 | */ |
| 11229 | @Override |
| 11230 | public void setCepEnabled(boolean isCepEnabled) { |
| 11231 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11232 | |
| 11233 | final long identity = Binder.clearCallingIdentity(); |
| 11234 | try { |
| 11235 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11236 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11237 | Phone defaultPhone = phone.getImsPhone(); |
| 11238 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11239 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11240 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11241 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11242 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11243 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11244 | + imsPhone.getMsisdn()); |
| 11245 | } |
| 11246 | } |
| 11247 | } finally { |
| 11248 | Binder.restoreCallingIdentity(identity); |
| 11249 | } |
| 11250 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11251 | |
| 11252 | /** |
| 11253 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11254 | * |
| 11255 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11256 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11257 | * before being read. |
| 11258 | */ |
| 11259 | @Override |
| 11260 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11261 | isCompressed) { |
| 11262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11263 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11264 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11265 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11266 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11267 | |
| 11268 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11269 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11270 | Binder.getCallingUserHandle())) { |
| 11271 | if (!isImsAvailableOnDevice()) { |
| 11272 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11273 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11274 | throw new IllegalStateException("IMS not available on device."); |
| 11275 | } |
| 11276 | } else { |
| 11277 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11278 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11279 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11280 | } |
| 11281 | |
| 11282 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11283 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11284 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11285 | } finally { |
| 11286 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11287 | } |
| 11288 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11289 | |
| 11290 | @Override |
| 11291 | public boolean isIccLockEnabled(int subId) { |
| 11292 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11293 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11294 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11295 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11296 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11297 | // Now that all security checks passes, perform the operation as ourselves. |
| 11298 | final long identity = Binder.clearCallingIdentity(); |
| 11299 | try { |
| 11300 | Phone phone = getPhone(subId); |
| 11301 | if (phone != null && phone.getIccCard() != null) { |
| 11302 | return phone.getIccCard().getIccLockEnabled(); |
| 11303 | } else { |
| 11304 | return false; |
| 11305 | } |
| 11306 | } finally { |
| 11307 | Binder.restoreCallingIdentity(identity); |
| 11308 | } |
| 11309 | } |
| 11310 | |
| 11311 | /** |
| 11312 | * Set the ICC pin lock enabled or disabled. |
| 11313 | * |
| 11314 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11315 | * three cases: |
| 11316 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11317 | * successfully. |
| 11318 | * - Positive number and zero for remaining password attempts. |
| 11319 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11320 | * |
| 11321 | */ |
| 11322 | @Override |
| 11323 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11324 | enforceModifyPermission(); |
| 11325 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11326 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11327 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11328 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11329 | Phone phone = getPhone(subId); |
| 11330 | if (phone == null) { |
| 11331 | return 0; |
| 11332 | } |
| 11333 | // Now that all security checks passes, perform the operation as ourselves. |
| 11334 | final long identity = Binder.clearCallingIdentity(); |
| 11335 | try { |
| 11336 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11337 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11338 | return attemptsRemaining; |
| 11339 | |
| 11340 | } catch (Exception e) { |
| 11341 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11342 | } finally { |
| 11343 | Binder.restoreCallingIdentity(identity); |
| 11344 | } |
| 11345 | return 0; |
| 11346 | } |
| 11347 | |
| 11348 | /** |
| 11349 | * Change the ICC password used in ICC pin lock. |
| 11350 | * |
| 11351 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11352 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11353 | * - Positive number and zero for remaining password attempts. |
| 11354 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11355 | * |
| 11356 | */ |
| 11357 | @Override |
| 11358 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11359 | enforceModifyPermission(); |
| 11360 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11362 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11363 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11364 | Phone phone = getPhone(subId); |
| 11365 | if (phone == null) { |
| 11366 | return 0; |
| 11367 | } |
| 11368 | // Now that all security checks passes, perform the operation as ourselves. |
| 11369 | final long identity = Binder.clearCallingIdentity(); |
| 11370 | try { |
| 11371 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11372 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11373 | return attemptsRemaining; |
| 11374 | |
| 11375 | } catch (Exception e) { |
| 11376 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11377 | } finally { |
| 11378 | Binder.restoreCallingIdentity(identity); |
| 11379 | } |
| 11380 | return 0; |
| 11381 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11382 | |
| 11383 | /** |
| 11384 | * Request for receiving user activity notification |
| 11385 | */ |
| 11386 | @Override |
| 11387 | public void requestUserActivityNotification() { |
| 11388 | if (!mNotifyUserActivity.get() |
| 11389 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11390 | mNotifyUserActivity.set(true); |
| 11391 | } |
| 11392 | } |
| 11393 | |
| 11394 | /** |
| 11395 | * Called when userActivity is signalled in the power manager. |
| 11396 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11397 | */ |
| 11398 | @Override |
| 11399 | public void userActivity() { |
| 11400 | // *************************************** |
| 11401 | // * Inherited from PhoneWindowManager * |
| 11402 | // *************************************** |
| 11403 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11404 | // WITH ITS LOCKS HELD. |
| 11405 | // |
| 11406 | // This code must be VERY careful about the locks |
| 11407 | // it acquires. |
| 11408 | // In fact, the current code acquires way too many, |
| 11409 | // and probably has lurking deadlocks. |
| 11410 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11411 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11412 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11413 | } |
| 11414 | |
| 11415 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11416 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11417 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11418 | } |
| 11419 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11420 | |
| 11421 | @Override |
| 11422 | public boolean canConnectTo5GInDsdsMode() { |
| 11423 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11424 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11425 | |
| 11426 | @Override |
| 11427 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11428 | String callingFeatureId) { |
| 11429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11430 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11431 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11432 | } |
| 11433 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11434 | enforceTelephonyFeatureWithException(callingPackage, |
| 11435 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11436 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11437 | Phone phone = getPhone(subId); |
| 11438 | if (phone == null) { |
| 11439 | throw new RuntimeException("phone is not available"); |
| 11440 | } |
| 11441 | // Now that all security checks passes, perform the operation as ourselves. |
| 11442 | final long identity = Binder.clearCallingIdentity(); |
| 11443 | try { |
| 11444 | return phone.getEquivalentHomePlmns(); |
| 11445 | } finally { |
| 11446 | Binder.restoreCallingIdentity(identity); |
| 11447 | } |
| 11448 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11449 | |
| 11450 | @Override |
| 11451 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11452 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11453 | if (!mApp.getResources().getBoolean( |
| 11454 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11455 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11456 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11457 | "isRadioInterfaceCapabilitySupported"); |
| 11458 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11459 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11460 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11461 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11462 | if (radioInterfaceCapabilities == null) { |
| 11463 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11464 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11465 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11466 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11467 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11468 | @Override |
| 11469 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11470 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11471 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11472 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11473 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11474 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11475 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11476 | |
| 11477 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11478 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11479 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11480 | if (DBG) { |
| 11481 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11482 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11483 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11484 | } |
| 11485 | |
| 11486 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11487 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11488 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11489 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11490 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11491 | if (callback != null) { |
| 11492 | try { |
| 11493 | callback.onAuthenticationFailure( |
| 11494 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11495 | } catch (RemoteException exception) { |
| 11496 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11497 | } |
| 11498 | return; |
| 11499 | } |
| 11500 | } |
| 11501 | |
| 11502 | final long token = Binder.clearCallingIdentity(); |
| 11503 | try { |
| 11504 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11505 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11506 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11507 | } finally { |
| 11508 | Binder.restoreCallingIdentity(token); |
| 11509 | } |
| 11510 | } |
| 11511 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11512 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11513 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11514 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11515 | * requested radio power state will actually be set. See {@link |
| 11516 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11517 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11518 | * @param enable {@code true} if trying to turn radio on. |
| 11519 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11520 | * false}. |
| 11521 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11522 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11523 | boolean isPhoneAvailable = false; |
| 11524 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11525 | Phone phone = PhoneFactory.getPhone(i); |
| 11526 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11527 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11528 | isPhoneAvailable = true; |
| 11529 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11530 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11531 | |
| 11532 | // return true if successfully informed the phone object about the thermal radio power |
| 11533 | // request. |
| 11534 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11535 | } |
| 11536 | |
| 11537 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11538 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11539 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11540 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11541 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11542 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11543 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11544 | } |
| 11545 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11546 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11547 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11548 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11549 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11550 | } |
| 11551 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11552 | setDataEnabledForReason( |
| 11553 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11554 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11555 | if (isDataThrottlingSupported) { |
| 11556 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11557 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11558 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11559 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11560 | } else if (thermalMitigationResult |
| 11561 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11562 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11563 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11564 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11565 | } |
| 11566 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11567 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11568 | |
| 11569 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11570 | } |
| 11571 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11572 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11573 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11574 | for (String pckg : context.getResources() |
| 11575 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11576 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11577 | } |
| 11578 | } |
| 11579 | |
| 11580 | return sThermalMitigationAllowlistedPackages; |
| 11581 | } |
| 11582 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11583 | private boolean isAnyPhoneInEmergencyState() { |
| 11584 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11585 | if (tm.isInEmergencyCall()) { |
| 11586 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11587 | return true; |
| 11588 | } |
| 11589 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11590 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11591 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11592 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11593 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11594 | return true; |
| 11595 | } |
| 11596 | } |
| 11597 | |
| 11598 | return false; |
| 11599 | } |
| 11600 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11601 | /** |
| 11602 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11603 | * @param packageName name of package to be allowlisted |
| 11604 | * @param context |
| 11605 | */ |
| 11606 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11607 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11608 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11609 | } |
| 11610 | |
| 11611 | /** |
| 11612 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11613 | * @param packageName name of package to remove from allowlist |
| 11614 | * @param context |
| 11615 | */ |
| 11616 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11617 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11618 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11619 | } |
| 11620 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11621 | /** |
| 11622 | * Thermal mitigation request to control functionalities at modem. |
| 11623 | * |
| 11624 | * @param subId the id of the subscription. |
| 11625 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11626 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11627 | * |
| 11628 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11629 | */ |
| 11630 | @Override |
| 11631 | @ThermalMitigationResult |
| 11632 | public int sendThermalMitigationRequest( |
| 11633 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11634 | ThermalMitigationRequest thermalMitigationRequest, |
| 11635 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11636 | enforceModifyPermission(); |
| 11637 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11638 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11639 | |
| 11640 | enforceTelephonyFeatureWithException(callingPackage, |
| 11641 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11642 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11643 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11644 | .contains(callingPackage)) { |
| 11645 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11646 | + "calling package: " + callingPackage); |
| 11647 | } |
| 11648 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11649 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11650 | final long identity = Binder.clearCallingIdentity(); |
| 11651 | |
| 11652 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11653 | try { |
| 11654 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11655 | switch (thermalMitigationAction) { |
| 11656 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11657 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11658 | handleDataThrottlingRequest(subId, |
| 11659 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11660 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11661 | break; |
| 11662 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11663 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11664 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11665 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11666 | } |
| 11667 | |
| 11668 | // Ensure that radio is on. If not able to power on due to phone being |
| 11669 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11670 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11671 | thermalMitigationResult = |
| 11672 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11673 | break; |
| 11674 | } |
| 11675 | |
| 11676 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11677 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11678 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11679 | break; |
| 11680 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11681 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11682 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11683 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11684 | } |
| 11685 | |
| 11686 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11687 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11688 | Phone phone = getPhone(subId); |
| 11689 | if (phone == null) { |
| 11690 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11691 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11692 | break; |
| 11693 | } |
| 11694 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11695 | TelephonyConnectionService service = |
| 11696 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11697 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11698 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11699 | thermalMitigationResult = |
| 11700 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11701 | break; |
| 11702 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11703 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11704 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11705 | break; |
| 11706 | } |
| 11707 | } else { |
| 11708 | thermalMitigationResult = |
| 11709 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11710 | break; |
| 11711 | } |
| 11712 | |
| 11713 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11714 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11715 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11716 | thermalMitigationResult = |
| 11717 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11718 | break; |
| 11719 | } |
| 11720 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11721 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11722 | break; |
| 11723 | default: |
| 11724 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11725 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11726 | } |
| 11727 | } catch (IllegalArgumentException e) { |
| 11728 | throw e; |
| 11729 | } catch (Exception e) { |
| 11730 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11731 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11732 | } finally { |
| 11733 | Binder.restoreCallingIdentity(identity); |
| 11734 | } |
| 11735 | |
| 11736 | if (DBG) { |
| 11737 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11738 | + thermalMitigationResult); |
| 11739 | } |
| 11740 | |
| 11741 | return thermalMitigationResult; |
| 11742 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11743 | |
| 11744 | /** |
| 11745 | * Set the GbaService Package Name that Telephony will bind to. |
| 11746 | * |
| 11747 | * @param subId The sim that the GbaService is associated with. |
| 11748 | * @param packageName The name of the package to be replaced with. |
| 11749 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11750 | */ |
| 11751 | @Override |
| 11752 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11753 | enforceModifyPermission(); |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11754 | int userId = ActivityManager.getCurrentUser(); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11755 | final long identity = Binder.clearCallingIdentity(); |
| 11756 | try { |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11757 | return getGbaManager(subId).overrideServicePackage(packageName, userId); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11758 | } finally { |
| 11759 | Binder.restoreCallingIdentity(identity); |
| 11760 | } |
| 11761 | } |
| 11762 | |
| 11763 | /** |
| 11764 | * Return the package name of the currently bound GbaService. |
| 11765 | * |
| 11766 | * @param subId The sim that the GbaService is associated with. |
| 11767 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11768 | */ |
| 11769 | @Override |
| 11770 | public String getBoundGbaService(int subId) { |
| 11771 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11772 | |
| 11773 | final long identity = Binder.clearCallingIdentity(); |
| 11774 | try { |
| 11775 | return getGbaManager(subId).getServicePackage(); |
| 11776 | } finally { |
| 11777 | Binder.restoreCallingIdentity(identity); |
| 11778 | } |
| 11779 | } |
| 11780 | |
| 11781 | /** |
| 11782 | * Set the release time for telephony to unbind GbaService. |
| 11783 | * |
| 11784 | * @param subId The sim that the GbaService is associated with. |
| 11785 | * @param interval The release time to unbind GbaService by millisecond. |
| 11786 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11787 | */ |
| 11788 | @Override |
| 11789 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11790 | enforceModifyPermission(); |
| 11791 | |
| 11792 | final long identity = Binder.clearCallingIdentity(); |
| 11793 | try { |
| 11794 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11795 | } finally { |
| 11796 | Binder.restoreCallingIdentity(identity); |
| 11797 | } |
| 11798 | } |
| 11799 | |
| 11800 | /** |
| 11801 | * Return the release time for telephony to unbind GbaService. |
| 11802 | * |
| 11803 | * @param subId The sim that the GbaService is associated with. |
| 11804 | * @return The release time to unbind GbaService by millisecond. |
| 11805 | */ |
| 11806 | @Override |
| 11807 | public int getGbaReleaseTime(int subId) { |
| 11808 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11809 | |
| 11810 | final long identity = Binder.clearCallingIdentity(); |
| 11811 | try { |
| 11812 | return getGbaManager(subId).getReleaseTime(); |
| 11813 | } finally { |
| 11814 | Binder.restoreCallingIdentity(identity); |
| 11815 | } |
| 11816 | } |
| 11817 | |
| 11818 | private GbaManager getGbaManager(int subId) { |
| 11819 | GbaManager instance = GbaManager.getInstance(subId); |
| 11820 | if (instance == null) { |
| 11821 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11822 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11823 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11824 | } |
| 11825 | return instance; |
| 11826 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11827 | |
| 11828 | /** |
| 11829 | * indicate whether the device and the carrier can support |
| 11830 | * RCS VoLTE single registration. |
| 11831 | */ |
| 11832 | @Override |
| 11833 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11834 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11835 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11836 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11837 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11838 | |
| 11839 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11840 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11841 | } |
| 11842 | |
| 11843 | final long identity = Binder.clearCallingIdentity(); |
| 11844 | try { |
| 11845 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11846 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11847 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11848 | if (isCapable != null) { |
| 11849 | return isCapable; |
| 11850 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11851 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11853 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11854 | } finally { |
| 11855 | Binder.restoreCallingIdentity(identity); |
| 11856 | } |
| 11857 | } |
| 11858 | |
| 11859 | /** |
| 11860 | * Register RCS provisioning callback. |
| 11861 | */ |
| 11862 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11863 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11864 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11865 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11866 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11867 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11868 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11869 | |
| 11870 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11871 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11872 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11873 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11874 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11875 | Binder.getCallingUserHandle())) { |
| 11876 | if (!isImsAvailableOnDevice()) { |
| 11877 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11878 | "IMS not available on device."); |
| 11879 | } |
| 11880 | } else { |
| 11881 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11882 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11883 | } |
| 11884 | |
| 11885 | final long identity = Binder.clearCallingIdentity(); |
| 11886 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11887 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11888 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11889 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11890 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11891 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11892 | } finally { |
| 11893 | Binder.restoreCallingIdentity(identity); |
| 11894 | } |
| 11895 | } |
| 11896 | |
| 11897 | /** |
| 11898 | * Unregister RCS provisioning callback. |
| 11899 | */ |
| 11900 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11901 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11902 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11903 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11904 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11905 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11906 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11907 | |
| 11908 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11909 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11910 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11911 | |
| 11912 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11913 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11914 | Binder.getCallingUserHandle())) { |
| 11915 | if (!isImsAvailableOnDevice()) { |
| 11916 | // operation failed silently |
| 11917 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11918 | return; |
| 11919 | } |
| 11920 | } else { |
| 11921 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11922 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11923 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11924 | } |
| 11925 | |
| 11926 | final long identity = Binder.clearCallingIdentity(); |
| 11927 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11928 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11929 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11930 | } finally { |
| 11931 | Binder.restoreCallingIdentity(identity); |
| 11932 | } |
| 11933 | } |
| 11934 | |
| 11935 | /** |
| 11936 | * trigger RCS reconfiguration. |
| 11937 | */ |
| 11938 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11939 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11940 | "triggerRcsReconfiguration", |
| 11941 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11942 | |
| 11943 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11944 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11945 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11946 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11947 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11948 | Binder.getCallingUserHandle())) { |
| 11949 | if (!isImsAvailableOnDevice()) { |
| 11950 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11951 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11952 | throw new IllegalStateException("IMS not available on device."); |
| 11953 | } |
| 11954 | } else { |
| 11955 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11956 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11957 | } |
| 11958 | |
| 11959 | final long identity = Binder.clearCallingIdentity(); |
| 11960 | try { |
| 11961 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11962 | } finally { |
| 11963 | Binder.restoreCallingIdentity(identity); |
| 11964 | } |
| 11965 | } |
| 11966 | |
| 11967 | /** |
| 11968 | * Provide the client configuration parameters of the RCS application. |
| 11969 | */ |
| 11970 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11971 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11972 | "setRcsClientConfiguration", |
| 11973 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11974 | |
| 11975 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11976 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11977 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11978 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11979 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11980 | Binder.getCallingUserHandle())) { |
| 11981 | if (!isImsAvailableOnDevice()) { |
| 11982 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11983 | "IMS not available on device."); |
| 11984 | } |
| 11985 | } else { |
| 11986 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11987 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11988 | } |
| 11989 | |
| 11990 | final long identity = Binder.clearCallingIdentity(); |
| 11991 | |
| 11992 | try { |
| 11993 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11994 | if (configBinder == null) { |
| 11995 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11996 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11997 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11998 | } else { |
| 11999 | configBinder.setRcsClientConfiguration(rcc); |
| 12000 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 12001 | |
| 12002 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 12003 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12004 | } catch (RemoteException e) { |
| 12005 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 12006 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 12007 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12008 | } finally { |
| 12009 | Binder.restoreCallingIdentity(identity); |
| 12010 | } |
| 12011 | } |
| 12012 | |
| 12013 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 12014 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 12015 | */ |
| 12016 | @Override |
| 12017 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 12018 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12019 | "setRcsSingleRegistrationTestModeEnabled"); |
| 12020 | |
| 12021 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 12022 | } |
| 12023 | |
| 12024 | /** |
| 12025 | * Gets the test mode for RCS VoLTE single registration. |
| 12026 | */ |
| 12027 | @Override |
| 12028 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 12029 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12030 | "getRcsSingleRegistrationTestModeEnabled"); |
| 12031 | |
| 12032 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 12033 | } |
| 12034 | |
| 12035 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12036 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 12037 | */ |
| 12038 | @Override |
| 12039 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 12040 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12041 | "setDeviceSingleRegistrationEnabledOverride"); |
| 12042 | enforceModifyPermission(); |
| 12043 | |
| 12044 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12045 | : Boolean.parseBoolean(enabledStr); |
| 12046 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 12047 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12048 | } |
| 12049 | |
| 12050 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12051 | * Sends a device to device communication message. Only usable via shell. |
| 12052 | * @param message message to send. |
| 12053 | * @param value message value. |
| 12054 | */ |
| 12055 | @Override |
| 12056 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12057 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12058 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12059 | enforceModifyPermission(); |
| 12060 | |
| 12061 | final long identity = Binder.clearCallingIdentity(); |
| 12062 | try { |
| 12063 | TelephonyConnectionService service = |
| 12064 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12065 | if (service == null) { |
| 12066 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12067 | return; |
| 12068 | } |
| 12069 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12070 | } finally { |
| 12071 | Binder.restoreCallingIdentity(identity); |
| 12072 | } |
| 12073 | } |
| 12074 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12075 | /** |
| 12076 | * Sets the specified device to device transport active. |
| 12077 | * @param transport The transport to set active. |
| 12078 | */ |
| 12079 | @Override |
| 12080 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12081 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12082 | "setActiveDeviceToDeviceTransport"); |
| 12083 | enforceModifyPermission(); |
| 12084 | |
| 12085 | final long identity = Binder.clearCallingIdentity(); |
| 12086 | try { |
| 12087 | TelephonyConnectionService service = |
| 12088 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12089 | if (service == null) { |
| 12090 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12091 | return; |
| 12092 | } |
| 12093 | service.setActiveDeviceToDeviceTransport(transport); |
| 12094 | } finally { |
| 12095 | Binder.restoreCallingIdentity(identity); |
| 12096 | } |
| 12097 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12098 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12099 | @Override |
| 12100 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12101 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12102 | "setDeviceToDeviceForceEnabled"); |
| 12103 | |
| 12104 | final long identity = Binder.clearCallingIdentity(); |
| 12105 | try { |
| 12106 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12107 | p -> { |
| 12108 | Phone thePhone = p.getImsPhone(); |
| 12109 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12110 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12111 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12112 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12113 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12114 | (ImsPhoneCallTracker) tracker; |
| 12115 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12116 | } |
| 12117 | } |
| 12118 | } |
| 12119 | ); |
| 12120 | } finally { |
| 12121 | Binder.restoreCallingIdentity(identity); |
| 12122 | } |
| 12123 | } |
| 12124 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12125 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12126 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12127 | */ |
| 12128 | @Override |
| 12129 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12130 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12131 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12132 | } |
| 12133 | |
| 12134 | /** |
| 12135 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12136 | */ |
| 12137 | @Override |
| 12138 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12139 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12140 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12141 | enforceModifyPermission(); |
| 12142 | |
| 12143 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12144 | : Boolean.parseBoolean(enabledStr); |
| 12145 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12146 | subId, enabled); |
| 12147 | } |
| 12148 | |
| 12149 | /** |
| 12150 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12151 | */ |
| 12152 | @Override |
| 12153 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12154 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12155 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12156 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12157 | |
| 12158 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12159 | * Overrides the ims feature validation result |
| 12160 | */ |
| 12161 | @Override |
| 12162 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12164 | "setImsFeatureValidationOverride"); |
| 12165 | |
| 12166 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12167 | : Boolean.parseBoolean(enabledStr); |
| 12168 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12169 | subId, enabled); |
| 12170 | } |
| 12171 | |
| 12172 | /** |
| 12173 | * Gets the ims feature validation override value |
| 12174 | */ |
| 12175 | @Override |
| 12176 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12178 | "getImsFeatureValidationOverride"); |
| 12179 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12180 | } |
| 12181 | |
| 12182 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12183 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12184 | * their mobile plan. |
| 12185 | */ |
| 12186 | @Override |
| 12187 | public String getMobileProvisioningUrl() { |
| 12188 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12189 | final long identity = Binder.clearCallingIdentity(); |
| 12190 | try { |
| 12191 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12192 | } finally { |
| 12193 | Binder.restoreCallingIdentity(identity); |
| 12194 | } |
| 12195 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12196 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12197 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12198 | * Get the EAB contact from the EAB database. |
| 12199 | */ |
| 12200 | @Override |
| 12201 | public String getContactFromEab(String contact) { |
| 12202 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12203 | enforceModifyPermission(); |
| 12204 | final long identity = Binder.clearCallingIdentity(); |
| 12205 | try { |
| 12206 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12207 | } finally { |
| 12208 | Binder.restoreCallingIdentity(identity); |
| 12209 | } |
| 12210 | } |
| 12211 | |
| 12212 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12213 | * Get the EAB capability from the EAB database. |
| 12214 | */ |
| 12215 | @Override |
| 12216 | public String getCapabilityFromEab(String contact) { |
| 12217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12218 | enforceModifyPermission(); |
| 12219 | final long identity = Binder.clearCallingIdentity(); |
| 12220 | try { |
| 12221 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12222 | } finally { |
| 12223 | Binder.restoreCallingIdentity(identity); |
| 12224 | } |
| 12225 | } |
| 12226 | |
| 12227 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12228 | * Remove the EAB contacts from the EAB database. |
| 12229 | */ |
| 12230 | @Override |
| 12231 | public int removeContactFromEab(int subId, String contacts) { |
| 12232 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12233 | enforceModifyPermission(); |
| 12234 | final long identity = Binder.clearCallingIdentity(); |
| 12235 | try { |
| 12236 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12237 | } finally { |
| 12238 | Binder.restoreCallingIdentity(identity); |
| 12239 | } |
| 12240 | } |
| 12241 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12242 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12243 | public boolean getDeviceUceEnabled() { |
| 12244 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12245 | final long identity = Binder.clearCallingIdentity(); |
| 12246 | try { |
| 12247 | return mApp.getDeviceUceEnabled(); |
| 12248 | } finally { |
| 12249 | Binder.restoreCallingIdentity(identity); |
| 12250 | } |
| 12251 | } |
| 12252 | |
| 12253 | @Override |
| 12254 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12255 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12256 | final long identity = Binder.clearCallingIdentity(); |
| 12257 | try { |
| 12258 | mApp.setDeviceUceEnabled(isEnabled); |
| 12259 | } finally { |
| 12260 | Binder.restoreCallingIdentity(identity); |
| 12261 | } |
| 12262 | } |
| 12263 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12264 | /** |
| 12265 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12266 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12267 | */ |
| 12268 | // Used for SHELL command only right now. |
| 12269 | @Override |
| 12270 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12271 | List<String> featureTags) { |
| 12272 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12273 | "addUceRegistrationOverrideShell"); |
| 12274 | final long identity = Binder.clearCallingIdentity(); |
| 12275 | try { |
| 12276 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12277 | new ArraySet<>(featureTags)); |
| 12278 | } catch (ImsException e) { |
| 12279 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12280 | } finally { |
| 12281 | Binder.restoreCallingIdentity(identity); |
| 12282 | } |
| 12283 | } |
| 12284 | |
| 12285 | /** |
| 12286 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12287 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12288 | */ |
| 12289 | // Used for SHELL command only right now. |
| 12290 | @Override |
| 12291 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12292 | List<String> featureTags) { |
| 12293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12294 | "removeUceRegistrationOverrideShell"); |
| 12295 | final long identity = Binder.clearCallingIdentity(); |
| 12296 | try { |
| 12297 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12298 | new ArraySet<>(featureTags)); |
| 12299 | } catch (ImsException e) { |
| 12300 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12301 | } finally { |
| 12302 | Binder.restoreCallingIdentity(identity); |
| 12303 | } |
| 12304 | } |
| 12305 | |
| 12306 | /** |
| 12307 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12308 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12309 | */ |
| 12310 | // Used for SHELL command only right now. |
| 12311 | @Override |
| 12312 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12313 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12314 | "clearUceRegistrationOverrideShell"); |
| 12315 | final long identity = Binder.clearCallingIdentity(); |
| 12316 | try { |
| 12317 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12318 | } catch (ImsException e) { |
| 12319 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12320 | } finally { |
| 12321 | Binder.restoreCallingIdentity(identity); |
| 12322 | } |
| 12323 | } |
| 12324 | |
| 12325 | /** |
| 12326 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12327 | */ |
| 12328 | // Used for SHELL command only right now. |
| 12329 | @Override |
| 12330 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12331 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12332 | "getLatestRcsContactUceCapabilityShell"); |
| 12333 | final long identity = Binder.clearCallingIdentity(); |
| 12334 | try { |
| 12335 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12336 | } catch (ImsException e) { |
| 12337 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12338 | } finally { |
| 12339 | Binder.restoreCallingIdentity(identity); |
| 12340 | } |
| 12341 | } |
| 12342 | |
| 12343 | /** |
| 12344 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12345 | * device does not have an active PUBLISH. |
| 12346 | */ |
| 12347 | // Used for SHELL command only right now. |
| 12348 | @Override |
| 12349 | public String getLastUcePidfXmlShell(int subId) { |
| 12350 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12351 | final long identity = Binder.clearCallingIdentity(); |
| 12352 | try { |
| 12353 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12354 | } catch (ImsException e) { |
| 12355 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12356 | } finally { |
| 12357 | Binder.restoreCallingIdentity(identity); |
| 12358 | } |
| 12359 | } |
| 12360 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12361 | /** |
| 12362 | * Remove UCE requests cannot be sent to the network status. |
| 12363 | */ |
| 12364 | // Used for SHELL command only right now. |
| 12365 | @Override |
| 12366 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12367 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12368 | final long identity = Binder.clearCallingIdentity(); |
| 12369 | try { |
| 12370 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12371 | } catch (ImsException e) { |
| 12372 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12373 | } finally { |
| 12374 | Binder.restoreCallingIdentity(identity); |
| 12375 | } |
| 12376 | } |
| 12377 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12378 | /** |
| 12379 | * Remove UCE requests cannot be sent to the network status. |
| 12380 | */ |
| 12381 | // Used for SHELL command only. |
| 12382 | @Override |
| 12383 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12384 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12385 | final long identity = Binder.clearCallingIdentity(); |
| 12386 | try { |
| 12387 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12388 | } catch (ImsException e) { |
| 12389 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12390 | } finally { |
| 12391 | Binder.restoreCallingIdentity(identity); |
| 12392 | } |
| 12393 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12394 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12395 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12396 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12397 | String callingPackage) { |
| 12398 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12399 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12400 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12401 | enforceTelephonyFeatureWithException(callingPackage, |
| 12402 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12403 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12404 | final int callingUid = Binder.getCallingUid(); |
| 12405 | // Verify that tha callingPackage belongs to the calling UID |
| 12406 | mApp.getSystemService(AppOpsManager.class) |
| 12407 | .checkPackage(callingUid, callingPackage); |
| 12408 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12409 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12410 | |
| 12411 | final long identity = Binder.clearCallingIdentity(); |
| 12412 | try { |
| 12413 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12414 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12415 | |
| 12416 | if (result instanceof IllegalStateException) { |
| 12417 | throw (IllegalStateException) result; |
| 12418 | } |
| 12419 | } finally { |
| 12420 | Binder.restoreCallingIdentity(identity); |
| 12421 | } |
| 12422 | } |
| 12423 | |
| 12424 | @Override |
| 12425 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12426 | String callingPackage) { |
| 12427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12428 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12429 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12430 | enforceTelephonyFeatureWithException(callingPackage, |
| 12431 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12432 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12433 | final int callingUid = Binder.getCallingUid(); |
| 12434 | // Verify that tha callingPackage belongs to the calling UID |
| 12435 | mApp.getSystemService(AppOpsManager.class) |
| 12436 | .checkPackage(callingUid, callingPackage); |
| 12437 | |
| 12438 | final long identity = Binder.clearCallingIdentity(); |
| 12439 | try { |
| 12440 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12441 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12442 | |
| 12443 | if (result instanceof IllegalStateException) { |
| 12444 | throw (IllegalStateException) result; |
| 12445 | } |
| 12446 | } finally { |
| 12447 | Binder.restoreCallingIdentity(identity); |
| 12448 | } |
| 12449 | } |
| 12450 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12451 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12452 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12453 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12454 | // phone/system process do not have further restriction on request |
| 12455 | return; |
| 12456 | } |
| 12457 | |
| 12458 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12459 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12460 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12461 | context.enforceCallingOrSelfPermission( |
| 12462 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12463 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12464 | } |
| 12465 | |
| 12466 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12467 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12468 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12469 | || info.isEnabled()) { |
| 12470 | throw new IllegalArgumentException( |
| 12471 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12472 | } |
| 12473 | |
| 12474 | // Thresholds length for each RAN need in range. This has been validated in |
| 12475 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12476 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12477 | final int[] thresholds = info.getThresholds(); |
| 12478 | Objects.requireNonNull(thresholds); |
| 12479 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12480 | || thresholds.length |
| 12481 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12482 | throw new IllegalArgumentException( |
| 12483 | "thresholds length is out of range: " + thresholds.length); |
| 12484 | } |
| 12485 | } |
| 12486 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12487 | |
| 12488 | /** |
| 12489 | * Gets the current phone capability. |
| 12490 | * |
| 12491 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12492 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12493 | * It's used to evaluate possible phone config change, for example from single |
| 12494 | * SIM device to multi-SIM device. |
| 12495 | */ |
| 12496 | @Override |
| 12497 | public PhoneCapability getPhoneCapability() { |
| 12498 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12499 | |
| 12500 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12501 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12502 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12503 | final long identity = Binder.clearCallingIdentity(); |
| 12504 | try { |
| 12505 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12506 | } finally { |
| 12507 | Binder.restoreCallingIdentity(identity); |
| 12508 | } |
| 12509 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12510 | |
| 12511 | /** |
| 12512 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12513 | * required to be done shortly after the API is invoked. |
| 12514 | */ |
| 12515 | @Override |
| 12516 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12517 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12518 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12519 | enforceRebootPermission(); |
| 12520 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12522 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12523 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12524 | final long identity = Binder.clearCallingIdentity(); |
| 12525 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12526 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12527 | } finally { |
| 12528 | Binder.restoreCallingIdentity(identity); |
| 12529 | } |
| 12530 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12531 | |
| 12532 | /** |
| 12533 | * Request to get the current slicing configuration including URSP rules and |
| 12534 | * NSSAIs (configured, allowed and rejected). |
| 12535 | * |
| 12536 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12537 | */ |
| 12538 | @Override |
| 12539 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12540 | TelephonyPermissions |
| 12541 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12542 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12543 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12544 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12545 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12546 | "getSlicingConfig"); |
| 12547 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12548 | final long identity = Binder.clearCallingIdentity(); |
| 12549 | try { |
| 12550 | Phone phone = getDefaultPhone(); |
| 12551 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12552 | } finally { |
| 12553 | Binder.restoreCallingIdentity(identity); |
| 12554 | } |
| 12555 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12556 | |
| 12557 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12558 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12559 | * |
| 12560 | * @param capability The premium capability to check. |
| 12561 | * @param subId The subId to check the premium capability for. |
| 12562 | * |
| 12563 | * @return Whether the given premium capability is available to purchase. |
| 12564 | */ |
| 12565 | @Override |
| 12566 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12567 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12568 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12569 | log("Premium capability " |
| 12570 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12571 | + " is not available for purchase due to missing permissions."); |
| 12572 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12573 | + "permission READ_BASIC_PHONE_STATE."); |
| 12574 | } |
| 12575 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12576 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12577 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12578 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12579 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12580 | if (phone == null) { |
| 12581 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12582 | return false; |
| 12583 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12584 | final long identity = Binder.clearCallingIdentity(); |
| 12585 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12586 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12587 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12588 | } finally { |
| 12589 | Binder.restoreCallingIdentity(identity); |
| 12590 | } |
| 12591 | } |
| 12592 | |
| 12593 | /** |
| 12594 | * Purchase the given premium capability from the carrier. |
| 12595 | * |
| 12596 | * @param capability The premium capability to purchase. |
| 12597 | * @param callback The result of the purchase request. |
| 12598 | * @param subId The subId to purchase the premium capability for. |
| 12599 | */ |
| 12600 | @Override |
| 12601 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12602 | log("purchasePremiumCapability: capability=" |
| 12603 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12604 | + getCurrentPackageName()); |
| 12605 | |
| 12606 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12607 | mApp, "purchasePremiumCapability")) { |
| 12608 | log("purchasePremiumCapability " |
| 12609 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12610 | + " failed due to missing permissions."); |
| 12611 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12612 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12613 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12614 | mApp, "purchasePremiumCapability")) { |
| 12615 | log("purchasePremiumCapability " |
| 12616 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12617 | + " failed due to missing permissions."); |
| 12618 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12619 | } |
| 12620 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12621 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12622 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12623 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12624 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12625 | if (phone == null) { |
| 12626 | try { |
| 12627 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12628 | callback.accept(result); |
| 12629 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12630 | } catch (RemoteException e) { |
| 12631 | String logStr = "Purchase premium capability " |
| 12632 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12633 | + " failed due to RemoteException handling null phone: " + e; |
| 12634 | if (DBG) log(logStr); |
| 12635 | AnomalyReporter.reportAnomaly( |
| 12636 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12637 | } |
| 12638 | return; |
| 12639 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12640 | |
| 12641 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12642 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12643 | if (mFeatureFlags.hsumPackageManager()) { |
| 12644 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12645 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12646 | } else { |
| 12647 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12648 | getCurrentPackageName(), 0).processName; |
| 12649 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12650 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12651 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12652 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12653 | |
| 12654 | boolean isVisible = false; |
| 12655 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12656 | if (am != null) { |
| 12657 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12658 | if (processes != null) { |
| 12659 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12660 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12661 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12662 | if (process.processName.equals(callingProcess) && process.importance |
| 12663 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12664 | isVisible = true; |
| 12665 | break; |
| 12666 | } |
| 12667 | } |
| 12668 | } |
| 12669 | } |
| 12670 | |
| 12671 | if (!isVisible) { |
| 12672 | try { |
| 12673 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12674 | callback.accept(result); |
| 12675 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12676 | } catch (RemoteException e) { |
| 12677 | String logStr = "Purchase premium capability " |
| 12678 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12679 | + " failed due to RemoteException handling background application: " + e; |
| 12680 | if (DBG) log(logStr); |
| 12681 | AnomalyReporter.reportAnomaly( |
| 12682 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12683 | } |
| 12684 | return; |
| 12685 | } |
| 12686 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12687 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12688 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12689 | } |
| 12690 | |
| 12691 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12692 | * Register an IMS connection state callback |
| 12693 | */ |
| 12694 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12695 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12696 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12697 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12698 | // ImsMmTelManager |
| 12699 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12700 | TelephonyPermissions |
| 12701 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12702 | mApp, subId, "registerImsStateCallback"); |
| 12703 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12704 | // ImsRcsManager or SipDelegateManager |
| 12705 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12706 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12707 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12708 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12709 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12710 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12711 | } |
| 12712 | |
| 12713 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12715 | "IMS not available on device."); |
| 12716 | } |
| 12717 | |
| 12718 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12719 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12720 | } |
| 12721 | |
| 12722 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12723 | if (controller == null) { |
| 12724 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12725 | "IMS not available on device."); |
| 12726 | } |
| 12727 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12728 | if (callingPackage == null) { |
| 12729 | callingPackage = getCurrentPackageName(); |
| 12730 | } |
| 12731 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12732 | final long token = Binder.clearCallingIdentity(); |
| 12733 | try { |
| 12734 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12735 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12736 | } catch (ImsException e) { |
| 12737 | throw new ServiceSpecificException(e.getCode()); |
| 12738 | } finally { |
| 12739 | Binder.restoreCallingIdentity(token); |
| 12740 | } |
| 12741 | } |
| 12742 | |
| 12743 | /** |
| 12744 | * Unregister an IMS connection state callback |
| 12745 | */ |
| 12746 | @Override |
| 12747 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12748 | final long token = Binder.clearCallingIdentity(); |
| 12749 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12750 | if (controller == null) { |
| 12751 | return; |
| 12752 | } |
| 12753 | try { |
| 12754 | controller.unregisterImsStateCallback(cb); |
| 12755 | } finally { |
| 12756 | Binder.restoreCallingIdentity(token); |
| 12757 | } |
| 12758 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12759 | |
| 12760 | /** |
| 12761 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12762 | * |
| 12763 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12764 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12765 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12766 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12767 | * If there is current registered network this value will be same as the registered cell |
| 12768 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12769 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12770 | * it will be cleared and null will be returned. |
| 12771 | * |
| 12772 | */ |
| 12773 | @Override |
| 12774 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12775 | String callingFeatureId) { |
| 12776 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12777 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12778 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12779 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12780 | .setCallingPackage(callingPackage) |
| 12781 | .setCallingFeatureId(callingFeatureId) |
| 12782 | .setCallingPid(Binder.getCallingPid()) |
| 12783 | .setCallingUid(Binder.getCallingUid()) |
| 12784 | .setMethod("getLastKnownCellIdentity") |
| 12785 | .setLogAsInfo(true) |
| 12786 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12787 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12788 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12789 | .build()); |
| 12790 | |
| 12791 | boolean hasFinePermission = |
| 12792 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12793 | if (!hasFinePermission |
| 12794 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12795 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12796 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12797 | } |
| 12798 | |
| 12799 | final long identity = Binder.clearCallingIdentity(); |
| 12800 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12801 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12802 | if (sst == null) return null; |
| 12803 | return sst.getLastKnownCellIdentity(); |
| 12804 | } finally { |
| 12805 | Binder.restoreCallingIdentity(identity); |
| 12806 | } |
| 12807 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12808 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12809 | /** |
| 12810 | * Sets the modem service class Name that Telephony will bind to. |
| 12811 | * |
| 12812 | * @param serviceName The class name of the modem service. |
| 12813 | * @return true if the operation is succeed, otherwise false. |
| 12814 | */ |
| 12815 | public boolean setModemService(String serviceName) { |
| 12816 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12817 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12819 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12820 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12821 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12822 | } |
| 12823 | |
| 12824 | /** |
| 12825 | * Return the class name of the currently bounded modem service. |
| 12826 | * |
| 12827 | * @return the class name of the modem service. |
| 12828 | */ |
| 12829 | public String getModemService() { |
| 12830 | String result; |
| 12831 | Log.d(LOG_TAG, "getModemService"); |
| 12832 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12833 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12834 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12835 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12836 | "getModemService"); |
| 12837 | result = mPhoneConfigurationManager.getModemService(); |
| 12838 | Log.d(LOG_TAG, "result = " + result); |
| 12839 | return result; |
| 12840 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12841 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12842 | /** |
| 12843 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12844 | * including carrier config, entitlement server, and config update. |
| 12845 | * |
| 12846 | * @param subId subId The subscription ID of the carrier. |
| 12847 | * |
| 12848 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12849 | * be returned. |
| 12850 | * |
| 12851 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12852 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12853 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12854 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12855 | final long identity = Binder.clearCallingIdentity(); |
| 12856 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12857 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12858 | } finally { |
| 12859 | Binder.restoreCallingIdentity(identity); |
| 12860 | } |
| 12861 | } |
| 12862 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12863 | @Override |
| 12864 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12865 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12866 | mApp.enforceCallingOrSelfPermission( |
| 12867 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12868 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12869 | |
| 12870 | final long identity = Binder.clearCallingIdentity(); |
| 12871 | try { |
| 12872 | Phone phone = getPhone(subId); |
| 12873 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12874 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12875 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12876 | phone.setVoiceServiceStateOverride(hasService); |
| 12877 | } finally { |
| 12878 | Binder.restoreCallingIdentity(identity); |
| 12879 | } |
| 12880 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12881 | |
| 12882 | /** |
| 12883 | * set removable eSIM as default eUICC. |
| 12884 | * |
| 12885 | * @hide |
| 12886 | */ |
| 12887 | @Override |
| 12888 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12889 | enforceModifyPermission(); |
| 12890 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12891 | |
| 12892 | final long identity = Binder.clearCallingIdentity(); |
| 12893 | try { |
| 12894 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12895 | } finally { |
| 12896 | Binder.restoreCallingIdentity(identity); |
| 12897 | } |
| 12898 | } |
| 12899 | |
| 12900 | /** |
| 12901 | * Returns whether the removable eSIM is default eUICC or not. |
| 12902 | * |
| 12903 | * @hide |
| 12904 | */ |
| 12905 | @Override |
| 12906 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12907 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12909 | |
| 12910 | final long identity = Binder.clearCallingIdentity(); |
| 12911 | try { |
| 12912 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12913 | } finally { |
| 12914 | Binder.restoreCallingIdentity(identity); |
| 12915 | } |
| 12916 | } |
| 12917 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12918 | /** |
| 12919 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12920 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12921 | * application currently configured for this user. |
| 12922 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12923 | * {@code null} if the functionality is not supported. |
| 12924 | * @hide |
| 12925 | */ |
| 12926 | @Override |
| 12927 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12928 | boolean updateIfNeeded) { |
| 12929 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12930 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12931 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12932 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12933 | "getDefaultRespondViaMessageApplication"); |
| 12934 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12935 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12936 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12937 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12938 | UserHandle mainUser = null; |
| 12939 | Context userContext = null; |
| 12940 | final long identity = Binder.clearCallingIdentity(); |
| 12941 | try { |
| 12942 | mainUser = mUserManager.getMainUser(); |
| 12943 | userContext = context.createContextAsUser(mainUser, 0); |
| 12944 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12945 | } finally { |
| 12946 | Binder.restoreCallingIdentity(identity); |
| 12947 | } |
| 12948 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12949 | updateIfNeeded, mainUser); |
| 12950 | } else { |
| 12951 | UserHandle userHandle = null; |
| 12952 | final long identity = Binder.clearCallingIdentity(); |
| 12953 | try { |
| 12954 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12955 | } finally { |
| 12956 | Binder.restoreCallingIdentity(identity); |
| 12957 | } |
| 12958 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12959 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12960 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12961 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12962 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12963 | |
| 12964 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12965 | * Set whether the device is able to connect with null ciphering or integrity |
| 12966 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12967 | * and all new subscriptions after this. |
| 12968 | * |
| 12969 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12970 | * @hide |
| 12971 | */ |
| 12972 | @Override |
| 12973 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12974 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12975 | enforceModifyPermission(); |
| 12976 | checkForNullCipherAndIntegritySupport(); |
| 12977 | |
| 12978 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12979 | // for listening to these preference changes and applying them immediately. |
| 12980 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12981 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12982 | editor.apply(); |
| 12983 | |
| 12984 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12985 | phone.handleNullCipherEnabledChange(); |
| 12986 | } |
| 12987 | } |
| 12988 | |
| 12989 | |
| 12990 | /** |
| 12991 | * Get whether the device is able to connect with null ciphering or integrity |
| 12992 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12993 | * the state of the radio. |
| 12994 | * |
| 12995 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12996 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12997 | * version for this feature. |
| 12998 | * @hide |
| 12999 | */ |
| 13000 | @Override |
| 13001 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 13002 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 13003 | enforceReadPermission(); |
| 13004 | checkForNullCipherAndIntegritySupport(); |
| 13005 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 13006 | } |
| 13007 | |
| 13008 | private void checkForNullCipherAndIntegritySupport() { |
| 13009 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 13010 | throw new UnsupportedOperationException( |
| 13011 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 13012 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 13013 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 13014 | throw new UnsupportedOperationException( |
| 13015 | "Null cipher and integrity operations unsupported by modem"); |
| 13016 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 13017 | } |
| 13018 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13019 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 13020 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 13021 | throw new UnsupportedOperationException( |
| 13022 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 13023 | + "above"); |
| 13024 | } |
| 13025 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 13026 | throw new UnsupportedOperationException( |
| 13027 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 13028 | } |
| 13029 | } |
| 13030 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13031 | private void checkForNullCipherNotificationSupport() { |
| 13032 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 13033 | throw new UnsupportedOperationException( |
| 13034 | "Null cipher notification operations require HAL 2.2 or above"); |
| 13035 | } |
| 13036 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 13037 | throw new UnsupportedOperationException( |
| 13038 | "Null cipher notification operations unsupported by modem"); |
| 13039 | } |
| 13040 | } |
| 13041 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 13042 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13043 | * Get the SIM state for the slot index. |
| 13044 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 13045 | * |
| 13046 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 13047 | */ |
| 13048 | @Override |
| 13049 | @SimState |
| 13050 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 13051 | if (!mApp.getResources().getBoolean( |
| 13052 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 13053 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13054 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13055 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13056 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13057 | IccCardConstants.State simState; |
| 13058 | if (slotIndex < 0) { |
| 13059 | simState = IccCardConstants.State.UNKNOWN; |
| 13060 | } else { |
| 13061 | Phone phone = null; |
| 13062 | try { |
| 13063 | phone = PhoneFactory.getPhone(slotIndex); |
| 13064 | } catch (IllegalStateException e) { |
| 13065 | // ignore |
| 13066 | } |
| 13067 | if (phone == null) { |
| 13068 | simState = IccCardConstants.State.UNKNOWN; |
| 13069 | } else { |
| 13070 | IccCard icc = phone.getIccCard(); |
| 13071 | if (icc == null) { |
| 13072 | simState = IccCardConstants.State.UNKNOWN; |
| 13073 | } else { |
| 13074 | simState = icc.getState(); |
| 13075 | } |
| 13076 | } |
| 13077 | } |
| 13078 | return simState.ordinal(); |
| 13079 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13080 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13081 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13082 | boolean enableLogcat, |
| 13083 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13084 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13085 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13086 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13087 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13088 | ecdDataBuilder |
| 13089 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13090 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13091 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13092 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13093 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13094 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13095 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13096 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13097 | Executors.newCachedThreadPool(), db, |
| 13098 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13099 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13100 | } |
| 13101 | |
| 13102 | /** |
| 13103 | * Request telephony to persist state for debugging emergency call failures. |
| 13104 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13105 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13106 | * @param enableLogcat whether to collect logcat output |
| 13107 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13108 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13109 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13110 | */ |
| 13111 | @Override |
| 13112 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13113 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13114 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13115 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13116 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13117 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13118 | && Flags.enableReadDropboxPermission()) { |
| 13119 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13120 | "persistEmergencyCallDiagnosticData"); |
| 13121 | } else { |
| 13122 | // Otherwise, enforce legacy permission. |
| 13123 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13124 | "persistEmergencyCallDiagnosticData"); |
| 13125 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13126 | final long identity = Binder.clearCallingIdentity(); |
| 13127 | try { |
| 13128 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13129 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13130 | |
| 13131 | } finally { |
| 13132 | Binder.restoreCallingIdentity(identity); |
| 13133 | } |
| 13134 | } |
| 13135 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13136 | /** |
| 13137 | * Get current cell broadcast ranges. |
| 13138 | */ |
| 13139 | @Override |
| 13140 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13141 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13142 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13143 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13144 | |
| 13145 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13146 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13147 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13148 | final long identity = Binder.clearCallingIdentity(); |
| 13149 | try { |
| 13150 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13151 | } finally { |
| 13152 | Binder.restoreCallingIdentity(identity); |
| 13153 | } |
| 13154 | } |
| 13155 | |
| 13156 | /** |
| 13157 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13158 | * |
| 13159 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13160 | */ |
| 13161 | @Override |
| 13162 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13163 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13164 | @Nullable IIntegerConsumer callback) { |
| 13165 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13166 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13167 | |
| 13168 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13169 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13170 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13171 | final long identity = Binder.clearCallingIdentity(); |
| 13172 | try { |
| 13173 | Phone phone = getPhoneFromSubId(subId); |
| 13174 | if (DBG) { |
| 13175 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13176 | } |
| 13177 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13178 | if (callback != null) { |
| 13179 | try { |
| 13180 | callback.accept(result); |
| 13181 | } catch (RemoteException e) { |
| 13182 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13183 | } |
| 13184 | } |
| 13185 | }); |
| 13186 | } finally { |
| 13187 | Binder.restoreCallingIdentity(identity); |
| 13188 | } |
| 13189 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13190 | |
| 13191 | /** |
| 13192 | * Returns whether the device supports the domain selection service. |
| 13193 | * |
| 13194 | * @return {@code true} if the device supports the domain selection service. |
| 13195 | */ |
| 13196 | @Override |
| 13197 | public boolean isDomainSelectionSupported() { |
| 13198 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13199 | "isDomainSelectionSupported"); |
| 13200 | |
| 13201 | final long identity = Binder.clearCallingIdentity(); |
| 13202 | try { |
| 13203 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13204 | } finally { |
| 13205 | Binder.restoreCallingIdentity(identity); |
| 13206 | } |
| 13207 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13208 | |
| 13209 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13210 | * Returns whether the AOSP domain selection service is supported. |
| 13211 | * |
| 13212 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13213 | * {@code false} otherwise. |
| 13214 | */ |
| 13215 | @Override |
| 13216 | public boolean isAospDomainSelectionService() { |
| 13217 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13218 | "isAospDomainSelectionService"); |
| 13219 | |
| 13220 | final long identity = Binder.clearCallingIdentity(); |
| 13221 | try { |
| 13222 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13223 | String dssComponentName = mApp.getResources().getString( |
| 13224 | R.string.config_domain_selection_service_component_name); |
| 13225 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13226 | TelephonyDomainSelectionService.class.getName()); |
| 13227 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13228 | + ", aosp=" + componentName.flattenToString()); |
| 13229 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13230 | } |
| 13231 | } finally { |
| 13232 | Binder.restoreCallingIdentity(identity); |
| 13233 | } |
| 13234 | return false; |
| 13235 | } |
| 13236 | |
| 13237 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13238 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13239 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13240 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13241 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13242 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13243 | * {@code false} to disable. |
| 13244 | * @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] | 13245 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13246 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13247 | * |
| 13248 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13249 | */ |
| 13250 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13251 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13252 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13253 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13254 | final long identity = Binder.clearCallingIdentity(); |
| 13255 | try { |
| 13256 | if (enableSatellite) { |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13257 | String caller = "PIM:requestSatelliteEnabled"; |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13258 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13259 | @Override |
| 13260 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13261 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13262 | + ", resultData=" + resultData); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13263 | mSatelliteController.decrementResultReceiverCount(caller); |
| 13264 | |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13265 | boolean isAllowed = false; |
| 13266 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13267 | callback::accept); |
| 13268 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13269 | if (resultData != null |
| 13270 | && resultData.containsKey( |
| 13271 | KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13272 | isAllowed = resultData.getBoolean( |
| 13273 | KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13274 | } else { |
| 13275 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13276 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13277 | } else { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13278 | result.accept(resultCode); |
| 13279 | return; |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13280 | } |
Sangyun Yun | 8bb6645 | 2024-11-25 15:46:10 +0000 | [diff] [blame] | 13281 | List<Integer> disallowedReasons = |
| 13282 | mSatelliteAccessController.getSatelliteDisallowedReasons(); |
| 13283 | if (disallowedReasons.stream().anyMatch(r -> |
| 13284 | (r == SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP |
| 13285 | || r == SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED |
| 13286 | || r == SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED))) { |
| 13287 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13288 | return; |
| 13289 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13290 | if (isAllowed) { |
Thomas Nguyen | dd8e083 | 2024-11-01 00:18:58 +0000 | [diff] [blame] | 13291 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13292 | @Override |
| 13293 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13294 | Log.d(LOG_TAG, "updateSystemSelectionChannels resultCode=" |
| 13295 | + resultCode); |
| 13296 | mSatelliteController.requestSatelliteEnabled( |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13297 | enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | dd8e083 | 2024-11-01 00:18:58 +0000 | [diff] [blame] | 13298 | } |
| 13299 | }; |
| 13300 | mSatelliteAccessController.updateSystemSelectionChannels( |
| 13301 | resultReceiver); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13302 | } else { |
| 13303 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13304 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13305 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13306 | }; |
| 13307 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
| 13308 | resultReceiver, true); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13309 | mSatelliteController.incrementResultReceiverCount(caller); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13310 | } else { |
| 13311 | // No need to check if satellite is allowed at current location when disabling |
| 13312 | // satellite |
| 13313 | mSatelliteController.requestSatelliteEnabled( |
| 13314 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13315 | } |
| 13316 | } finally { |
| 13317 | Binder.restoreCallingIdentity(identity); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13318 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13319 | } |
| 13320 | |
| 13321 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13322 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13323 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13324 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13325 | * 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] | 13326 | * |
| 13327 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13328 | */ |
| 13329 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13330 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13331 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13332 | final long identity = Binder.clearCallingIdentity(); |
| 13333 | try { |
| 13334 | mSatelliteController.requestIsSatelliteEnabled(result); |
| 13335 | } finally { |
| 13336 | Binder.restoreCallingIdentity(identity); |
| 13337 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13341 | * Request to get whether the satellite service demo mode is enabled. |
| 13342 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13343 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13344 | * if the request is successful or an error code if the request failed. |
| 13345 | * |
| 13346 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13347 | */ |
| 13348 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13349 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13350 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13351 | final long identity = Binder.clearCallingIdentity(); |
| 13352 | try { |
| 13353 | mSatelliteController.requestIsDemoModeEnabled(result); |
| 13354 | } finally { |
| 13355 | Binder.restoreCallingIdentity(identity); |
| 13356 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13357 | } |
| 13358 | |
| 13359 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13360 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13361 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13362 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13363 | * enabled if the request is successful or an error code if the request failed. |
| 13364 | * |
| 13365 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13366 | */ |
| 13367 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13368 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13369 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13370 | final long identity = Binder.clearCallingIdentity(); |
| 13371 | try { |
| 13372 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
| 13373 | } finally { |
| 13374 | Binder.restoreCallingIdentity(identity); |
| 13375 | } |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13376 | } |
| 13377 | |
| 13378 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13379 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13380 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13381 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13382 | * the device 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] | 13383 | */ |
| 13384 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13385 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13386 | final long identity = Binder.clearCallingIdentity(); |
| 13387 | try { |
| 13388 | mSatelliteController.requestIsSatelliteSupported(result); |
| 13389 | } finally { |
| 13390 | Binder.restoreCallingIdentity(identity); |
| 13391 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13392 | } |
| 13393 | |
| 13394 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13395 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13396 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13397 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13398 | * 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] | 13399 | * |
| 13400 | * @throws SecurityException if the caller doesn't have required permission. |
| 13401 | */ |
| 13402 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13403 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13404 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13405 | final long identity = Binder.clearCallingIdentity(); |
| 13406 | try { |
| 13407 | mSatelliteController.requestSatelliteCapabilities(result); |
| 13408 | } finally { |
| 13409 | Binder.restoreCallingIdentity(identity); |
| 13410 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13411 | } |
| 13412 | |
| 13413 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13414 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13415 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13416 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13417 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13418 | * @param resultCallback The callback to get the result of the request. |
| 13419 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13420 | * |
| 13421 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13422 | */ |
| 13423 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13424 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13425 | @NonNull IIntegerConsumer resultCallback, |
| 13426 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13427 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13428 | final long identity = Binder.clearCallingIdentity(); |
| 13429 | try { |
| 13430 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
| 13431 | } finally { |
| 13432 | Binder.restoreCallingIdentity(identity); |
| 13433 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13434 | } |
| 13435 | |
| 13436 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13437 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13438 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13439 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13440 | * @param resultCallback The callback to get the result of the request. |
| 13441 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13442 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13443 | * |
| 13444 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13445 | */ |
| 13446 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13447 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13448 | @NonNull IIntegerConsumer resultCallback, |
| 13449 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13450 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13451 | final long identity = Binder.clearCallingIdentity(); |
| 13452 | try { |
| 13453 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
| 13454 | } finally { |
| 13455 | Binder.restoreCallingIdentity(identity); |
| 13456 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13457 | } |
| 13458 | |
| 13459 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13460 | * Register the subscription with a satellite provider. |
| 13461 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13462 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13463 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13464 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13465 | * @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] | 13466 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13467 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13468 | * @return The signal transport used by the caller to cancel the provision request, |
| 13469 | * or {@code null} if the request failed. |
| 13470 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13471 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13472 | */ |
| 13473 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13474 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13475 | @NonNull String token, @NonNull byte[] provisionData, |
| 13476 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13477 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13478 | final long identity = Binder.clearCallingIdentity(); |
| 13479 | try { |
| 13480 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13481 | callback); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13482 | } finally { |
| 13483 | Binder.restoreCallingIdentity(identity); |
| 13484 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13485 | } |
| 13486 | |
| 13487 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13488 | * Unregister the device/subscription with the satellite provider. |
| 13489 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13490 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13491 | * should report as deprovisioned. |
| 13492 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13493 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13494 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13495 | * |
| 13496 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13497 | */ |
| 13498 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13499 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13500 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13501 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13502 | final long identity = Binder.clearCallingIdentity(); |
| 13503 | try { |
| 13504 | mSatelliteController.deprovisionSatelliteService(token, callback); |
| 13505 | } finally { |
| 13506 | Binder.restoreCallingIdentity(identity); |
| 13507 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13508 | } |
| 13509 | |
| 13510 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13511 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13512 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13513 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13514 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13515 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13516 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13517 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13518 | */ |
| 13519 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13520 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13521 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13522 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13523 | final long identity = Binder.clearCallingIdentity(); |
| 13524 | try { |
| 13525 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
| 13526 | } finally { |
| 13527 | Binder.restoreCallingIdentity(identity); |
| 13528 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13529 | } |
| 13530 | |
| 13531 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13532 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13533 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13534 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13535 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13536 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13537 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13538 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13539 | */ |
| 13540 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13541 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13542 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13543 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13544 | final long identity = Binder.clearCallingIdentity(); |
| 13545 | try { |
| 13546 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
| 13547 | } finally { |
| 13548 | Binder.restoreCallingIdentity(identity); |
| 13549 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13550 | } |
| 13551 | |
| 13552 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13553 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13554 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13555 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13556 | * satellite provider if the request is successful or an error code if the |
| 13557 | * request failed. |
| 13558 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [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 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13563 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13564 | final long identity = Binder.clearCallingIdentity(); |
| 13565 | try { |
| 13566 | mSatelliteController.requestIsSatelliteProvisioned(result); |
| 13567 | } finally { |
| 13568 | Binder.restoreCallingIdentity(identity); |
| 13569 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13570 | } |
| 13571 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13572 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13573 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13574 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13575 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13576 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13577 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13578 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13579 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13580 | */ |
| 13581 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13582 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13583 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13584 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13585 | final long identity = Binder.clearCallingIdentity(); |
| 13586 | try { |
| 13587 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
| 13588 | } finally { |
| 13589 | Binder.restoreCallingIdentity(identity); |
| 13590 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13591 | } |
| 13592 | |
| 13593 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13594 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13595 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13596 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13597 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13598 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13599 | * |
| 13600 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13601 | */ |
| 13602 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13603 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13604 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13605 | final long identity = Binder.clearCallingIdentity(); |
| 13606 | try { |
| 13607 | mSatelliteController.unregisterForModemStateChanged(callback); |
| 13608 | } finally { |
| 13609 | Binder.restoreCallingIdentity(identity); |
| 13610 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13611 | } |
| 13612 | |
| 13613 | /** |
| 13614 | * Register to receive incoming datagrams over satellite. |
| 13615 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13616 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13617 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13618 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13619 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13620 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13621 | */ |
| 13622 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13623 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13624 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13625 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13626 | final long identity = Binder.clearCallingIdentity(); |
| 13627 | try { |
| 13628 | return mSatelliteController.registerForIncomingDatagram(callback); |
| 13629 | } finally { |
| 13630 | Binder.restoreCallingIdentity(identity); |
| 13631 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13632 | } |
| 13633 | |
| 13634 | /** |
| 13635 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13636 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13637 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13638 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13639 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13640 | * |
| 13641 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13642 | */ |
| 13643 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13644 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13645 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13646 | final long identity = Binder.clearCallingIdentity(); |
| 13647 | try { |
| 13648 | mSatelliteController.unregisterForIncomingDatagram(callback); |
| 13649 | } finally { |
| 13650 | Binder.restoreCallingIdentity(identity); |
| 13651 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13652 | } |
| 13653 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13654 | /** |
| 13655 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13656 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13657 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13658 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13659 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13660 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13661 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13662 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13663 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13664 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13665 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13666 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13667 | final long identity = Binder.clearCallingIdentity(); |
| 13668 | try { |
| 13669 | mSatelliteController.pollPendingDatagrams(callback); |
| 13670 | } finally { |
| 13671 | Binder.restoreCallingIdentity(identity); |
| 13672 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13673 | } |
| 13674 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13675 | /** |
| 13676 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13677 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13678 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13679 | * input to this method. Datagram received here will be passed down to modem without any |
| 13680 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13681 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13682 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13683 | * SOS_SMS or LOCATION_SHARING. |
| 13684 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13685 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13686 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13687 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13688 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13689 | * |
| 13690 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13691 | */ |
| 13692 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13693 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13694 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13695 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13696 | enforceSatelliteCommunicationPermission("sendDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13697 | final long identity = Binder.clearCallingIdentity(); |
| 13698 | try { |
| 13699 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
| 13700 | callback); |
| 13701 | } finally { |
| 13702 | Binder.restoreCallingIdentity(identity); |
| 13703 | } |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13704 | } |
| 13705 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13706 | /** |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13707 | * Returns integer array of disallowed reasons of satellite. |
| 13708 | * |
| 13709 | * @return Integer array of disallowed reasons of satellite. |
| 13710 | * |
| 13711 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13712 | */ |
| 13713 | @NonNull public int[] getSatelliteDisallowedReasons() { |
| 13714 | enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons"); |
| 13715 | final long identity = Binder.clearCallingIdentity(); |
| 13716 | try { |
| 13717 | return mSatelliteAccessController.getSatelliteDisallowedReasons() |
| 13718 | .stream().mapToInt(Integer::intValue).toArray(); |
| 13719 | } finally { |
| 13720 | Binder.restoreCallingIdentity(identity); |
| 13721 | } |
| 13722 | } |
| 13723 | |
| 13724 | /** |
| 13725 | * Registers for disallowed reasons change event from satellite service. |
| 13726 | * |
| 13727 | * @param callback The callback to handle disallowed reasons changed event. |
| 13728 | * |
| 13729 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13730 | */ |
| 13731 | @Override |
| 13732 | public void registerForSatelliteDisallowedReasonsChanged( |
| 13733 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13734 | enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged"); |
| 13735 | final long identity = Binder.clearCallingIdentity(); |
| 13736 | try { |
| 13737 | mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback); |
| 13738 | } finally { |
| 13739 | Binder.restoreCallingIdentity(identity); |
| 13740 | } |
| 13741 | } |
| 13742 | |
| 13743 | /** |
| 13744 | * Unregisters for disallowed reasons change event from satellite service. |
| 13745 | * If callback was not registered before, the request will be ignored. |
| 13746 | * |
| 13747 | * @param callback The callback to handle disallowed reasons changed event. |
| 13748 | * {@link #registerForSatelliteDisallowedReasonsChanged( |
| 13749 | * ISatelliteDisallowedReasonsCallback)}. |
| 13750 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13751 | */ |
| 13752 | @Override |
| 13753 | public void unregisterForSatelliteDisallowedReasonsChanged( |
| 13754 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13755 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged"); |
| 13756 | final long identity = Binder.clearCallingIdentity(); |
| 13757 | try { |
| 13758 | mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback); |
| 13759 | } finally { |
| 13760 | Binder.restoreCallingIdentity(identity); |
| 13761 | } |
| 13762 | } |
| 13763 | |
| 13764 | /** |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13765 | * Request to get whether satellite communication is allowed for the current location. |
| 13766 | * |
| 13767 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13768 | * allowed for the current location for. |
| 13769 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13770 | * for the current location if the request is successful or an error code |
| 13771 | * if the request failed. |
| 13772 | * |
| 13773 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13774 | */ |
| 13775 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13776 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13777 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13778 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13779 | final long identity = Binder.clearCallingIdentity(); |
| 13780 | try { |
| 13781 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, |
| 13782 | false); |
| 13783 | } finally { |
| 13784 | Binder.restoreCallingIdentity(identity); |
| 13785 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13786 | } |
| 13787 | |
| 13788 | /** |
youngtaecha | edc8a1c | 2024-10-15 09:07:25 +0000 | [diff] [blame] | 13789 | * Request to get satellite access configuration for the current location. |
| 13790 | * |
| 13791 | * @param result The result receiver that returns the satellite access configuration |
| 13792 | * for the current location if the request is successful or an error code |
| 13793 | * if the request failed. |
| 13794 | * |
| 13795 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13796 | */ |
| 13797 | @Override |
| 13798 | public void requestSatelliteAccessConfigurationForCurrentLocation( |
| 13799 | @NonNull ResultReceiver result) { |
| 13800 | enforceSatelliteCommunicationPermission( |
| 13801 | "requestSatelliteAccessConfigurationForCurrentLocation"); |
| 13802 | final long identity = Binder.clearCallingIdentity(); |
| 13803 | try { |
| 13804 | mSatelliteAccessController |
| 13805 | .requestSatelliteAccessConfigurationForCurrentLocation(result); |
| 13806 | } finally { |
| 13807 | Binder.restoreCallingIdentity(identity); |
| 13808 | } |
| 13809 | } |
| 13810 | |
| 13811 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13812 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13813 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13814 | * @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] | 13815 | * be visible if the request is successful or an error code if the request failed. |
| 13816 | * |
| 13817 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13818 | */ |
| 13819 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13820 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13821 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13822 | final long identity = Binder.clearCallingIdentity(); |
| 13823 | try { |
| 13824 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
| 13825 | } finally { |
| 13826 | Binder.restoreCallingIdentity(identity); |
| 13827 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13828 | } |
| 13829 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13830 | /** |
Adrian | 8e30ad0 | 2024-11-21 17:22:29 +0000 | [diff] [blame] | 13831 | * Request to get the name to display for Satellite subscription. |
| 13832 | * |
| 13833 | * @param result The result receiver that returns the display name to use for satellite feature |
| 13834 | * in the UI for current satellite subscription if the request is successful, |
| 13835 | * or an error code if the request failed. |
| 13836 | * |
| 13837 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13838 | */ |
| 13839 | @Override |
| 13840 | public void requestSatelliteDisplayName(@NonNull ResultReceiver result) { |
| 13841 | enforceSatelliteCommunicationPermission("requestSatelliteDisplayName"); |
| 13842 | final long identity = Binder.clearCallingIdentity(); |
| 13843 | try { |
| 13844 | mSatelliteController.requestSatelliteDisplayName(result); |
| 13845 | } finally { |
| 13846 | Binder.restoreCallingIdentity(identity); |
| 13847 | } |
| 13848 | } |
| 13849 | |
| 13850 | /** |
Daniel Banta | 99cc753 | 2024-11-15 02:31:08 +0000 | [diff] [blame] | 13851 | * Request to get the currently selected satellite subscription id. |
| 13852 | * |
| 13853 | * @param result The result receiver that returns the currently selected satellite subscription |
| 13854 | * id if the request is successful or an error code if the request failed. |
| 13855 | * |
| 13856 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13857 | */ |
| 13858 | @Override |
| 13859 | public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) { |
| 13860 | enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId"); |
| 13861 | final long identity = Binder.clearCallingIdentity(); |
| 13862 | try { |
| 13863 | mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result); |
| 13864 | } finally { |
| 13865 | Binder.restoreCallingIdentity(identity); |
| 13866 | } |
| 13867 | } |
| 13868 | |
| 13869 | /** |
Daniel Banta | 9332024 | 2024-11-21 00:34:41 +0000 | [diff] [blame] | 13870 | * Registers for selected satellite subscription changed event from the satellite service. |
| 13871 | * |
| 13872 | * @param callback The callback to handle the satellite subscription changed event. |
| 13873 | * |
| 13874 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13875 | * |
| 13876 | * @throws SecurityException if the caller doesn't have required permission. |
| 13877 | */ |
| 13878 | @Override |
| 13879 | @SatelliteManager.SatelliteResult |
| 13880 | public int registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13881 | @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) { |
| 13882 | enforceSatelliteCommunicationPermission( |
| 13883 | "registerForSelectedNbIotSatelliteSubscriptionChanged"); |
| 13884 | final long identity = Binder.clearCallingIdentity(); |
| 13885 | try { |
| 13886 | return mSatelliteController.registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13887 | callback); |
| 13888 | } finally { |
| 13889 | Binder.restoreCallingIdentity(identity); |
| 13890 | } |
| 13891 | } |
| 13892 | |
| 13893 | /** |
| 13894 | * Unregisters for selected satellite subscription changed event from the satellite service. |
| 13895 | * If callback was not registered before, the request will be ignored. |
| 13896 | * |
| 13897 | * @param callback The callback that was passed to {@link |
| 13898 | * #registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13899 | * ISelectedNbIotSatelliteSubscriptionCallback)}. |
| 13900 | * |
| 13901 | * @throws SecurityException if the caller doesn't have required permission. |
| 13902 | */ |
| 13903 | @Override |
| 13904 | public void unregisterForSelectedNbIotSatelliteSubscriptionChanged( |
| 13905 | @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) { |
| 13906 | enforceSatelliteCommunicationPermission( |
| 13907 | "unregisterForSelectedNbIotSatelliteSubscriptionChanged"); |
| 13908 | final long identity = Binder.clearCallingIdentity(); |
| 13909 | try { |
| 13910 | mSatelliteController.unregisterForSelectedNbIotSatelliteSubscriptionChanged( |
| 13911 | callback); |
| 13912 | } finally { |
| 13913 | Binder.restoreCallingIdentity(identity); |
| 13914 | } |
| 13915 | } |
| 13916 | |
| 13917 | /** |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13918 | * 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] | 13919 | * |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13920 | * @param isAligned {@code true} Device is aligned with the satellite. |
| 13921 | * {@code false} Device fails to align with the satellite. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13922 | * |
| 13923 | * @throws SecurityException if the caller doesn't have required permission. |
| 13924 | */ |
| 13925 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13926 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13927 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13928 | enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite"); |
| 13929 | final long identity = Binder.clearCallingIdentity(); |
| 13930 | try { |
| 13931 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
| 13932 | } finally { |
| 13933 | Binder.restoreCallingIdentity(identity); |
| 13934 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13935 | } |
| 13936 | |
| 13937 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13938 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13939 | * by modem. |
| 13940 | * |
| 13941 | * @param subId The subId of the subscription to request for. |
| 13942 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13943 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13944 | * operation. |
| 13945 | * |
| 13946 | * @throws SecurityException if the caller doesn't have required permission. |
| 13947 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13948 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13949 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13950 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13951 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13952 | final long identity = Binder.clearCallingIdentity(); |
| 13953 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13954 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13955 | } finally { |
| 13956 | Binder.restoreCallingIdentity(identity); |
| 13957 | } |
| 13958 | } |
| 13959 | |
| 13960 | /** |
| 13961 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13962 | * by modem. |
| 13963 | * |
| 13964 | * @param subId The subId of the subscription to request for. |
| 13965 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13966 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13967 | * operation. |
| 13968 | * |
| 13969 | * @throws SecurityException if the caller doesn't have required permission. |
| 13970 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13971 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13972 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13973 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13974 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13975 | final long identity = Binder.clearCallingIdentity(); |
| 13976 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13977 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13978 | } finally { |
| 13979 | Binder.restoreCallingIdentity(identity); |
| 13980 | } |
| 13981 | } |
| 13982 | |
| 13983 | /** |
| 13984 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13985 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13986 | * |
| 13987 | * @param subId The subId of the subscription to request for. |
| 13988 | * |
| 13989 | * @return Integer array of reasons for disallowing satellite communication. |
| 13990 | * |
| 13991 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13992 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13993 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13994 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13995 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13996 | final long identity = Binder.clearCallingIdentity(); |
| 13997 | try { |
| 13998 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13999 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 14000 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 14001 | } finally { |
| 14002 | Binder.restoreCallingIdentity(identity); |
| 14003 | } |
| 14004 | } |
| 14005 | |
| 14006 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14007 | * Request to get the signal strength of the satellite connection. |
| 14008 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14009 | * @param result Result receiver to get the error code of the request and the current signal |
| 14010 | * strength of the satellite connection. |
| 14011 | * |
| 14012 | * @throws SecurityException if the caller doesn't have required permission. |
| 14013 | */ |
| 14014 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14015 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14016 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 14017 | final long identity = Binder.clearCallingIdentity(); |
| 14018 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14019 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14020 | } finally { |
| 14021 | Binder.restoreCallingIdentity(identity); |
| 14022 | } |
| 14023 | } |
| 14024 | |
| 14025 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 14026 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 14027 | * is not successful, a {@link ServiceSpecificException} that contains |
| 14028 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14029 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 14030 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 14031 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 14032 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 14033 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 14034 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14035 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 14036 | * @throws SecurityException If the caller doesn't have the required permission. |
| 14037 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14038 | */ |
| 14039 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14040 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 14041 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14042 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 14043 | final long identity = Binder.clearCallingIdentity(); |
| 14044 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14045 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14046 | } finally { |
| 14047 | Binder.restoreCallingIdentity(identity); |
| 14048 | } |
| 14049 | } |
| 14050 | |
| 14051 | /** |
| 14052 | * Unregisters for NTN signal strength changed from satellite modem. |
| 14053 | * If callback was not registered before, the request will be ignored. |
| 14054 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14055 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14056 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14057 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14058 | * |
| 14059 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14060 | */ |
| 14061 | @Override |
| 14062 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14063 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14064 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 14065 | final long identity = Binder.clearCallingIdentity(); |
| 14066 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14067 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14068 | } finally { |
| 14069 | Binder.restoreCallingIdentity(identity); |
| 14070 | } |
| 14071 | } |
| 14072 | |
| 14073 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14074 | * Registers for satellite capabilities change event from the satellite service. |
| 14075 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14076 | * @param callback The callback to handle the satellite capabilities changed event. |
| 14077 | * |
| 14078 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14079 | * |
| 14080 | * @throws SecurityException if the caller doesn't have required permission. |
| 14081 | */ |
| 14082 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14083 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14084 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14085 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14086 | final long identity = Binder.clearCallingIdentity(); |
| 14087 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14088 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14089 | } finally { |
| 14090 | Binder.restoreCallingIdentity(identity); |
| 14091 | } |
| 14092 | } |
| 14093 | |
| 14094 | /** |
| 14095 | * Unregisters for satellite capabilities change event from the satellite service. |
| 14096 | * If callback was not registered before, the request will be ignored. |
| 14097 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14098 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14099 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14100 | * |
| 14101 | * @throws SecurityException if the caller doesn't have required permission. |
| 14102 | */ |
| 14103 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14104 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14105 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 14106 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14107 | final long identity = Binder.clearCallingIdentity(); |
| 14108 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14109 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14110 | } finally { |
| 14111 | Binder.restoreCallingIdentity(identity); |
| 14112 | } |
| 14113 | } |
| 14114 | |
| 14115 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14116 | * Registers for the satellite supported state changed. |
| 14117 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14118 | * @param callback The callback to handle the satellite supported state changed event. |
| 14119 | * |
| 14120 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14121 | * |
| 14122 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14123 | */ |
| 14124 | @Override |
| 14125 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14126 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14127 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14128 | final long identity = Binder.clearCallingIdentity(); |
| 14129 | try { |
| 14130 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
| 14131 | } finally { |
| 14132 | Binder.restoreCallingIdentity(identity); |
| 14133 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14134 | } |
| 14135 | |
| 14136 | /** |
| 14137 | * Unregisters for the satellite supported state changed. |
| 14138 | * If callback was not registered before, the request will be ignored. |
| 14139 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14140 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14141 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14142 | * |
| 14143 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14144 | */ |
| 14145 | @Override |
| 14146 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14147 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14148 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14149 | final long identity = Binder.clearCallingIdentity(); |
| 14150 | try { |
| 14151 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
| 14152 | } finally { |
| 14153 | Binder.restoreCallingIdentity(identity); |
| 14154 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14155 | } |
| 14156 | |
| 14157 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14158 | * This API can be used by only CTS to update satellite vendor service package name. |
| 14159 | * |
| 14160 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 14161 | * @param provisioned Whether satellite should be provisioned or not. |
| 14162 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14163 | * @return {@code true} if the satellite vendor service is set successfully, |
| 14164 | * {@code false} otherwise. |
| 14165 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 14166 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 14167 | String provisioned) { |
| 14168 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 14169 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14170 | TelephonyPermissions.enforceShellOnly( |
| 14171 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 14172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14173 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14174 | "setSatelliteServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14175 | final long identity = Binder.clearCallingIdentity(); |
| 14176 | try { |
| 14177 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 14178 | provisioned); |
| 14179 | } finally { |
| 14180 | Binder.restoreCallingIdentity(identity); |
| 14181 | } |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14182 | } |
| 14183 | |
| 14184 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14185 | * This API can be used by only CTS to update satellite gateway service package name. |
| 14186 | * |
| 14187 | * @param servicePackageName The package name of the satellite gateway service. |
| 14188 | * @return {@code true} if the satellite gateway service is set successfully, |
| 14189 | * {@code false} otherwise. |
| 14190 | */ |
| 14191 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 14192 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 14193 | TelephonyPermissions.enforceShellOnly( |
| 14194 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 14195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14196 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14197 | "setSatelliteGatewayServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14198 | final long identity = Binder.clearCallingIdentity(); |
| 14199 | try { |
| 14200 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 14201 | } finally { |
| 14202 | Binder.restoreCallingIdentity(identity); |
| 14203 | } |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14204 | } |
| 14205 | |
| 14206 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14207 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 14208 | * |
| 14209 | * @param packageName The package name of the satellite pointing UI app. |
| 14210 | * @param className The class name of the satellite pointing UI app. |
| 14211 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 14212 | * {@code false} otherwise. |
| 14213 | */ |
| 14214 | public boolean setSatellitePointingUiClassName( |
| 14215 | @Nullable String packageName, @Nullable String className) { |
| 14216 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 14217 | + ", className=" + className); |
| 14218 | TelephonyPermissions.enforceShellOnly( |
| 14219 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 14220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14221 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14222 | "setSatellitePointingUiClassName"); |
| 14223 | final long identity = Binder.clearCallingIdentity(); |
| 14224 | try { |
| 14225 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 14226 | } finally { |
| 14227 | Binder.restoreCallingIdentity(identity); |
| 14228 | } |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14229 | } |
| 14230 | |
| 14231 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14232 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 14233 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 14234 | * listening mode. |
| 14235 | * |
| 14236 | * @param timeoutMillis The timeout duration in millisecond. |
| 14237 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14238 | */ |
| 14239 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 14240 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 14241 | TelephonyPermissions.enforceShellOnly( |
| 14242 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 14243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14244 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14245 | "setSatelliteListeningTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14246 | final long identity = Binder.clearCallingIdentity(); |
| 14247 | try { |
| 14248 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 14249 | } finally { |
| 14250 | Binder.restoreCallingIdentity(identity); |
| 14251 | } |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14252 | } |
| 14253 | |
| 14254 | /** |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14255 | * This API can be used by only CTS to control ingoring cellular service state event. |
| 14256 | * |
| 14257 | * @param enabled Whether to enable boolean config. |
| 14258 | * @return {@code true} if the value is set successfully, {@code false} otherwise. |
| 14259 | */ |
| 14260 | public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14261 | Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14262 | TelephonyPermissions.enforceShellOnly( |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14263 | Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState"); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14265 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14266 | "setSatelliteIgnoreCellularServiceState"); |
| 14267 | final long identity = Binder.clearCallingIdentity(); |
| 14268 | try { |
| 14269 | return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled); |
| 14270 | } finally { |
| 14271 | Binder.restoreCallingIdentity(identity); |
| 14272 | } |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14273 | } |
| 14274 | |
| 14275 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14276 | * This API can be used by only CTS to override the timeout durations used by the |
| 14277 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14278 | * |
| 14279 | * @param timeoutMillis The timeout duration in millisecond. |
| 14280 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14281 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14282 | public boolean setDatagramControllerTimeoutDuration( |
| 14283 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14284 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14285 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14286 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14287 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14288 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14289 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14290 | "setDatagramControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14291 | final long identity = Binder.clearCallingIdentity(); |
| 14292 | try { |
| 14293 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 14294 | reset, timeoutType, timeoutMillis); |
| 14295 | } finally { |
| 14296 | Binder.restoreCallingIdentity(identity); |
| 14297 | } |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14298 | } |
| 14299 | |
| 14300 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14301 | * This API can be used by only CTS to override the boolean configs used by the |
| 14302 | * DatagramController module. |
| 14303 | * |
| 14304 | * @param enable Whether to enable or disable boolean config. |
| 14305 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 14306 | */ |
| 14307 | public boolean setDatagramControllerBooleanConfig( |
| 14308 | boolean reset, int booleanType, boolean enable) { |
| 14309 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 14310 | + ", reset=" + reset + ", enable=" + enable); |
| 14311 | TelephonyPermissions.enforceShellOnly( |
| 14312 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 14313 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14314 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14315 | "ssetDatagramControllerBooleanConfig"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14316 | final long identity = Binder.clearCallingIdentity(); |
| 14317 | try { |
| 14318 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, |
| 14319 | enable); |
| 14320 | } finally { |
| 14321 | Binder.restoreCallingIdentity(identity); |
| 14322 | } |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14323 | } |
| 14324 | |
| 14325 | |
| 14326 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14327 | * This API can be used by only CTS to override the timeout durations used by the |
| 14328 | * SatelliteController module. |
| 14329 | * |
| 14330 | * @param timeoutMillis The timeout duration in millisecond. |
| 14331 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14332 | */ |
| 14333 | public boolean setSatelliteControllerTimeoutDuration( |
| 14334 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14335 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14336 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 14337 | TelephonyPermissions.enforceShellOnly( |
| 14338 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 14339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14340 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14341 | "setSatelliteControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14342 | final long identity = Binder.clearCallingIdentity(); |
| 14343 | try { |
| 14344 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 14345 | reset, timeoutType, timeoutMillis); |
| 14346 | } finally { |
| 14347 | Binder.restoreCallingIdentity(identity); |
| 14348 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14349 | } |
| 14350 | |
| 14351 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14352 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 14353 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 14354 | * |
| 14355 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 14356 | * of the following values to enable the override: |
| 14357 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 14358 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 14359 | * To disable the override, use -1 for handoverType. |
| 14360 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 14361 | * delaySeconds after the emergency call starts. |
| 14362 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 14363 | */ |
| 14364 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 14365 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 14366 | TelephonyPermissions.enforceShellOnly( |
| 14367 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 14368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14369 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14370 | "setEmergencyCallToSatelliteHandoverType"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14371 | final long identity = Binder.clearCallingIdentity(); |
| 14372 | try { |
| 14373 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 14374 | handoverType, delaySeconds); |
| 14375 | } finally { |
| 14376 | Binder.restoreCallingIdentity(identity); |
| 14377 | } |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14378 | } |
| 14379 | |
| 14380 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14381 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 14382 | * |
| 14383 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 14384 | * otherwise. |
| 14385 | * @param isProvisioned The overriding provision status. |
| 14386 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 14387 | */ |
| 14388 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 14389 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 14390 | + ", isProvisioned=" + isProvisioned); |
| 14391 | TelephonyPermissions.enforceShellOnly( |
| 14392 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 14393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14394 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14395 | "setOemEnabledSatelliteProvisionStatus"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14396 | final long identity = Binder.clearCallingIdentity(); |
| 14397 | try { |
| 14398 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 14399 | } finally { |
| 14400 | Binder.restoreCallingIdentity(identity); |
| 14401 | } |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14402 | } |
| 14403 | |
| 14404 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14405 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 14406 | * |
| 14407 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 14408 | */ |
| 14409 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 14410 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 14411 | long locationCountryCodeTimestampNanos) { |
| 14412 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 14413 | + String.join(", ", currentNetworkCountryCodes) |
| 14414 | + ", locationCountryCode=" + locationCountryCode |
| 14415 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 14416 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 14417 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14418 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14419 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14420 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes"); |
| 14421 | final long identity = Binder.clearCallingIdentity(); |
| 14422 | try { |
| 14423 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), |
| 14424 | mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes, |
| 14425 | cachedNetworkCountryCodes, locationCountryCode, |
| 14426 | locationCountryCodeTimestampNanos); |
| 14427 | } finally { |
| 14428 | Binder.restoreCallingIdentity(identity); |
| 14429 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14430 | } |
| 14431 | |
| 14432 | /** |
| 14433 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 14434 | * access controller. |
| 14435 | * |
| 14436 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 14437 | * otherwise. |
| 14438 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 14439 | */ |
| 14440 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14441 | String s2CellFile, long locationFreshDurationNanos, |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14442 | List<String> satelliteCountryCodes, String satelliteAccessConfigurationFile) { |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14443 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14444 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14445 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14446 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14447 | ? String.join(", ", satelliteCountryCodes) : null) |
| 14448 | + ", satelliteAccessConfigurationFile=" + satelliteAccessConfigurationFile); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14449 | TelephonyPermissions.enforceShellOnly( |
| 14450 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14452 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14453 | "setSatelliteAccessControlOverlayConfigs"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14454 | final long identity = Binder.clearCallingIdentity(); |
| 14455 | try { |
| 14456 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14457 | isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes, |
| 14458 | satelliteAccessConfigurationFile); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14459 | } finally { |
| 14460 | Binder.restoreCallingIdentity(identity); |
| 14461 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14462 | } |
| 14463 | |
| 14464 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14465 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14466 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14467 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14468 | * |
| 14469 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14470 | * satellite modem or not. |
| 14471 | * |
| 14472 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14473 | */ |
| 14474 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14475 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14476 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14477 | + "disabled"); |
| 14478 | return false; |
| 14479 | } |
| 14480 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14481 | TelephonyPermissions.enforceShellOnly( |
| 14482 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14484 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14485 | "setShouldSendDatagramToModemInDemoMode"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14486 | final long identity = Binder.clearCallingIdentity(); |
| 14487 | try { |
| 14488 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14489 | shouldSendToModemInDemoMode); |
| 14490 | } finally { |
| 14491 | Binder.restoreCallingIdentity(identity); |
| 14492 | } |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14493 | } |
| 14494 | |
| 14495 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14496 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14497 | * |
| 14498 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14499 | * the allowed state. |
| 14500 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14501 | */ |
| 14502 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14503 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14504 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14505 | + "oemEnabledSatelliteFlag is disabled"); |
| 14506 | return false; |
| 14507 | } |
| 14508 | |
| 14509 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14510 | + "state=" + state); |
| 14511 | TelephonyPermissions.enforceShellOnly( |
| 14512 | Binder.getCallingUid(), |
| 14513 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14514 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14515 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14516 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14517 | final long identity = Binder.clearCallingIdentity(); |
| 14518 | try { |
| 14519 | return mSatelliteAccessController |
| 14520 | .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state); |
| 14521 | } finally { |
| 14522 | Binder.restoreCallingIdentity(identity); |
| 14523 | } |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14524 | } |
| 14525 | |
| 14526 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14527 | * Sets the service defined in ComponentName to be bound. |
| 14528 | * |
| 14529 | * This should only be used for testing. |
| 14530 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14531 | * {@code false} otherwise. |
| 14532 | */ |
| 14533 | @Override |
| 14534 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14535 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14536 | |
| 14537 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14538 | "setDomainSelectionServiceOverride"); |
| 14539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14540 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14541 | |
| 14542 | final long identity = Binder.clearCallingIdentity(); |
| 14543 | try { |
| 14544 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14545 | return DomainSelectionResolver.getInstance() |
| 14546 | .setDomainSelectionServiceOverride(componentName); |
| 14547 | } |
| 14548 | } finally { |
| 14549 | Binder.restoreCallingIdentity(identity); |
| 14550 | } |
| 14551 | return false; |
| 14552 | } |
| 14553 | |
| 14554 | /** |
| 14555 | * Clears the DomainSelectionService override. |
| 14556 | * |
| 14557 | * This should only be used for testing. |
| 14558 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14559 | * {@code false} otherwise. |
| 14560 | */ |
| 14561 | @Override |
| 14562 | public boolean clearDomainSelectionServiceOverride() { |
| 14563 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14564 | |
| 14565 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14566 | "clearDomainSelectionServiceOverride"); |
| 14567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14568 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14569 | |
| 14570 | final long identity = Binder.clearCallingIdentity(); |
| 14571 | try { |
| 14572 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14573 | return DomainSelectionResolver.getInstance() |
| 14574 | .clearDomainSelectionServiceOverride(); |
| 14575 | } |
| 14576 | } finally { |
| 14577 | Binder.restoreCallingIdentity(identity); |
| 14578 | } |
| 14579 | return false; |
| 14580 | } |
| 14581 | |
| 14582 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14583 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14584 | * |
| 14585 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14586 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14587 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14588 | * |
| 14589 | * @param enable if notifications about disclosure events should be enabled |
| 14590 | * @throws SecurityException if the caller does not have the required privileges |
| 14591 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14592 | */ |
| 14593 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14594 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14595 | enforceModifyPermission(); |
| 14596 | checkForIdentifierDisclosureNotificationSupport(); |
| 14597 | |
| 14598 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14599 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14600 | editor.apply(); |
| 14601 | |
| 14602 | // Each phone instance is responsible for updating its respective modem immediately |
| 14603 | // after we've made a preference change. |
| 14604 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14605 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14606 | } |
| 14607 | } |
| 14608 | |
| 14609 | /** |
| 14610 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14611 | * |
| 14612 | * @throws SecurityException if the caller does not have the required privileges |
| 14613 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14614 | */ |
| 14615 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14616 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14617 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14618 | checkForIdentifierDisclosureNotificationSupport(); |
| 14619 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14620 | } |
| 14621 | |
| 14622 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14623 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14624 | * are in use by the cellular modem. |
| 14625 | * |
| 14626 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14627 | * @throws SecurityException if the caller does not have the required privileges |
| 14628 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14629 | * and integrity algorithms in use |
| 14630 | * @hide |
| 14631 | */ |
| 14632 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14633 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14634 | enforceModifyPermission(); |
| 14635 | checkForNullCipherNotificationSupport(); |
| 14636 | |
| 14637 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14638 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14639 | editor.apply(); |
| 14640 | |
| 14641 | // Each phone instance is responsible for updating its respective modem immediately |
| 14642 | // after a preference change. |
| 14643 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14644 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14645 | } |
| 14646 | } |
| 14647 | |
| 14648 | /** |
| 14649 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14650 | * cellular modem. |
| 14651 | * |
| 14652 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14653 | * @throws SecurityException if the caller does not have the required privileges |
| 14654 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14655 | * and integrity algorithms in use |
| 14656 | * @hide |
| 14657 | */ |
| 14658 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14659 | public boolean isNullCipherNotificationsEnabled() { |
| 14660 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14661 | checkForNullCipherNotificationSupport(); |
| 14662 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14663 | } |
| 14664 | |
| 14665 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14666 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14667 | * |
| 14668 | * <p>This method behaves in one of the following ways: |
| 14669 | * <ul> |
| 14670 | * <li>return true : if the calling package has the appop permission {@link |
| 14671 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14672 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14673 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14674 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14675 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14676 | * </ul> |
| 14677 | */ |
| 14678 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14679 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14680 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14681 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14682 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14683 | return true; |
| 14684 | } |
| 14685 | } |
| 14686 | return false; |
| 14687 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14688 | |
| 14689 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14690 | * @return The subscription manager service instance. |
| 14691 | */ |
| 14692 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14693 | return SubscriptionManagerService.getInstance(); |
| 14694 | } |
| 14695 | |
| 14696 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14697 | * Class binds the consumer[callback] and carrierId. |
| 14698 | */ |
| 14699 | private static class CallerCallbackInfo { |
| 14700 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14701 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14702 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14703 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14704 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14705 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14706 | } |
| 14707 | |
| 14708 | public Consumer<Integer> getConsumer() { |
| 14709 | return mConsumer; |
| 14710 | } |
| 14711 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14712 | public Set<Integer> getCarrierIds() { |
| 14713 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14714 | } |
| 14715 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14716 | |
| 14717 | /* |
| 14718 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14719 | * But the context that is passed in is unused if the phone app is already alive. |
| 14720 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14721 | */ |
| 14722 | @VisibleForTesting |
| 14723 | public void setPackageManager(PackageManager packageManager) { |
| 14724 | mPackageManager = packageManager; |
| 14725 | } |
| 14726 | |
| 14727 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14728 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14729 | * But the context that is passed in is unused if the phone app is already alive. |
| 14730 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14731 | */ |
| 14732 | @VisibleForTesting |
| 14733 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14734 | mAppOps = appOps; |
| 14735 | } |
| 14736 | |
| 14737 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14738 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14739 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14740 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14741 | */ |
| 14742 | @VisibleForTesting |
| 14743 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14744 | mFeatureFlags = featureFlags; |
| 14745 | } |
| 14746 | |
| 14747 | /** |
| 14748 | * Make sure the device has required telephony feature |
| 14749 | * |
| 14750 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14751 | */ |
| 14752 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14753 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14754 | if (callingPackage == null || mPackageManager == null) { |
| 14755 | return; |
| 14756 | } |
| 14757 | |
| 14758 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14759 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14760 | Binder.getCallingUserHandle()) |
| 14761 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14762 | // Skip to check associated telephony feature, |
| 14763 | // if compatibility change is not enabled for the current process or |
| 14764 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14765 | return; |
| 14766 | } |
| 14767 | |
| 14768 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14769 | throw new UnsupportedOperationException( |
| 14770 | methodName + " is unsupported without " + telephonyFeature); |
| 14771 | } |
| 14772 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14773 | |
| 14774 | /** |
| 14775 | * Registers for the satellite communication allowed state changed. |
| 14776 | * |
| 14777 | * @param subId The subId of the subscription to register for the satellite communication |
| 14778 | * allowed state changed. |
| 14779 | * @param callback The callback to handle the satellite communication allowed |
| 14780 | * state changed event. |
| 14781 | * |
| 14782 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14783 | * |
| 14784 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14785 | */ |
| 14786 | @Override |
| 14787 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14788 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14789 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14790 | final long identity = Binder.clearCallingIdentity(); |
| 14791 | try { |
| 14792 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14793 | subId, callback); |
| 14794 | } finally { |
| 14795 | Binder.restoreCallingIdentity(identity); |
| 14796 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14797 | } |
| 14798 | |
| 14799 | /** |
| 14800 | * Unregisters for the satellite communication allowed state changed. |
| 14801 | * If callback was not registered before, the request will be ignored. |
| 14802 | * |
| 14803 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14804 | * allowed state changed. |
| 14805 | * @param callback The callback that was passed to |
| 14806 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14807 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14808 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14809 | */ |
| 14810 | @Override |
| 14811 | public void unregisterForCommunicationAllowedStateChanged( |
| 14812 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14813 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14814 | final long identity = Binder.clearCallingIdentity(); |
| 14815 | try { |
| 14816 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14817 | callback); |
| 14818 | } finally { |
| 14819 | Binder.restoreCallingIdentity(identity); |
| 14820 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14821 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14822 | |
| 14823 | /** |
| 14824 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14825 | * |
| 14826 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14827 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14828 | * if the request is successful or an error code if the request failed. |
| 14829 | * |
| 14830 | * @throws SecurityException if the caller doesn't have required permission. |
| 14831 | */ |
| 14832 | @Override |
| 14833 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14834 | enforceModifyPermission(); |
| 14835 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14836 | final long identity = Binder.clearCallingIdentity(); |
| 14837 | try { |
| 14838 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14839 | } finally { |
| 14840 | Binder.restoreCallingIdentity(identity); |
| 14841 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14842 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14843 | |
| 14844 | /** |
| 14845 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14846 | * |
| 14847 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14848 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14849 | * |
| 14850 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14851 | */ |
| 14852 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14853 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14854 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14855 | final long identity = Binder.clearCallingIdentity(); |
| 14856 | try { |
| 14857 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14858 | } finally { |
| 14859 | Binder.restoreCallingIdentity(identity); |
| 14860 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14861 | } |
| 14862 | |
| 14863 | /** |
| 14864 | * Deliver the list of provisioned satellite subscriber ids. |
| 14865 | * |
| 14866 | * @param list List of provisioned satellite subscriber ids. |
| 14867 | * @param result The result receiver that returns whether deliver success or fail. |
| 14868 | * |
| 14869 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14870 | */ |
| 14871 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14872 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14873 | @NonNull ResultReceiver result) { |
| 14874 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14875 | final long identity = Binder.clearCallingIdentity(); |
| 14876 | try { |
| 14877 | mSatelliteController.provisionSatellite(list, result); |
| 14878 | } finally { |
| 14879 | Binder.restoreCallingIdentity(identity); |
| 14880 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14881 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14882 | |
| 14883 | /** |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14884 | * Deliver the list of deprovisioned satellite subscriber ids. |
| 14885 | * |
| 14886 | * @param list List of deprovisioned satellite subscriber ids. |
| 14887 | * @param result The result receiver that returns whether deliver success or fail. |
| 14888 | * |
| 14889 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14890 | */ |
| 14891 | @Override |
| 14892 | public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
| 14893 | @NonNull ResultReceiver result) { |
| 14894 | enforceSatelliteCommunicationPermission("deprovisionSatellite"); |
| 14895 | final long identity = Binder.clearCallingIdentity(); |
| 14896 | try { |
| 14897 | mSatelliteController.deprovisionSatellite(list, result); |
| 14898 | } finally { |
| 14899 | Binder.restoreCallingIdentity(identity); |
| 14900 | } |
| 14901 | } |
| 14902 | |
Aishwarya Mallampati | a646bc1 | 2024-11-08 23:33:24 +0000 | [diff] [blame] | 14903 | |
| 14904 | /** |
| 14905 | * Inform whether application supports NTN SMS in satellite mode. |
| 14906 | * |
| 14907 | * This method is used by default messaging application to inform framework whether it supports |
| 14908 | * NTN SMS or not. |
| 14909 | * |
| 14910 | * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}. |
| 14911 | * |
| 14912 | * @throws SecurityException if the caller doesn't have required permission. |
| 14913 | */ |
| 14914 | @Override |
| 14915 | public void setNtnSmsSupported(boolean ntnSmsSupported) { |
| 14916 | enforceSatelliteCommunicationPermission("setNtnSmsSupported"); |
| 14917 | enforceSendSmsPermission(); |
Aishwarya Mallampati | dcd19f3 | 2024-11-22 17:26:54 +0000 | [diff] [blame] | 14918 | |
| 14919 | final long identity = Binder.clearCallingIdentity(); |
| 14920 | try { |
| 14921 | mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported); |
| 14922 | } finally { |
| 14923 | Binder.restoreCallingIdentity(identity); |
| 14924 | } |
Aishwarya Mallampati | a646bc1 | 2024-11-08 23:33:24 +0000 | [diff] [blame] | 14925 | } |
| 14926 | |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14927 | /** |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14928 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14929 | * value : |
| 14930 | * config_satellite_gateway_service_package and |
| 14931 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14932 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14933 | * subscriber informations. |
| 14934 | * |
| 14935 | * @param name the name is one of the following that constitute an intent. |
| 14936 | * Component package name, or component class name. |
| 14937 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14938 | */ |
| 14939 | @Override |
| 14940 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14941 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14942 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14943 | + " carrierRoamingNbIotNtn is disabled"); |
| 14944 | return false; |
| 14945 | } |
| 14946 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14947 | TelephonyPermissions.enforceShellOnly( |
| 14948 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14950 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14951 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14952 | final long identity = Binder.clearCallingIdentity(); |
| 14953 | try { |
| 14954 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14955 | } finally { |
| 14956 | Binder.restoreCallingIdentity(identity); |
| 14957 | } |
| 14958 | } |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 14959 | |
| 14960 | /** |
| 14961 | * This API can be used by only CTS to override the Euicc UI component. |
| 14962 | * |
| 14963 | * @param componentName ui component to be launched for testing. {@code null} to reset. |
| 14964 | * |
| 14965 | * @hide |
| 14966 | */ |
| 14967 | @Override |
| 14968 | public void setTestEuiccUiComponent(@Nullable ComponentName componentName) { |
| 14969 | enforceModifyPermission(); |
| 14970 | log("setTestEuiccUiComponent: " + componentName); |
| 14971 | mTestEuiccUiComponent = componentName; |
| 14972 | } |
| 14973 | |
| 14974 | /** |
| 14975 | * This API can be used by only CTS to retrieve the Euicc UI component. |
| 14976 | * |
| 14977 | * @return Euicc UI component. {@code null} if not available. |
| 14978 | * @hide |
| 14979 | */ |
| 14980 | @Override |
| 14981 | @Nullable |
| 14982 | public ComponentName getTestEuiccUiComponent() { |
| 14983 | enforceReadPrivilegedPermission("getTestEuiccUiComponent"); |
| 14984 | return mTestEuiccUiComponent; |
| 14985 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14986 | |
| 14987 | /** |
| 14988 | * This API can be used only for test purpose to override the carrier roaming Ntn eligibility |
| 14989 | * |
| 14990 | * @param state to update Ntn Eligibility. |
| 14991 | * @param resetRequired to reset the overridden flag in satellite controller. |
| 14992 | * @return {@code true} if the shell command is successful, {@code false} otherwise. |
| 14993 | */ |
| 14994 | public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state, |
| 14995 | boolean resetRequired) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14996 | final long identity = Binder.clearCallingIdentity(); |
| 14997 | try { |
| 14998 | return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state, |
| 14999 | resetRequired); |
| 15000 | } finally { |
| 15001 | Binder.restoreCallingIdentity(identity); |
| 15002 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 15003 | } |
jinjeong | c29c54e | 2024-11-15 08:11:18 +0000 | [diff] [blame] | 15004 | |
| 15005 | /** |
| 15006 | * Returns carrier id maps to the passing {@link CarrierIdentifier}. |
| 15007 | * |
| 15008 | * @param carrierIdentifier {@link CarrierIdentifier}. |
| 15009 | * |
| 15010 | * @return carrier id from passing {@link CarrierIdentifier} or UNKNOWN_CARRIER_ID |
| 15011 | * if the carrier cannot be identified |
| 15012 | */ |
| 15013 | public int getCarrierIdFromIdentifier(@NonNull CarrierIdentifier carrierIdentifier) { |
| 15014 | enforceReadPrivilegedPermission("getCarrierIdFromIdentifier"); |
| 15015 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 15016 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromIdentifier"); |
| 15017 | |
| 15018 | final long identity = Binder.clearCallingIdentity(); |
| 15019 | try { |
| 15020 | return CarrierResolver.getCarrierIdFromIdentifier(mApp, carrierIdentifier); |
| 15021 | } finally { |
| 15022 | Binder.restoreCallingIdentity(identity); |
| 15023 | } |
| 15024 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 15025 | } |