Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
| 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 29 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 30 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 34 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 35 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 36 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 38 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 39 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 41 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 43 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 44 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 45 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 46 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 47 | import android.compat.annotation.ChangeId; |
| 48 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 49 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 50 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 51 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.content.Context; |
| 53 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 55 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 56 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.net.Uri; |
| 58 | import android.os.AsyncResult; |
| 59 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 60 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 62 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 64 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 65 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 66 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import android.os.Looper; |
| 68 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 69 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 70 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 71 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 72 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 73 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 74 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 75 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 76 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 77 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 78 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 82 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 83 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 84 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 85 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 86 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 87 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 90 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 91 | import android.telephony.AccessNetworkConstants; |
| 92 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 96 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 97 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 98 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 99 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 100 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 101 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 102 | import android.telephony.CellIdentityCdma; |
| 103 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfoGsm; |
| 106 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 107 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 110 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 111 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 112 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 115 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 118 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrengthUpdateRequest; |
| 123 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 131 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 132 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 133 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 136 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 137 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 138 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 139 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import android.telephony.gba.GbaAuthRequest; |
| 141 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 142 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 146 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 154 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 165 | import android.telephony.satellite.NtnSignalStrength; |
| 166 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteSubscriberInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 175 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 178 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 179 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 180 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 181 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 182 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 197 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 214 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 221 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 224 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 230 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 232 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 233 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 234 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 235 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 236 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.IccIoResult; |
| 238 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 246 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 247 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 248 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 249 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 250 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 251 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 252 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 253 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 254 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 255 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 256 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 257 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 258 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 259 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 260 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 261 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 262 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 263 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 264 | import com.android.services.telephony.TelecomAccountRegistry; |
| 265 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 266 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 267 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 268 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 269 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 270 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 271 | import java.io.IOException; |
| 272 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 273 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 275 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 276 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 277 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 278 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 279 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 280 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 281 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 282 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 283 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 284 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 285 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 286 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 287 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 288 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 289 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * Implementation of the ITelephony interface. |
| 293 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 294 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 296 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 297 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 298 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | |
| 300 | // Message codes used with mMainThreadHandler |
| 301 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 302 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 303 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 304 | private static final int CMD_OPEN_CHANNEL = 9; |
| 305 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 306 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 307 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 308 | private static final int CMD_NV_READ_ITEM = 13; |
| 309 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 310 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 311 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 312 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 313 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 314 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 315 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 316 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 317 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 318 | private static final int CMD_SEND_ENVELOPE = 25; |
| 319 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 320 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 321 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 322 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 323 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 325 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 326 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 327 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 329 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 330 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 331 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 332 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 333 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 334 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 335 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 336 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 337 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 338 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 339 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 340 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 341 | private static final int CMD_SWITCH_SLOTS = 50; |
| 342 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 343 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 344 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 345 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 346 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 347 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 348 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 349 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 350 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 351 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 352 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 353 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 354 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 355 | private static final int CMD_MODEM_REBOOT = 64; |
| 356 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 357 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 358 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 359 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 360 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 361 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 362 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 363 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 364 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 365 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 366 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 367 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 368 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 369 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 370 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 372 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 373 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 374 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 375 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 376 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 377 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 378 | private static final int CMD_GET_CALL_WAITING = 87; |
| 379 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 380 | private static final int CMD_SET_CALL_WAITING = 89; |
| 381 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 382 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 383 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 384 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 385 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 386 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 387 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 388 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 389 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 390 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 391 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 392 | private static final int CMD_SET_SIM_POWER = 101; |
| 393 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 394 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 395 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 396 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 397 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 398 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 399 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 400 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 401 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 402 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 403 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 404 | private static final int CMD_ENABLE_VONR = 113; |
| 405 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 406 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 407 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 408 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 409 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 410 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 411 | // Parameters of select command. |
| 412 | private static final int SELECT_COMMAND = 0xA4; |
| 413 | private static final int SELECT_P1 = 0x04; |
| 414 | private static final int SELECT_P2 = 0; |
| 415 | private static final int SELECT_P3 = 0x10; |
| 416 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 417 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 418 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 419 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 420 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 421 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 422 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | /** The singleton instance. */ |
| 425 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 426 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 428 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 429 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 430 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 431 | private final CallManager mCM; |
| 432 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 433 | |
| 434 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 435 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 436 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 438 | private final SharedPreferences mTelephonySharedPreferences; |
| 439 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 440 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 441 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 442 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 443 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 445 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 446 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 447 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 448 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 449 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 450 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 451 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 452 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 453 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 454 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 455 | // String to store multi SIM allowed |
| 456 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 457 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 458 | // The AID of ISD-R. |
| 459 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 460 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 461 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 462 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 463 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 464 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 465 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 466 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 467 | 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] | 468 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 469 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 470 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 471 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 472 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 473 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 474 | */ |
| 475 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 476 | "reset_network_erase_modem_config_enabled"; |
| 477 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 478 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 479 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 480 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 481 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 482 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 483 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 484 | /** |
| 485 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 486 | * one ICCID active at the same time. |
| 487 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 488 | * |
| 489 | * @hide |
| 490 | */ |
| 491 | @ChangeId |
| 492 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 493 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 494 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 495 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 496 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 497 | * operation fails. |
| 498 | */ |
| 499 | @ChangeId |
| 500 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 501 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 502 | |
| 503 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 504 | * A request object to use for transmitting data to an ICC. |
| 505 | */ |
| 506 | private static final class IccAPDUArgument { |
| 507 | public int channel, cla, command, p1, p2, p3; |
| 508 | public String data; |
| 509 | |
| 510 | public IccAPDUArgument(int channel, int cla, int command, |
| 511 | int p1, int p2, int p3, String data) { |
| 512 | this.channel = channel; |
| 513 | this.cla = cla; |
| 514 | this.command = command; |
| 515 | this.p1 = p1; |
| 516 | this.p2 = p2; |
| 517 | this.p3 = p3; |
| 518 | this.data = data; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 523 | * A request object to use for transmitting data to an ICC. |
| 524 | */ |
| 525 | private static final class ManualNetworkSelectionArgument { |
| 526 | public OperatorInfo operatorInfo; |
| 527 | public boolean persistSelection; |
| 528 | |
| 529 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 530 | this.operatorInfo = operatorInfo; |
| 531 | this.persistSelection = persistSelection; |
| 532 | } |
| 533 | } |
| 534 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 535 | private static final class PurchasePremiumCapabilityArgument { |
| 536 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 537 | public @NonNull IIntegerConsumer callback; |
| 538 | |
| 539 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 540 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 541 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 542 | this.callback = callback; |
| 543 | } |
| 544 | } |
| 545 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 546 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 547 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 548 | * request after sending. The main thread will notify the request when it is complete. |
| 549 | */ |
| 550 | private static final class MainThreadRequest { |
| 551 | /** The argument to use for the request */ |
| 552 | public Object argument; |
| 553 | /** The result of the request that is run on the main thread */ |
| 554 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 555 | // The subscriber id that this request applies to. Defaults to |
| 556 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 557 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 558 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 559 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 560 | public Phone phone; |
| 561 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 562 | public WorkSource workSource; |
| 563 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 564 | public MainThreadRequest(Object argument) { |
| 565 | this.argument = argument; |
| 566 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 567 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 568 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 569 | this.argument = argument; |
| 570 | if (phone != null) { |
| 571 | this.phone = phone; |
| 572 | } |
| 573 | this.workSource = workSource; |
| 574 | } |
| 575 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 576 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 577 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 578 | if (subId != null) { |
| 579 | this.subId = subId; |
| 580 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 581 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 585 | private static final class IncomingThirdPartyCallArgs { |
| 586 | public final ComponentName component; |
| 587 | public final String callId; |
| 588 | public final String callerDisplayName; |
| 589 | |
| 590 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 591 | String callerDisplayName) { |
| 592 | this.component = component; |
| 593 | this.callId = callId; |
| 594 | this.callerDisplayName = callerDisplayName; |
| 595 | } |
| 596 | } |
| 597 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 598 | /** |
| 599 | * A handler that processes messages on the main thread in the phone process. Since many |
| 600 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 601 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 602 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 603 | * on, which will be notified when the operation completes and will contain the result of the |
| 604 | * request. |
| 605 | * |
| 606 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 607 | * note that request.result must be set to something non-null for the calling thread to |
| 608 | * unblock. |
| 609 | */ |
| 610 | private final class MainThreadHandler extends Handler { |
| 611 | @Override |
| 612 | public void handleMessage(Message msg) { |
| 613 | MainThreadRequest request; |
| 614 | Message onCompleted; |
| 615 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 616 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 618 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 619 | |
| 620 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | case CMD_HANDLE_USSD_REQUEST: { |
| 622 | request = (MainThreadRequest) msg.obj; |
| 623 | final Phone phone = getPhoneFromRequest(request); |
| 624 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 625 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 627 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | if (!isUssdApiAllowed(request.subId)) { |
| 629 | // Carrier does not support use of this API, return failure. |
| 630 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 631 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 632 | Bundle returnData = new Bundle(); |
| 633 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 634 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 637 | notifyRequester(request); |
| 638 | return; |
| 639 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 640 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 641 | try { |
| 642 | request.result = phone != null |
| 643 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 644 | } catch (CallStateException cse) { |
| 645 | request.result = false; |
| 646 | } |
| 647 | // Wake up the requesting thread |
| 648 | notifyRequester(request); |
| 649 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 652 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 653 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 654 | final Phone phone = getPhoneFromRequest(request); |
| 655 | request.result = phone != null ? |
| 656 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 657 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 658 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 659 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 660 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 661 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 662 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 666 | uiccPort = getUiccPortFromRequest(request); |
| 667 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 669 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 670 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 673 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 674 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 675 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 676 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 677 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | ar = (AsyncResult) msg.obj; |
| 683 | request = (MainThreadRequest) ar.userObj; |
| 684 | if (ar.exception == null && ar.result != null) { |
| 685 | request.result = ar.result; |
| 686 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 687 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | if (ar.result == null) { |
| 689 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | } else { |
| 694 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 695 | } |
| 696 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 697 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | break; |
| 699 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 701 | request = (MainThreadRequest) msg.obj; |
| 702 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 703 | uiccPort = getUiccPortFromRequest(request); |
| 704 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 706 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 707 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | } else { |
| 709 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 710 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 711 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 712 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 713 | iccArgument.p2, |
| 714 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 715 | } |
| 716 | break; |
| 717 | |
| 718 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 719 | ar = (AsyncResult) msg.obj; |
| 720 | request = (MainThreadRequest) ar.userObj; |
| 721 | if (ar.exception == null && ar.result != null) { |
| 722 | request.result = ar.result; |
| 723 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 724 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 725 | if (ar.result == null) { |
| 726 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 727 | } else if (ar.exception instanceof CommandException) { |
| 728 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 729 | ar.exception); |
| 730 | } else { |
| 731 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 732 | } |
| 733 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 734 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case CMD_EXCHANGE_SIM_IO: |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 740 | uiccPort = getUiccPortFromRequest(request); |
| 741 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 742 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 743 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 745 | } else { |
| 746 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 747 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 748 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 749 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 750 | iccArgument.data, onCompleted); |
| 751 | } |
| 752 | break; |
| 753 | |
| 754 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 755 | ar = (AsyncResult) msg.obj; |
| 756 | request = (MainThreadRequest) ar.userObj; |
| 757 | if (ar.exception == null && ar.result != null) { |
| 758 | request.result = ar.result; |
| 759 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 760 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 763 | break; |
| 764 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 765 | case CMD_SEND_ENVELOPE: |
| 766 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 767 | uiccPort = getUiccPortFromRequest(request); |
| 768 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 769 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 770 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 771 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 772 | } else { |
| 773 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 774 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_SEND_ENVELOPE_DONE: |
| 779 | ar = (AsyncResult) msg.obj; |
| 780 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 781 | if (ar.exception == null && ar.result != null) { |
| 782 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 783 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 784 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 785 | if (ar.result == null) { |
| 786 | loge("sendEnvelopeWithStatus: Empty response"); |
| 787 | } else if (ar.exception instanceof CommandException) { |
| 788 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 789 | ar.exception); |
| 790 | } else { |
| 791 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 792 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 793 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 794 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | case CMD_OPEN_CHANNEL: |
| 798 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 799 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 800 | IccLogicalChannelRequest openChannelRequest = |
| 801 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 802 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 803 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 804 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 805 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 806 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 807 | } else { |
| 808 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 809 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 810 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 811 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 812 | break; |
| 813 | |
| 814 | case EVENT_OPEN_CHANNEL_DONE: |
| 815 | ar = (AsyncResult) msg.obj; |
| 816 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 817 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 818 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 819 | int[] result = (int[]) ar.result; |
| 820 | int channelId = result[0]; |
| 821 | byte[] selectResponse = null; |
| 822 | if (result.length > 1) { |
| 823 | selectResponse = new byte[result.length - 1]; |
| 824 | for (int i = 1; i < result.length; ++i) { |
| 825 | selectResponse[i - 1] = (byte) result[i]; |
| 826 | } |
| 827 | } |
| 828 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 829 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 830 | |
| 831 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 832 | if (uiccPort == null) { |
| 833 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 834 | } else { |
| 835 | IccLogicalChannelRequest channelRequest = |
| 836 | (IccLogicalChannelRequest) request.argument; |
| 837 | channelRequest.channel = channelId; |
| 838 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 839 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 840 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | if (ar.result == null) { |
| 842 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 843 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 844 | if (ar.exception != null) { |
| 845 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 846 | } |
| 847 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 848 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 849 | if (ar.exception instanceof CommandException) { |
| 850 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 851 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 852 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 853 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 854 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 855 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 859 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 860 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 861 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 862 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case CMD_CLOSE_CHANNEL: |
| 866 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 867 | uiccPort = getUiccPortFromRequest(request); |
| 868 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 869 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 870 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 871 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 872 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 873 | } else { |
| 874 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 875 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 876 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 880 | ar = (AsyncResult) msg.obj; |
| 881 | request = (MainThreadRequest) ar.userObj; |
| 882 | if (ar.exception == null) { |
| 883 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 884 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 885 | if (uiccPort == null) { |
| 886 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 887 | } else { |
| 888 | final int channelId = (Integer) request.argument; |
| 889 | uiccPort.onLogicalChannelClosed(channelId); |
| 890 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 891 | } else { |
| 892 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 893 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 894 | if (ar.exception instanceof CommandException) { |
| 895 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 896 | CommandException.Error error = |
| 897 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 898 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 899 | // should only throw exceptions from the binder threads. |
| 900 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 901 | "iccCloseLogicalChannel: invalid argument "); |
| 902 | } |
| 903 | } else { |
| 904 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 905 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 906 | request.result = (exception != null) ? exception : |
| 907 | new IllegalStateException( |
| 908 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 909 | } |
| 910 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case CMD_NV_READ_ITEM: |
| 914 | request = (MainThreadRequest) msg.obj; |
| 915 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 916 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 917 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 921 | ar = (AsyncResult) msg.obj; |
| 922 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 923 | if (ar.exception == null && ar.result != null) { |
| 924 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 925 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | request.result = ""; |
| 927 | if (ar.result == null) { |
| 928 | loge("nvReadItem: Empty response"); |
| 929 | } else if (ar.exception instanceof CommandException) { |
| 930 | loge("nvReadItem: CommandException: " + |
| 931 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 932 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 933 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 936 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 937 | break; |
| 938 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 939 | case CMD_NV_WRITE_ITEM: |
| 940 | request = (MainThreadRequest) msg.obj; |
| 941 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 942 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 943 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 944 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 945 | break; |
| 946 | |
| 947 | case EVENT_NV_WRITE_ITEM_DONE: |
| 948 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 949 | break; |
| 950 | |
| 951 | case CMD_NV_WRITE_CDMA_PRL: |
| 952 | request = (MainThreadRequest) msg.obj; |
| 953 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 954 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 955 | break; |
| 956 | |
| 957 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 958 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 959 | break; |
| 960 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 961 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 962 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 963 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 964 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 965 | break; |
| 966 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 967 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 968 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 969 | break; |
| 970 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 971 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 972 | request = (MainThreadRequest) msg.obj; |
| 973 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 974 | request); |
| 975 | Phone phone = getPhoneFromRequest(request); |
| 976 | if (phone != null) { |
| 977 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 978 | } else { |
| 979 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 980 | request.result = false; |
| 981 | notifyRequester(request); |
| 982 | } |
| 983 | break; |
| 984 | } |
| 985 | |
| 986 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 987 | ar = (AsyncResult) msg.obj; |
| 988 | request = (MainThreadRequest) ar.userObj; |
| 989 | if (ar.exception == null && ar.result != null) { |
| 990 | request.result = ar.result; |
| 991 | } else { |
| 992 | // request.result must be set to something non-null |
| 993 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 994 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 995 | request.result = ar.result; |
| 996 | } else { |
| 997 | request.result = false; |
| 998 | } |
| 999 | if (ar.result == null) { |
| 1000 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1001 | } else if (ar.exception instanceof CommandException) { |
| 1002 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1003 | + ar.exception); |
| 1004 | } else { |
| 1005 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1006 | } |
| 1007 | } |
| 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1011 | case CMD_IS_VONR_ENABLED: { |
| 1012 | request = (MainThreadRequest) msg.obj; |
| 1013 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1014 | request); |
| 1015 | Phone phone = getPhoneFromRequest(request); |
| 1016 | if (phone != null) { |
| 1017 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1018 | } else { |
| 1019 | loge("isVoNrEnabled: No phone object"); |
| 1020 | request.result = false; |
| 1021 | notifyRequester(request); |
| 1022 | } |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1027 | ar = (AsyncResult) msg.obj; |
| 1028 | request = (MainThreadRequest) ar.userObj; |
| 1029 | if (ar.exception == null && ar.result != null) { |
| 1030 | request.result = ar.result; |
| 1031 | } else { |
| 1032 | // request.result must be set to something non-null |
| 1033 | // for the calling thread to unblock |
| 1034 | if (ar.result != null) { |
| 1035 | request.result = ar.result; |
| 1036 | } else { |
| 1037 | request.result = false; |
| 1038 | } |
| 1039 | if (ar.result == null) { |
| 1040 | loge("isVoNrEnabled: Empty response"); |
| 1041 | } else if (ar.exception instanceof CommandException) { |
| 1042 | loge("isVoNrEnabled: CommandException: " |
| 1043 | + ar.exception); |
| 1044 | } else { |
| 1045 | loge("isVoNrEnabled: Unknown exception"); |
| 1046 | } |
| 1047 | } |
| 1048 | notifyRequester(request); |
| 1049 | break; |
| 1050 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1051 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1052 | request = (MainThreadRequest) msg.obj; |
| 1053 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1054 | Phone phone = getPhoneFromRequest(request); |
| 1055 | if (phone != null) { |
| 1056 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1057 | request.workSource); |
| 1058 | } else { |
| 1059 | loge("enableNrDualConnectivity: No phone object"); |
| 1060 | request.result = |
| 1061 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1062 | notifyRequester(request); |
| 1063 | } |
| 1064 | break; |
| 1065 | } |
| 1066 | |
| 1067 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1068 | ar = (AsyncResult) msg.obj; |
| 1069 | request = (MainThreadRequest) ar.userObj; |
| 1070 | if (ar.exception == null) { |
| 1071 | request.result = |
| 1072 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1073 | } else { |
| 1074 | request.result = |
| 1075 | TelephonyManager |
| 1076 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1077 | if (ar.exception instanceof CommandException) { |
| 1078 | CommandException.Error error = |
| 1079 | ((CommandException) (ar.exception)).getCommandError(); |
| 1080 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1081 | request.result = |
| 1082 | TelephonyManager |
| 1083 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1084 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1085 | request.result = |
| 1086 | TelephonyManager |
| 1087 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1088 | } |
| 1089 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1090 | + ar.exception); |
| 1091 | } else { |
| 1092 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1093 | } |
| 1094 | } |
| 1095 | notifyRequester(request); |
| 1096 | break; |
| 1097 | } |
| 1098 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1099 | case CMD_ENABLE_VONR: { |
| 1100 | request = (MainThreadRequest) msg.obj; |
| 1101 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1102 | Phone phone = getPhoneFromRequest(request); |
| 1103 | if (phone != null) { |
| 1104 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1105 | request.workSource); |
| 1106 | } else { |
| 1107 | loge("setVoNrEnabled: No phone object"); |
| 1108 | request.result = |
| 1109 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1110 | notifyRequester(request); |
| 1111 | } |
| 1112 | break; |
| 1113 | } |
| 1114 | |
| 1115 | case EVENT_ENABLE_VONR_DONE: { |
| 1116 | ar = (AsyncResult) msg.obj; |
| 1117 | request = (MainThreadRequest) ar.userObj; |
| 1118 | if (ar.exception == null) { |
| 1119 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1120 | } else { |
| 1121 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1122 | if (ar.exception instanceof CommandException) { |
| 1123 | CommandException.Error error = |
| 1124 | ((CommandException) (ar.exception)).getCommandError(); |
| 1125 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1126 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1127 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1128 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1129 | } else { |
| 1130 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1131 | } |
| 1132 | loge("setVoNrEnabled" + ": CommandException: " |
| 1133 | + ar.exception); |
| 1134 | } else { |
| 1135 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1136 | } |
| 1137 | } |
| 1138 | notifyRequester(request); |
| 1139 | break; |
| 1140 | } |
| 1141 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1145 | request); |
| 1146 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1147 | break; |
| 1148 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1149 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1150 | ar = (AsyncResult) msg.obj; |
| 1151 | request = (MainThreadRequest) ar.userObj; |
| 1152 | if (ar.exception == null && ar.result != null) { |
| 1153 | request.result = ar.result; // Integer |
| 1154 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1155 | // request.result must be set to something non-null |
| 1156 | // for the calling thread to unblock |
| 1157 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1159 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1161 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1162 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1163 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1164 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1165 | } |
| 1166 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1167 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1168 | break; |
| 1169 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1170 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1171 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1172 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1173 | request); |
| 1174 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1175 | (Pair<Integer, Long>) request.argument; |
| 1176 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1177 | reasonWithNetworkTypes.first, |
| 1178 | reasonWithNetworkTypes.second, |
| 1179 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1180 | break; |
| 1181 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1182 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1183 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1184 | break; |
| 1185 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1186 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1187 | request = (MainThreadRequest) msg.obj; |
| 1188 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1189 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1190 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1191 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1192 | break; |
| 1193 | |
| 1194 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1195 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1196 | break; |
| 1197 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1198 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1199 | request = (MainThreadRequest) msg.obj; |
| 1200 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1201 | request); |
| 1202 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1203 | break; |
| 1204 | |
| 1205 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1206 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1207 | break; |
| 1208 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1209 | case CMD_PERFORM_NETWORK_SCAN: |
| 1210 | request = (MainThreadRequest) msg.obj; |
| 1211 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1212 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1213 | break; |
| 1214 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | request = (MainThreadRequest) msg.obj; |
| 1217 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1219 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1220 | request.argument; |
| 1221 | int callForwardingReason = args.first; |
| 1222 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | } |
| 1225 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | ar = (AsyncResult) msg.obj; |
| 1227 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1229 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1230 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1232 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1234 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1235 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1236 | // any service for voice call. |
| 1237 | if ((callForwardInfo.serviceClass |
| 1238 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1239 | callForwardingInfo = new CallForwardingInfo( |
| 1240 | callForwardInfo.status |
| 1241 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | callForwardInfo.reason, |
| 1243 | callForwardInfo.number, |
| 1244 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | // Didn't find a call forward info for voice call. |
| 1249 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1251 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | } else { |
| 1255 | if (ar.result == null) { |
| 1256 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1257 | } |
| 1258 | if (ar.exception != null) { |
| 1259 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1260 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1261 | int errorCode = TelephonyManager |
| 1262 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | if (ar.exception instanceof CommandException) { |
| 1264 | CommandException.Error error = |
| 1265 | ((CommandException) (ar.exception)).getCommandError(); |
| 1266 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1267 | errorCode = TelephonyManager |
| 1268 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1269 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1270 | errorCode = TelephonyManager |
| 1271 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | } |
| 1273 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | request = (MainThreadRequest) msg.obj; |
| 1281 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1285 | request.argument).first; |
| 1286 | request.phone.setCallForwardingOption( |
| 1287 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1288 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1289 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | callForwardingInfoToSet.getReason(), |
| 1291 | callForwardingInfoToSet.getNumber(), |
| 1292 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1293 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | ar = (AsyncResult) msg.obj; |
| 1298 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | Consumer<Integer> callback = |
| 1300 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1301 | request.argument).second; |
| 1302 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1304 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1305 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | if (ar.exception instanceof CommandException) { |
| 1307 | CommandException.Error error = |
| 1308 | ((CommandException) (ar.exception)).getCommandError(); |
| 1309 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1310 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1311 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1313 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1314 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | callback.accept(errorCode); |
| 1318 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1319 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1324 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | request = (MainThreadRequest) msg.obj; |
| 1326 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1327 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1328 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1331 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1332 | ar = (AsyncResult) msg.obj; |
| 1333 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1335 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1337 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | // Service Class is a bit mask per 3gpp 27.007. |
| 1339 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1340 | if (callForwardResults.length > 1 |
| 1341 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1343 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1345 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1347 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | } |
| 1349 | } else { |
| 1350 | if (ar.result == null) { |
| 1351 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1352 | } |
| 1353 | if (ar.exception != null) { |
| 1354 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1355 | } |
| 1356 | if (ar.exception instanceof CommandException) { |
| 1357 | CommandException.Error error = |
| 1358 | ((CommandException) (ar.exception)).getCommandError(); |
| 1359 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1360 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1361 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1362 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1363 | callWaitingStatus = |
| 1364 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1368 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1371 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1372 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1375 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1376 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1380 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | ar = (AsyncResult) msg.obj; |
| 1382 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1384 | Consumer<Integer> callback = |
| 1385 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1386 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1387 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1388 | if (ar.exception instanceof CommandException) { |
| 1389 | CommandException.Error error = |
| 1390 | ((CommandException) (ar.exception)).getCommandError(); |
| 1391 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1392 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1393 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1394 | callback.accept( |
| 1395 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1396 | } else { |
| 1397 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1398 | } |
| 1399 | } else { |
| 1400 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1401 | } |
| 1402 | } else { |
| 1403 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1404 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1405 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1406 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1407 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1408 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1409 | ar = (AsyncResult) msg.obj; |
| 1410 | request = (MainThreadRequest) ar.userObj; |
| 1411 | CellNetworkScanResult cellScanResult; |
| 1412 | if (ar.exception == null && ar.result != null) { |
| 1413 | cellScanResult = new CellNetworkScanResult( |
| 1414 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1415 | (List<OperatorInfo>) ar.result); |
| 1416 | } else { |
| 1417 | if (ar.result == null) { |
| 1418 | loge("getCellNetworkScanResults: Empty response"); |
| 1419 | } |
| 1420 | if (ar.exception != null) { |
| 1421 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1422 | } |
| 1423 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1424 | if (ar.exception instanceof CommandException) { |
| 1425 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1426 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1427 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1428 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1429 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1430 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1431 | } |
| 1432 | } |
| 1433 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1434 | } |
| 1435 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1436 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | |
| 1439 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1440 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1441 | ManualNetworkSelectionArgument selArg = |
| 1442 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1443 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1444 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1445 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1446 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
| 1449 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
| 1452 | if (ar.exception == null) { |
| 1453 | request.result = true; |
| 1454 | } else { |
| 1455 | request.result = false; |
| 1456 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1457 | } |
| 1458 | notifyRequester(request); |
| 1459 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1460 | break; |
| 1461 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1462 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1463 | request = (MainThreadRequest) msg.obj; |
| 1464 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1465 | if (defaultPhone != null) { |
| 1466 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1467 | } else { |
| 1468 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1469 | Bundle bundle = new Bundle(); |
| 1470 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1471 | new ModemActivityInfo(0, 0, 0, |
| 1472 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1473 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1474 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1475 | break; |
| 1476 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1477 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1478 | ar = (AsyncResult) msg.obj; |
| 1479 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1480 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1481 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1482 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1483 | if (mLastModemActivityInfo == null) { |
| 1484 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1485 | mLastModemActivitySpecificInfo[0] = |
| 1486 | new ActivityStatsTechSpecificInfo( |
| 1487 | 0, |
| 1488 | 0, |
| 1489 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1490 | 0); |
| 1491 | mLastModemActivityInfo = |
| 1492 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1493 | } |
| 1494 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1495 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1496 | // Update the last modem activity info and the result of the request. |
| 1497 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1498 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1499 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1500 | } else { |
| 1501 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1502 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1503 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1504 | // We don't want to return mLastModemActivityInfo which is updated |
| 1505 | // inside mergeModemActivityInfo() |
| 1506 | ret = new ModemActivityInfo( |
| 1507 | mLastModemActivityInfo.getTimestampMillis(), |
| 1508 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1509 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1510 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1511 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1512 | } else { |
| 1513 | if (ar.result == null) { |
| 1514 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1515 | error = TelephonyManager.ModemActivityInfoException |
| 1516 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1517 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1518 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1519 | error = TelephonyManager.ModemActivityInfoException |
| 1520 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1521 | } else { |
| 1522 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | error = TelephonyManager.ModemActivityInfoException |
| 1524 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1527 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1528 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1529 | bundle.putParcelable( |
| 1530 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1531 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1532 | } else { |
| 1533 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1534 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1535 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1536 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1537 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1538 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1539 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1540 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1541 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1542 | CarrierRestrictionRules argument = |
| 1543 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1544 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1545 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1546 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1547 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1548 | |
| 1549 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1550 | ar = (AsyncResult) msg.obj; |
| 1551 | request = (MainThreadRequest) ar.userObj; |
| 1552 | if (ar.exception == null && ar.result != null) { |
| 1553 | request.result = ar.result; |
| 1554 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1555 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1556 | if (ar.exception instanceof CommandException) { |
| 1557 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1558 | CommandException.Error error = |
| 1559 | ((CommandException) (ar.exception)).getCommandError(); |
| 1560 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1561 | request.result = |
| 1562 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1563 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1564 | } else { |
| 1565 | loge("setAllowedCarriers: Unknown exception"); |
| 1566 | } |
| 1567 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1568 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1569 | break; |
| 1570 | |
| 1571 | case CMD_GET_ALLOWED_CARRIERS: |
| 1572 | request = (MainThreadRequest) msg.obj; |
| 1573 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1574 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1575 | break; |
| 1576 | |
| 1577 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1578 | ar = (AsyncResult) msg.obj; |
| 1579 | request = (MainThreadRequest) ar.userObj; |
| 1580 | if (ar.exception == null && ar.result != null) { |
| 1581 | request.result = ar.result; |
| 1582 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1583 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1584 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1585 | if (ar.result == null) { |
| 1586 | loge("getAllowedCarriers: Empty response"); |
| 1587 | } else if (ar.exception instanceof CommandException) { |
| 1588 | loge("getAllowedCarriers: CommandException: " + |
| 1589 | ar.exception); |
| 1590 | } else { |
| 1591 | loge("getAllowedCarriers: Unknown exception"); |
| 1592 | } |
| 1593 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1594 | if (request.argument != null) { |
| 1595 | // This is for the implementation of carrierRestrictionStatus. |
| 1596 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1597 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1598 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1599 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1600 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1601 | CarrierRestrictionRules carrierRestrictionRules = |
| 1602 | (CarrierRestrictionRules) ar.result; |
| 1603 | int carrierId = -1; |
| 1604 | try { |
| 1605 | CarrierIdentifier carrierIdentifier = |
| 1606 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1607 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1608 | carrierIdentifier); |
| 1609 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1610 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1611 | } |
| 1612 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1613 | int restrictedStatus = |
| 1614 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1615 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1616 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1617 | lockStatus = TelephonyManager |
| 1618 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } else { |
| 1621 | Rlog.e(LOG_TAG, |
| 1622 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1623 | } |
| 1624 | callback.accept(lockStatus); |
| 1625 | } else { |
| 1626 | // This is for the implementation of getAllowedCarriers. |
| 1627 | notifyRequester(request); |
| 1628 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1629 | break; |
| 1630 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1631 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1632 | ar = (AsyncResult) msg.obj; |
| 1633 | request = (MainThreadRequest) ar.userObj; |
| 1634 | if (ar.exception == null && ar.result != null) { |
| 1635 | request.result = ar.result; |
| 1636 | } else { |
| 1637 | request.result = new IllegalArgumentException( |
| 1638 | "Failed to retrieve Forbidden Plmns"); |
| 1639 | if (ar.result == null) { |
| 1640 | loge("getForbiddenPlmns: Empty response"); |
| 1641 | } else { |
| 1642 | loge("getForbiddenPlmns: Unknown exception"); |
| 1643 | } |
| 1644 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1645 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1646 | break; |
| 1647 | |
| 1648 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1649 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1650 | uiccPort = getUiccPortFromRequest(request); |
| 1651 | if (uiccPort == null) { |
| 1652 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1653 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1654 | "getForbiddenPlmns() UiccPort is null"); |
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 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1659 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1660 | if (uiccApp == null) { |
| 1661 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1662 | + appType); |
| 1663 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1664 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1665 | break; |
| 1666 | } else { |
| 1667 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1668 | + " specified type -- " + appType); |
| 1669 | } |
| 1670 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1671 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1672 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1673 | break; |
| 1674 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1675 | case CMD_SWITCH_SLOTS: |
| 1676 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1677 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1678 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1679 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1680 | break; |
| 1681 | |
| 1682 | case EVENT_SWITCH_SLOTS_DONE: |
| 1683 | ar = (AsyncResult) msg.obj; |
| 1684 | request = (MainThreadRequest) ar.userObj; |
| 1685 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1686 | notifyRequester(request); |
| 1687 | break; |
| 1688 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1689 | request = (MainThreadRequest) msg.obj; |
| 1690 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1691 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1692 | break; |
| 1693 | |
| 1694 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1695 | ar = (AsyncResult) msg.obj; |
| 1696 | request = (MainThreadRequest) ar.userObj; |
| 1697 | if (ar.exception != null) { |
| 1698 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1699 | } else { |
| 1700 | int mode = ((int[]) ar.result)[0]; |
| 1701 | if (mode == 0) { |
| 1702 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1703 | } else { |
| 1704 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1705 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1706 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1707 | notifyRequester(request); |
| 1708 | break; |
| 1709 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1712 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1713 | break; |
| 1714 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1715 | ar = (AsyncResult) msg.obj; |
| 1716 | request = (MainThreadRequest) ar.userObj; |
| 1717 | if (ar.exception != null) { |
| 1718 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1719 | } else { |
| 1720 | request.result = ((int[]) ar.result)[0]; |
| 1721 | } |
| 1722 | notifyRequester(request); |
| 1723 | break; |
| 1724 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1725 | request = (MainThreadRequest) msg.obj; |
| 1726 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1727 | int mode = (int) request.argument; |
| 1728 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1729 | break; |
| 1730 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1731 | ar = (AsyncResult) msg.obj; |
| 1732 | request = (MainThreadRequest) ar.userObj; |
| 1733 | request.result = ar.exception == null; |
| 1734 | notifyRequester(request); |
| 1735 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1736 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1737 | request = (MainThreadRequest) msg.obj; |
| 1738 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1739 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1740 | break; |
| 1741 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1742 | ar = (AsyncResult) msg.obj; |
| 1743 | request = (MainThreadRequest) ar.userObj; |
| 1744 | if (ar.exception != null) { |
| 1745 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1746 | } else { |
| 1747 | request.result = ((int[]) ar.result)[0]; |
| 1748 | } |
| 1749 | notifyRequester(request); |
| 1750 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1751 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1752 | request = (MainThreadRequest) msg.obj; |
| 1753 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1754 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1755 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1756 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1757 | break; |
| 1758 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1759 | ar = (AsyncResult) msg.obj; |
| 1760 | request = (MainThreadRequest) ar.userObj; |
| 1761 | request.result = ar.exception == null; |
| 1762 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1763 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1764 | case CMD_GET_ALL_CELL_INFO: |
| 1765 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1766 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1767 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1768 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1769 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1770 | ar = (AsyncResult) msg.obj; |
| 1771 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1772 | // If a timeout occurs, the response will be null |
| 1773 | request.result = (ar.exception == null && ar.result != null) |
| 1774 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1775 | synchronized (request) { |
| 1776 | request.notifyAll(); |
| 1777 | } |
| 1778 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1780 | request = (MainThreadRequest) msg.obj; |
| 1781 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1782 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1783 | break; |
| 1784 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1785 | ar = (AsyncResult) msg.obj; |
| 1786 | request = (MainThreadRequest) ar.userObj; |
| 1787 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1788 | try { |
| 1789 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1790 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1791 | cb.onError( |
| 1792 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1793 | ar.exception.getClass().getName(), |
| 1794 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1795 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1796 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1797 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1798 | } else { |
| 1799 | // use the result as returned |
| 1800 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1801 | } |
| 1802 | } catch (RemoteException re) { |
| 1803 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1804 | } |
| 1805 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1806 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1807 | request = (MainThreadRequest) msg.obj; |
| 1808 | WorkSource ws = (WorkSource) request.argument; |
| 1809 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1810 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1811 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1812 | } |
| 1813 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1814 | ar = (AsyncResult) msg.obj; |
| 1815 | request = (MainThreadRequest) ar.userObj; |
| 1816 | if (ar.exception == null) { |
| 1817 | request.result = ar.result; |
| 1818 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1819 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1820 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1821 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | synchronized (request) { |
| 1825 | request.notifyAll(); |
| 1826 | } |
| 1827 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1828 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1829 | case CMD_MODEM_REBOOT: |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1832 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1833 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1834 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1835 | handleNullReturnEvent(msg, "rebootModem"); |
| 1836 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1837 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1838 | request = (MainThreadRequest) msg.obj; |
| 1839 | boolean enable = (boolean) request.argument; |
| 1840 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1841 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1842 | PhoneConfigurationManager.getInstance() |
| 1843 | .enablePhone(request.phone, enable, onCompleted); |
| 1844 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1845 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1846 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1847 | ar = (AsyncResult) msg.obj; |
| 1848 | request = (MainThreadRequest) ar.userObj; |
| 1849 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1850 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1851 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1852 | if ((boolean) request.result) { |
| 1853 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1854 | updateModemStateMetrics(); |
| 1855 | } else { |
| 1856 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1857 | + ar.exception); |
| 1858 | } |
| 1859 | notifyRequester(request); |
| 1860 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1861 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1862 | case CMD_GET_MODEM_STATUS: |
| 1863 | request = (MainThreadRequest) msg.obj; |
| 1864 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1865 | PhoneConfigurationManager.getInstance() |
| 1866 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1867 | break; |
| 1868 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1869 | ar = (AsyncResult) msg.obj; |
| 1870 | request = (MainThreadRequest) ar.userObj; |
| 1871 | int id = request.phone.getPhoneId(); |
| 1872 | if (ar.exception == null && ar.result != null) { |
| 1873 | request.result = ar.result; |
| 1874 | //update the cache as modem status has changed |
| 1875 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1876 | (boolean) request.result); |
| 1877 | } else { |
| 1878 | // Return true if modem status cannot be retrieved. For most cases, |
| 1879 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1880 | // and disable modem are not supported. Modem is always on. |
| 1881 | // TODO: this should be fixed in R to support a third |
| 1882 | // status UNKNOWN b/131631629 |
| 1883 | request.result = true; |
| 1884 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1885 | + ar.exception); |
| 1886 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1887 | notifyRequester(request); |
| 1888 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1889 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1890 | request = (MainThreadRequest) msg.obj; |
| 1891 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1892 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1893 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1894 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1895 | break; |
| 1896 | } |
| 1897 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1898 | ar = (AsyncResult) msg.obj; |
| 1899 | request = (MainThreadRequest) ar.userObj; |
| 1900 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1901 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1902 | args.second.accept(ar.exception == null); |
| 1903 | notifyRequester(request); |
| 1904 | break; |
| 1905 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1906 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1907 | request = (MainThreadRequest) msg.obj; |
| 1908 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1909 | Phone phone = getPhoneFromRequest(request); |
| 1910 | if (phone != null) { |
| 1911 | phone.getSystemSelectionChannels(onCompleted); |
| 1912 | } else { |
| 1913 | loge("getSystemSelectionChannels: No phone object"); |
| 1914 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1915 | notifyRequester(request); |
| 1916 | } |
| 1917 | break; |
| 1918 | } |
| 1919 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1920 | ar = (AsyncResult) msg.obj; |
| 1921 | request = (MainThreadRequest) ar.userObj; |
| 1922 | if (ar.exception == null && ar.result != null) { |
| 1923 | request.result = ar.result; |
| 1924 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1925 | request.result = new IllegalStateException( |
| 1926 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1927 | if (ar.result == null) { |
| 1928 | loge("getSystemSelectionChannels: Empty response"); |
| 1929 | } else { |
| 1930 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1931 | } |
| 1932 | } |
| 1933 | notifyRequester(request); |
| 1934 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1935 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1936 | ar = (AsyncResult) msg.obj; |
| 1937 | request = (MainThreadRequest) ar.userObj; |
| 1938 | if (ar.exception == null && ar.result != null) { |
| 1939 | request.result = ar.result; |
| 1940 | } else { |
| 1941 | request.result = -1; |
| 1942 | loge("Failed to set Forbidden Plmns"); |
| 1943 | if (ar.result == null) { |
| 1944 | loge("setForbidenPlmns: Empty response"); |
| 1945 | } else if (ar.exception != null) { |
| 1946 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1947 | request.result = -1; |
| 1948 | } else { |
| 1949 | loge("setForbiddenPlmns: Unknown exception"); |
| 1950 | } |
| 1951 | } |
| 1952 | notifyRequester(request); |
| 1953 | break; |
| 1954 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1955 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1956 | uiccPort = getUiccPortFromRequest(request); |
| 1957 | if (uiccPort == null) { |
| 1958 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1959 | request.result = -1; |
| 1960 | notifyRequester(request); |
| 1961 | break; |
| 1962 | } |
| 1963 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1964 | (Pair<Integer, List<String>>) request.argument; |
| 1965 | appType = setFplmnsArgs.first; |
| 1966 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1967 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1968 | if (uiccApp == null) { |
| 1969 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1970 | request.result = -1; |
| 1971 | loge("Failed to get UICC App"); |
| 1972 | notifyRequester(request); |
| 1973 | } else { |
| 1974 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1975 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1976 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1977 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1978 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1979 | case CMD_ERASE_MODEM_CONFIG: |
| 1980 | request = (MainThreadRequest) msg.obj; |
| 1981 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1982 | defaultPhone.eraseModemConfig(onCompleted); |
| 1983 | break; |
| 1984 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1985 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1986 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1987 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1988 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1989 | request = (MainThreadRequest) msg.obj; |
| 1990 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1991 | notifyRequester(request); |
| 1992 | break; |
| 1993 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1994 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1995 | request = (MainThreadRequest) msg.obj; |
| 1996 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1997 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1998 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1999 | changed.first, changed.second, onCompleted); |
| 2000 | break; |
| 2001 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2002 | ar = (AsyncResult) msg.obj; |
| 2003 | request = (MainThreadRequest) ar.userObj; |
| 2004 | if (ar.exception == null) { |
| 2005 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2006 | // If the operation is successful, update the PIN storage |
| 2007 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2008 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2009 | UiccController.getInstance().getPinStorage() |
| 2010 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2011 | } else { |
| 2012 | request.result = msg.arg1; |
| 2013 | } |
| 2014 | notifyRequester(request); |
| 2015 | break; |
| 2016 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2017 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2018 | request = (MainThreadRequest) msg.obj; |
| 2019 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2020 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2021 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2022 | enabled.first, enabled.second, onCompleted); |
| 2023 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2024 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2025 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2026 | ar = (AsyncResult) msg.obj; |
| 2027 | request = (MainThreadRequest) ar.userObj; |
| 2028 | if (ar.exception == null) { |
| 2029 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2030 | // If the operation is successful, update the PIN storage |
| 2031 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2032 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2033 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2034 | UiccController.getInstance().getPinStorage() |
| 2035 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2036 | } else { |
| 2037 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2038 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2039 | } else { |
| 2040 | request.result = msg.arg1; |
| 2041 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2042 | |
| 2043 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2044 | notifyRequester(request); |
| 2045 | break; |
| 2046 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2047 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2048 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2049 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2050 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2051 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2052 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2053 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2054 | |
| 2055 | case CMD_SET_DATA_THROTTLING: { |
| 2056 | request = (MainThreadRequest) msg.obj; |
| 2057 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2058 | DataThrottlingRequest dataThrottlingRequest = |
| 2059 | (DataThrottlingRequest) request.argument; |
| 2060 | Phone phone = getPhoneFromRequest(request); |
| 2061 | if (phone != null) { |
| 2062 | phone.setDataThrottling(onCompleted, |
| 2063 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2064 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2065 | } else { |
| 2066 | loge("setDataThrottling: No phone object"); |
| 2067 | request.result = |
| 2068 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2069 | notifyRequester(request); |
| 2070 | } |
| 2071 | |
| 2072 | break; |
| 2073 | } |
| 2074 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2075 | ar = (AsyncResult) msg.obj; |
| 2076 | request = (MainThreadRequest) ar.userObj; |
| 2077 | |
| 2078 | if (ar.exception == null) { |
| 2079 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2080 | } else if (ar.exception instanceof CommandException) { |
| 2081 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2082 | CommandException.Error error = |
| 2083 | ((CommandException) (ar.exception)).getCommandError(); |
| 2084 | |
| 2085 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2086 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2087 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2088 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2089 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2090 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2091 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2092 | } else { |
| 2093 | request.result = |
| 2094 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2095 | } |
| 2096 | } else { |
| 2097 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2098 | } |
| 2099 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2100 | notifyRequester(request); |
| 2101 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2102 | |
| 2103 | case CMD_SET_SIM_POWER: { |
| 2104 | request = (MainThreadRequest) msg.obj; |
| 2105 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2106 | request = (MainThreadRequest) msg.obj; |
| 2107 | int stateToSet = |
| 2108 | ((Pair<Integer, IIntegerConsumer>) |
| 2109 | request.argument).first; |
| 2110 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2111 | break; |
| 2112 | } |
| 2113 | case EVENT_SET_SIM_POWER_DONE: { |
| 2114 | ar = (AsyncResult) msg.obj; |
| 2115 | request = (MainThreadRequest) ar.userObj; |
| 2116 | IIntegerConsumer callback = |
| 2117 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2118 | if (ar.exception != null) { |
| 2119 | loge("setSimPower exception: " + ar.exception); |
| 2120 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2121 | .RESULT_ERROR_UNKNOWN; |
| 2122 | if (ar.exception instanceof CommandException) { |
| 2123 | CommandException.Error error = |
| 2124 | ((CommandException) (ar.exception)).getCommandError(); |
| 2125 | if (error == CommandException.Error.SIM_ERR) { |
| 2126 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2127 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2128 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2129 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2130 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2131 | } else { |
| 2132 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2133 | } |
| 2134 | } |
| 2135 | try { |
| 2136 | callback.accept(errorCode); |
| 2137 | } catch (RemoteException e) { |
| 2138 | // Ignore if the remote process is no longer available to call back. |
| 2139 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2140 | } |
| 2141 | } else { |
| 2142 | try { |
| 2143 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2144 | } catch (RemoteException e) { |
| 2145 | // Ignore if the remote process is no longer available to call back. |
| 2146 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2147 | } |
| 2148 | } |
| 2149 | break; |
| 2150 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2151 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2152 | request = (MainThreadRequest) msg.obj; |
| 2153 | |
| 2154 | final Phone phone = getPhoneFromRequest(request); |
| 2155 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2156 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2157 | notifyRequester(request); |
| 2158 | break; |
| 2159 | } |
| 2160 | |
| 2161 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2162 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2163 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2164 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2165 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2166 | request.subId, pair.first /*callingUid*/, |
| 2167 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2171 | ar = (AsyncResult) msg.obj; |
| 2172 | request = (MainThreadRequest) ar.userObj; |
| 2173 | // request.result will be the exception of ar if present, true otherwise. |
| 2174 | // Be cautious not to leave result null which will wait() forever |
| 2175 | request.result = ar.exception != null ? ar.exception : true; |
| 2176 | notifyRequester(request); |
| 2177 | break; |
| 2178 | } |
| 2179 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2180 | request = (MainThreadRequest) msg.obj; |
| 2181 | |
| 2182 | Phone phone = getPhoneFromRequest(request); |
| 2183 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2184 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2185 | notifyRequester(request); |
| 2186 | break; |
| 2187 | } |
| 2188 | |
| 2189 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2190 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2191 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2192 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2193 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2194 | request.subId, pair.first /*callingUid*/, |
| 2195 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2196 | break; |
| 2197 | } |
| 2198 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2199 | ar = (AsyncResult) msg.obj; |
| 2200 | request = (MainThreadRequest) ar.userObj; |
| 2201 | request.result = ar.exception != null ? ar.exception : true; |
| 2202 | notifyRequester(request); |
| 2203 | break; |
| 2204 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2205 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2206 | case CMD_GET_SLICING_CONFIG: { |
| 2207 | request = (MainThreadRequest) msg.obj; |
| 2208 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2209 | request.phone.getSlicingConfig(onCompleted); |
| 2210 | break; |
| 2211 | } |
| 2212 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2213 | ar = (AsyncResult) msg.obj; |
| 2214 | request = (MainThreadRequest) ar.userObj; |
| 2215 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2216 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2217 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2218 | Bundle bundle = new Bundle(); |
| 2219 | int resultCode = 0; |
| 2220 | if (ar.exception != null) { |
| 2221 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2222 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2223 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2224 | } else if (ar.result == null) { |
| 2225 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2226 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2227 | } else { |
| 2228 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2229 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2230 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2234 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2235 | } |
| 2236 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2237 | result.send(resultCode, bundle); |
| 2238 | notifyRequester(request); |
| 2239 | break; |
| 2240 | } |
| 2241 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | request = (MainThreadRequest) msg.obj; |
| 2244 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | PurchasePremiumCapabilityArgument arg = |
| 2246 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2247 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2248 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2249 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2251 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2252 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2253 | ar = (AsyncResult) msg.obj; |
| 2254 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2255 | PurchasePremiumCapabilityArgument arg = |
| 2256 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 | try { |
| 2258 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2259 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2260 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2261 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2262 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2263 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2264 | } catch (RemoteException e) { |
| 2265 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2266 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2267 | + " failed: " + e; |
| 2268 | if (DBG) log(logStr); |
| 2269 | AnomalyReporter.reportAnomaly( |
| 2270 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2271 | } |
| 2272 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2273 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2274 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2275 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2276 | request = (MainThreadRequest) msg.obj; |
| 2277 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2278 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2279 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2280 | notifyRequester(request); |
| 2281 | break; |
| 2282 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | default: |
| 2284 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2285 | break; |
| 2286 | } |
| 2287 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2288 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2289 | private void notifyRequester(MainThreadRequest request) { |
| 2290 | synchronized (request) { |
| 2291 | request.notifyAll(); |
| 2292 | } |
| 2293 | } |
| 2294 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2295 | private void handleNullReturnEvent(Message msg, String command) { |
| 2296 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2297 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2298 | if (ar.exception == null) { |
| 2299 | request.result = true; |
| 2300 | } else { |
| 2301 | request.result = false; |
| 2302 | if (ar.exception instanceof CommandException) { |
| 2303 | loge(command + ": CommandException: " + ar.exception); |
| 2304 | } else { |
| 2305 | loge(command + ": Unknown exception"); |
| 2306 | } |
| 2307 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2308 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2309 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | /** |
| 2313 | * Posts the specified command to be executed on the main thread, |
| 2314 | * waits for the request to complete, and returns the result. |
| 2315 | * @see #sendRequestAsync |
| 2316 | */ |
| 2317 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2318 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2319 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * Posts the specified command to be executed on the main thread, |
| 2324 | * waits for the request to complete, and returns the result. |
| 2325 | * @see #sendRequestAsync |
| 2326 | */ |
| 2327 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2328 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2329 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * Posts the specified command to be executed on the main thread, |
| 2334 | * waits for the request to complete, and returns the result. |
| 2335 | * @see #sendRequestAsync |
| 2336 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2337 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2338 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2339 | } |
| 2340 | |
| 2341 | /** |
| 2342 | * Posts the specified command to be executed on the main thread, |
| 2343 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2344 | * if not timeout or null otherwise. |
| 2345 | * @see #sendRequestAsync |
| 2346 | */ |
| 2347 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2348 | long timeoutInMs) { |
| 2349 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * Posts the specified command to be executed on the main thread, |
| 2354 | * waits for the request to complete, and returns the result. |
| 2355 | * @see #sendRequestAsync |
| 2356 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2357 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2358 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /** |
| 2362 | * Posts the specified command to be executed on the main thread, |
| 2363 | * waits for the request to complete, and returns the result. |
| 2364 | * @see #sendRequestAsync |
| 2365 | */ |
| 2366 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2367 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2368 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2372 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2373 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2374 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2375 | * @see #sendRequestAsync |
| 2376 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2377 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2378 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2380 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2381 | } |
| 2382 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2383 | MainThreadRequest request = null; |
| 2384 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2385 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2386 | } else if (phone != null) { |
| 2387 | request = new MainThreadRequest(argument, phone, workSource); |
| 2388 | } else { |
| 2389 | request = new MainThreadRequest(argument, subId, workSource); |
| 2390 | } |
| 2391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2393 | msg.sendToTarget(); |
| 2394 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2397 | if (timeoutInMs >= 0) { |
| 2398 | // Wait for at least timeoutInMs before returning null request result |
| 2399 | long now = SystemClock.elapsedRealtime(); |
| 2400 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2401 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2402 | try { |
| 2403 | request.wait(deadline - now); |
| 2404 | } catch (InterruptedException e) { |
| 2405 | // Do nothing, go back and check if request is completed or timeout |
| 2406 | } finally { |
| 2407 | now = SystemClock.elapsedRealtime(); |
| 2408 | } |
| 2409 | } |
| 2410 | } else { |
| 2411 | // Wait for the request to complete |
| 2412 | while (request.result == null) { |
| 2413 | try { |
| 2414 | request.wait(); |
| 2415 | } catch (InterruptedException e) { |
| 2416 | // Do nothing, go back and wait until the request is complete |
| 2417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2421 | if (request.result == null) { |
| 2422 | Log.wtf(LOG_TAG, |
| 2423 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2424 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | return request.result; |
| 2426 | } |
| 2427 | |
| 2428 | /** |
| 2429 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2430 | * Posts the specified command to be executed on the main thread, and |
| 2431 | * returns immediately. |
| 2432 | * @see #sendRequest |
| 2433 | */ |
| 2434 | private void sendRequestAsync(int command) { |
| 2435 | mMainThreadHandler.sendEmptyMessage(command); |
| 2436 | } |
| 2437 | |
| 2438 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2439 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2440 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2441 | */ |
| 2442 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2443 | sendRequestAsync(command, argument, null, null); |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2448 | * @see {@link #sendRequest(int,Object)} |
| 2449 | */ |
| 2450 | private void sendRequestAsync( |
| 2451 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2452 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2453 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2454 | msg.sendToTarget(); |
| 2455 | } |
| 2456 | |
| 2457 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2459 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2460 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2461 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | synchronized (PhoneInterfaceManager.class) { |
| 2463 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2464 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | } else { |
| 2466 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2467 | } |
| 2468 | return sInstance; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2473 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2475 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2476 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2478 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2479 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2480 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2482 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2483 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2484 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2485 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2486 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2487 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2488 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2489 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2490 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2491 | mVendorApiLevel = SystemProperties.getInt( |
| 2492 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2493 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2494 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2496 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2497 | |
| 2498 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2499 | // entitlementStatus for satellite service. |
| 2500 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2503 | @VisibleForTesting |
| 2504 | public SharedPreferences getSharedPreferences() { |
| 2505 | return mTelephonySharedPreferences; |
| 2506 | } |
| 2507 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2508 | /** |
| 2509 | * Get the default phone for this device. |
| 2510 | */ |
| 2511 | @VisibleForTesting |
| 2512 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2513 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2514 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2515 | } |
| 2516 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | private void publish() { |
| 2518 | if (DBG) log("publish: " + this); |
| 2519 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2520 | TelephonyFrameworkInitializer |
| 2521 | .getTelephonyServiceManager() |
| 2522 | .getTelephonyServiceRegisterer() |
| 2523 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2526 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2527 | if (request.phone != null) { |
| 2528 | return request.phone; |
| 2529 | } else { |
| 2530 | return getPhoneFromSubId(request.subId); |
| 2531 | } |
| 2532 | } |
| 2533 | |
| 2534 | private Phone getPhoneFromSubId(int subId) { |
| 2535 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2536 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2539 | /** |
| 2540 | * Get phone object associated with a subscription. |
| 2541 | * Return default phone if phone object associated with subscription is null |
| 2542 | * @param subId - subscriptionId |
| 2543 | * @return phone object associated with a subscription or default phone if null. |
| 2544 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2545 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2546 | Phone phone = getPhoneFromSubId(subId); |
| 2547 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2548 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2549 | phone = getDefaultPhone(); |
| 2550 | } |
| 2551 | return phone; |
| 2552 | } |
| 2553 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2554 | @Nullable |
| 2555 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2556 | Phone phone = getPhoneFromRequest(request); |
| 2557 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2558 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2561 | /** |
| 2562 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2563 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2564 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2565 | * @return The Phone associated the sub Id |
| 2566 | */ |
| 2567 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2568 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2571 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2572 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2573 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2574 | } |
| 2575 | |
| 2576 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2577 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2578 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2581 | private boolean isImsAvailableOnDevice() { |
| 2582 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2583 | if (pm == null) { |
| 2584 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2585 | // so do not throw error and allow. |
| 2586 | return true; |
| 2587 | } |
| 2588 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2589 | } |
| 2590 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2591 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2592 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2593 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2594 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2595 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2598 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | if (DBG) log("dial: " + number); |
| 2600 | // No permission check needed here: This is just a wrapper around the |
| 2601 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2602 | // the UI before it does anything. |
| 2603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | final long identity = Binder.clearCallingIdentity(); |
| 2605 | try { |
| 2606 | String url = createTelUrl(number); |
| 2607 | if (url == null) { |
| 2608 | return; |
| 2609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2611 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2612 | PhoneConstants.State state = mCM.getState(subId); |
| 2613 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2614 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2615 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2616 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 | } |
| 2618 | } finally { |
| 2619 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2624 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2627 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | if (DBG) log("call: " + number); |
| 2629 | |
| 2630 | // 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] | 2631 | // need to do a permission check since we're calling startActivityAsUser() |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | // from the context of the phone app. |
| 2633 | enforceCallPermission(); |
| 2634 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2635 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | != AppOpsManager.MODE_ALLOWED) { |
| 2637 | return; |
| 2638 | } |
| 2639 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2640 | enforceTelephonyFeatureWithException(callingPackage, |
| 2641 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2643 | final long identity = Binder.clearCallingIdentity(); |
| 2644 | try { |
| 2645 | String url = createTelUrl(number); |
| 2646 | if (url == null) { |
| 2647 | return; |
| 2648 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | boolean isValid = false; |
| 2651 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2652 | if (slist != null) { |
| 2653 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2654 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2655 | isValid = true; |
| 2656 | break; |
| 2657 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2658 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2659 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | if (!isValid) { |
| 2661 | return; |
| 2662 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2663 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2665 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2666 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2667 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
| 2670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2673 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2674 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2675 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2676 | } |
| 2677 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2678 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2679 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2680 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2681 | } |
| 2682 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2683 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2686 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2687 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2688 | "supplyPinReportResultForSubscriber"); |
| 2689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | final long identity = Binder.clearCallingIdentity(); |
| 2691 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2692 | Phone phone = getPhone(subId); |
| 2693 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | checkSimPin.start(); |
| 2695 | return checkSimPin.unlockSim(null, pin); |
| 2696 | } finally { |
| 2697 | Binder.restoreCallingIdentity(identity); |
| 2698 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2701 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2704 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2705 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2706 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | final long identity = Binder.clearCallingIdentity(); |
| 2708 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2709 | Phone phone = getPhone(subId); |
| 2710 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2711 | checkSimPuk.start(); |
| 2712 | return checkSimPuk.unlockSim(puk, pin); |
| 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
| 2715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2719 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | * a synchronous one. |
| 2721 | */ |
| 2722 | private static class UnlockSim extends Thread { |
| 2723 | |
| 2724 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2725 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | |
| 2727 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2728 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2729 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | |
| 2731 | // For replies from SimCard interface |
| 2732 | private Handler mHandler; |
| 2733 | |
| 2734 | // For async handler to identify request type |
| 2735 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2736 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2737 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2738 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2739 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2741 | UnlockSim(int phoneId, IccCard simCard) { |
| 2742 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2743 | mSimCard = simCard; |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
| 2747 | public void run() { |
| 2748 | Looper.prepare(); |
| 2749 | synchronized (UnlockSim.this) { |
| 2750 | mHandler = new Handler() { |
| 2751 | @Override |
| 2752 | public void handleMessage(Message msg) { |
| 2753 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2754 | switch (msg.what) { |
| 2755 | case SUPPLY_PIN_COMPLETE: |
| 2756 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2757 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2758 | mRetryCount = msg.arg1; |
| 2759 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2760 | CommandException.Error error = null; |
| 2761 | if (ar.exception instanceof CommandException) { |
| 2762 | error = ((CommandException) (ar.exception)) |
| 2763 | .getCommandError(); |
| 2764 | } |
| 2765 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2766 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2767 | } else if (error == CommandException.Error.ABORTED) { |
| 2768 | /* When UiccCardApp dispose, handle message and return |
| 2769 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2770 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2771 | } else { |
| 2772 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2773 | } |
| 2774 | } else { |
| 2775 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2778 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | UnlockSim.this.notifyAll(); |
| 2780 | } |
| 2781 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2782 | case SUPPLY_PIN_DELAYED: |
| 2783 | if(!mDone) { |
| 2784 | String logStr = "Delay in receiving SIM PIN response "; |
| 2785 | if (DBG) log(logStr); |
| 2786 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2787 | } |
| 2788 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | }; |
| 2792 | UnlockSim.this.notifyAll(); |
| 2793 | } |
| 2794 | Looper.loop(); |
| 2795 | } |
| 2796 | |
| 2797 | /* |
| 2798 | * Use PIN or PUK to unlock SIM card |
| 2799 | * |
| 2800 | * If PUK is null, unlock SIM card with PIN |
| 2801 | * |
| 2802 | * 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] | 2803 | * |
| 2804 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2805 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2806 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2807 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | |
| 2809 | while (mHandler == null) { |
| 2810 | try { |
| 2811 | wait(); |
| 2812 | } catch (InterruptedException e) { |
| 2813 | Thread.currentThread().interrupt(); |
| 2814 | } |
| 2815 | } |
| 2816 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2817 | |
| 2818 | if (puk == null) { |
| 2819 | mSimCard.supplyPin(pin, callback); |
| 2820 | } else { |
| 2821 | mSimCard.supplyPuk(puk, pin, callback); |
| 2822 | } |
| 2823 | |
| 2824 | while (!mDone) { |
| 2825 | try { |
| 2826 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2827 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2828 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2829 | wait(); |
| 2830 | } catch (InterruptedException e) { |
| 2831 | // Restore the interrupted status |
| 2832 | Thread.currentThread().interrupt(); |
| 2833 | } |
| 2834 | } |
| 2835 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2836 | int[] resultArray = new int[2]; |
| 2837 | resultArray[0] = mResult; |
| 2838 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2839 | |
| 2840 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2841 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2842 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2843 | // This instance is no longer reused, so quit its thread's looper. |
| 2844 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2845 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2846 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2850 | /** |
| 2851 | * This method has been removed due to privacy and stability concerns. |
| 2852 | */ |
| 2853 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2855 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2856 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2859 | @Override |
| 2860 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2861 | mApp.getSystemService(AppOpsManager.class) |
| 2862 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2863 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2864 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2865 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2866 | // Callers targeting S have no business invoking this method. |
| 2867 | return; |
| 2868 | } |
| 2869 | |
| 2870 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2871 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2872 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2873 | .setCallingPackage(callingPackage) |
| 2874 | .setCallingFeatureId(null) |
| 2875 | .setCallingPid(Binder.getCallingPid()) |
| 2876 | .setCallingUid(Binder.getCallingUid()) |
| 2877 | .setMethod("updateServiceLocation") |
| 2878 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2879 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2880 | .build()); |
| 2881 | // Apps that lack location permission have no business calling this method; |
| 2882 | // however, because no permission was declared in the public API, denials must |
| 2883 | // all be "soft". |
| 2884 | switch (locationResult) { |
| 2885 | case DENIED_HARD: /* fall through */ |
| 2886 | case DENIED_SOFT: |
| 2887 | return; |
| 2888 | } |
| 2889 | |
| 2890 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2893 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2896 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2899 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2900 | @Override |
| 2901 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2902 | return isRadioOnWithFeature(callingPackage, null); |
| 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | @Override |
| 2907 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2908 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2909 | callingFeatureId); |
| 2910 | } |
| 2911 | |
| 2912 | @Deprecated |
| 2913 | @Override |
| 2914 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2915 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2918 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2919 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2920 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2922 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2923 | return false; |
| 2924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2925 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2926 | enforceTelephonyFeatureWithException(callingPackage, |
| 2927 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2928 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | return isRadioOnForSubscriber(subId); |
| 2932 | } finally { |
| 2933 | Binder.restoreCallingIdentity(identity); |
| 2934 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | final long identity = Binder.clearCallingIdentity(); |
| 2939 | try { |
| 2940 | final Phone phone = getPhone(subId); |
| 2941 | if (phone != null) { |
| 2942 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2943 | } else { |
| 2944 | return false; |
| 2945 | } |
| 2946 | } finally { |
| 2947 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2948 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2952 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2954 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2955 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2958 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2959 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2960 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2961 | final long identity = Binder.clearCallingIdentity(); |
| 2962 | try { |
| 2963 | final Phone phone = getPhone(subId); |
| 2964 | if (phone != null) { |
| 2965 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2966 | } |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2969 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2973 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2976 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2977 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2978 | |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | final Phone phone = getPhone(subId); |
| 2982 | if (phone == null) { |
| 2983 | return false; |
| 2984 | } |
| 2985 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2986 | toggleRadioOnOffForSubscriber(subId); |
| 2987 | } |
| 2988 | return true; |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2991 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2992 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2993 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2994 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2995 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2996 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 2997 | if (!mApp.getResources().getBoolean( |
| 2998 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 2999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3000 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3001 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3002 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3003 | /* |
| 3004 | * If any of the Radios are available, it will need to be |
| 3005 | * shutdown. So return true if any Radio is available. |
| 3006 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3007 | final long identity = Binder.clearCallingIdentity(); |
| 3008 | try { |
| 3009 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3010 | Phone phone = PhoneFactory.getPhone(i); |
| 3011 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3012 | } |
| 3013 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3014 | return false; |
| 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3017 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3021 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | enforceModifyPermission(); |
| 3023 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3024 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3025 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3030 | logv("Shutting down Phone " + i); |
| 3031 | shutdownRadioUsingPhoneId(i); |
| 3032 | } |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3039 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3040 | if (phone != null && phone.isRadioAvailable()) { |
| 3041 | phone.shutdownRadio(); |
| 3042 | } |
| 3043 | } |
| 3044 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3045 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3046 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3048 | if (!turnOn) { |
| 3049 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3050 | } |
| 3051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3055 | if (defaultPhone != null) { |
| 3056 | defaultPhone.setRadioPower(turnOn); |
| 3057 | return true; |
| 3058 | } else { |
| 3059 | loge("There's no default phone."); |
| 3060 | return false; |
| 3061 | } |
| 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3064 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3067 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3070 | if (!turnOn) { |
| 3071 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3072 | + ",callingPackage=" + getCurrentPackageName()); |
| 3073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | final long identity = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | final Phone phone = getPhone(subId); |
| 3077 | if (phone != null) { |
| 3078 | phone.setRadioPower(turnOn); |
| 3079 | return true; |
| 3080 | } else { |
| 3081 | return false; |
| 3082 | } |
| 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3085 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3088 | /** |
| 3089 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3090 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3091 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3092 | * powering it off, and these radio off votes will be cleared. |
| 3093 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3094 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3095 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3096 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3097 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3098 | * check its vote. |
| 3099 | * |
| 3100 | * @param subId The subscription ID. |
| 3101 | * @param reason The reason for powering off radio. |
| 3102 | * @return true on success and false on failure. |
| 3103 | */ |
| 3104 | public boolean requestRadioPowerOffForReason(int subId, |
| 3105 | @TelephonyManager.RadioPowerReason int reason) { |
| 3106 | enforceModifyPermission(); |
| 3107 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3108 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3109 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3110 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3111 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3112 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3115 | boolean result = false; |
| 3116 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3117 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3118 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3119 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3120 | if (!result) { |
| 3121 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3122 | } |
| 3123 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | /** |
| 3130 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3131 | * {@link requestRadioPowerOffForReason}. |
| 3132 | * |
| 3133 | * @param subId The subscription ID. |
| 3134 | * @param reason The reason for powering off radio. |
| 3135 | * @return true on success and false on failure. |
| 3136 | */ |
| 3137 | public boolean clearRadioPowerOffForReason(int subId, |
| 3138 | @TelephonyManager.RadioPowerReason int reason) { |
| 3139 | enforceModifyPermission(); |
| 3140 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3141 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3142 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3143 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3144 | final long identity = Binder.clearCallingIdentity(); |
| 3145 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3146 | boolean result = false; |
| 3147 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3148 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3149 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3150 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3151 | if (!result) { |
| 3152 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3153 | } |
| 3154 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | /** |
| 3161 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3162 | * |
| 3163 | * @param subId The subscription ID. |
| 3164 | * @param callingPackage The package making the call. |
| 3165 | * @param callingFeatureId The feature in the package. |
| 3166 | * @return List of reasons for powering off radio. |
| 3167 | */ |
| 3168 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3169 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3170 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3171 | enforceTelephonyFeatureWithException(callingPackage, |
| 3172 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3173 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3174 | final long identity = Binder.clearCallingIdentity(); |
| 3175 | List result = new ArrayList(); |
| 3176 | try { |
| 3177 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3178 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3179 | return result; |
| 3180 | } |
| 3181 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3182 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3183 | if (phone != null) { |
| 3184 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3185 | } else { |
| 3186 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3187 | } |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
| 3190 | } |
| 3191 | return result; |
| 3192 | } |
| 3193 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3194 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3195 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3196 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3199 | enforceTelephonyFeatureWithException(callingPackage, |
| 3200 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3204 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3206 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3207 | phone.getDataSettingsManager().setDataEnabled( |
| 3208 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | return true; |
| 3210 | } else { |
| 3211 | return false; |
| 3212 | } |
| 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3218 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3219 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3220 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3223 | enforceTelephonyFeatureWithException(callingPackage, |
| 3224 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | final long identity = Binder.clearCallingIdentity(); |
| 3227 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3228 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3230 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3231 | phone.getDataSettingsManager().setDataEnabled( |
| 3232 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | return true; |
| 3234 | } else { |
| 3235 | return false; |
| 3236 | } |
| 3237 | } finally { |
| 3238 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3242 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3243 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3244 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3245 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | final long identity = Binder.clearCallingIdentity(); |
| 3248 | try { |
| 3249 | final Phone phone = getPhone(subId); |
| 3250 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3251 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | } else { |
| 3253 | return false; |
| 3254 | } |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3261 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3264 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3265 | enforceCallPermission(); |
| 3266 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3267 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3268 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3270 | final long identity = Binder.clearCallingIdentity(); |
| 3271 | try { |
| 3272 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3273 | return; |
| 3274 | } |
| 3275 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3276 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
| 3279 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3280 | }; |
| 3281 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3282 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3283 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3285 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3286 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | final long identity = Binder.clearCallingIdentity(); |
| 3289 | try { |
| 3290 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3291 | return false; |
| 3292 | } |
| 3293 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3294 | } finally { |
| 3295 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3299 | /** |
| 3300 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3301 | * tag on getCallState Binder call. |
| 3302 | */ |
| 3303 | @Deprecated |
| 3304 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3305 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3306 | if (CompatChanges.isChangeEnabled( |
| 3307 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3308 | Binder.getCallingUid())) { |
| 3309 | // Do not allow this API to be called on API version 31+, it should only be |
| 3310 | // called on old apps using this Binder call directly. |
| 3311 | throw new SecurityException("This method can only be used for applications " |
| 3312 | + "targeting API version 30 or less."); |
| 3313 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | final long identity = Binder.clearCallingIdentity(); |
| 3315 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3316 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3317 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3318 | } finally { |
| 3319 | Binder.restoreCallingIdentity(identity); |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | @Override |
| 3324 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3325 | if (CompatChanges.isChangeEnabled( |
| 3326 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3327 | Binder.getCallingUid())) { |
| 3328 | // Check READ_PHONE_STATE for API version 31+ |
| 3329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3330 | featureId, "getCallStateForSubscription")) { |
| 3331 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3332 | + "targeting API level 31+."); |
| 3333 | } |
| 3334 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3335 | |
| 3336 | enforceTelephonyFeatureWithException(callingPackage, |
| 3337 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3338 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3339 | final long identity = Binder.clearCallingIdentity(); |
| 3340 | try { |
| 3341 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3343 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3344 | } finally { |
| 3345 | Binder.restoreCallingIdentity(identity); |
| 3346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3349 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3350 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3351 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | @Override |
| 3355 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3356 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3357 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3358 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3359 | final long identity = Binder.clearCallingIdentity(); |
| 3360 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3361 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3363 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3364 | } else { |
| 3365 | return PhoneConstantConversions.convertDataState( |
| 3366 | PhoneConstants.DataState.DISCONNECTED); |
| 3367 | } |
| 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3373 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3374 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3375 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3379 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3381 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3385 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3387 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3388 | } else { |
| 3389 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3390 | } |
| 3391 | } finally { |
| 3392 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3393 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3397 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3398 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3399 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3400 | |
| 3401 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3402 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3403 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3404 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3405 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3406 | .setCallingPid(Binder.getCallingPid()) |
| 3407 | .setCallingUid(Binder.getCallingUid()) |
| 3408 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3409 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3410 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3411 | .build()); |
| 3412 | switch (locationResult) { |
| 3413 | case DENIED_HARD: |
| 3414 | throw new SecurityException("Not allowed to access cell location"); |
| 3415 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3416 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3417 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3420 | enforceTelephonyFeatureWithException(callingPackage, |
| 3421 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3422 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3423 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3424 | final long identity = Binder.clearCallingIdentity(); |
| 3425 | try { |
| 3426 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3427 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3428 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
| 3431 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3434 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3435 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3436 | if (!mApp.getResources().getBoolean( |
| 3437 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3438 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3439 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3440 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3441 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3442 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3443 | // registered cell info, so return a NULL country instead. |
| 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3446 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3447 | // Get default phone in this case. |
| 3448 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3449 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3450 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3451 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3452 | if (phone == null) return ""; |
| 3453 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3454 | if (sst == null) return ""; |
| 3455 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3456 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3457 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
| 3460 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3463 | /** |
| 3464 | * This method was removed due to potential issues caused by performing partial |
| 3465 | * updates of service state, and lack of a credible use case. |
| 3466 | * |
| 3467 | * This has the ability to break the telephony implementation by disabling notification of |
| 3468 | * changes in device connectivity. DO NOT USE THIS! |
| 3469 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3470 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3471 | public void enableLocationUpdates() { |
| 3472 | mApp.enforceCallingOrSelfPermission( |
| 3473 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3476 | /** |
| 3477 | * This method was removed due to potential issues caused by performing partial |
| 3478 | * updates of service state, and lack of a credible use case. |
| 3479 | * |
| 3480 | * This has the ability to break the telephony implementation by disabling notification of |
| 3481 | * changes in device connectivity. DO NOT USE THIS! |
| 3482 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3483 | @Override |
| 3484 | public void disableLocationUpdates() { |
| 3485 | mApp.enforceCallingOrSelfPermission( |
| 3486 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | @Override |
| 3490 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3491 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3492 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3493 | try { |
| 3494 | mApp.getSystemService(AppOpsManager.class) |
| 3495 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3496 | } catch (SecurityException e) { |
| 3497 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3498 | throw e; |
| 3499 | } |
| 3500 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3501 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3502 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3503 | throw new SecurityException( |
| 3504 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3505 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3506 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3507 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3508 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3509 | return null; |
| 3510 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3511 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3512 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3513 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3514 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3515 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3517 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3518 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3519 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3520 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3521 | for (CellInfo ci : info) { |
| 3522 | if (ci instanceof CellInfoGsm) { |
| 3523 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3524 | } else if (ci instanceof CellInfoWcdma) { |
| 3525 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3526 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3528 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3531 | private List<CellInfo> getCachedCellInfo() { |
| 3532 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3533 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3534 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3535 | if (info != null) cellInfos.addAll(info); |
| 3536 | } |
| 3537 | return cellInfos; |
| 3538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | |
| 3540 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3541 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3542 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3543 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3544 | |
| 3545 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3546 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3547 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3548 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3549 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3550 | .setCallingPid(Binder.getCallingPid()) |
| 3551 | .setCallingUid(Binder.getCallingUid()) |
| 3552 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3553 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3554 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3555 | .build()); |
| 3556 | switch (locationResult) { |
| 3557 | case DENIED_HARD: |
| 3558 | throw new SecurityException("Not allowed to access cell info"); |
| 3559 | case DENIED_SOFT: |
| 3560 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3563 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3564 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3565 | return getCachedCellInfo(); |
| 3566 | } |
| 3567 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3568 | enforceTelephonyFeatureWithException(callingPackage, |
| 3569 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3570 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3571 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3572 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3576 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3577 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3578 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | if (info != null) cellInfos.addAll(info); |
| 3580 | } |
| 3581 | return cellInfos; |
| 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3587 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3588 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3589 | String callingFeatureId) { |
| 3590 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3591 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3595 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3596 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3597 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3598 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3601 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3602 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3603 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3604 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3605 | |
| 3606 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3607 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3608 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3609 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3610 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3611 | .setCallingPid(Binder.getCallingPid()) |
| 3612 | .setCallingUid(Binder.getCallingUid()) |
| 3613 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3614 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3615 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3616 | .build()); |
| 3617 | switch (locationResult) { |
| 3618 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3619 | if (TelephonyPermissions |
| 3620 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3621 | // Safetynet logging for b/154934934 |
| 3622 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3623 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3624 | throw new SecurityException("Not allowed to access cell info"); |
| 3625 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3626 | if (TelephonyPermissions |
| 3627 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3628 | // Safetynet logging for b/154934934 |
| 3629 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3630 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3631 | try { |
| 3632 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3633 | } catch (RemoteException re) { |
| 3634 | // Drop without consequences |
| 3635 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3636 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3639 | enforceTelephonyFeatureWithException(callingPackage, |
| 3640 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3641 | |
| 3642 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3643 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3644 | |
| 3645 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3646 | } |
| 3647 | |
| 3648 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3649 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3650 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3651 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | |
| 3653 | final long identity = Binder.clearCallingIdentity(); |
| 3654 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3655 | Phone phone = getPhone(subId); |
| 3656 | if (phone == null) { |
| 3657 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3658 | } else { |
| 3659 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | } finally { |
| 3662 | Binder.restoreCallingIdentity(identity); |
| 3663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3666 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3667 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3668 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3669 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3670 | return null; |
| 3671 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3672 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3673 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3674 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3675 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3676 | return null; |
| 3677 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3678 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3679 | enforceTelephonyFeatureWithException(callingPackage, |
| 3680 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | return phone.getImei(); |
| 3685 | } finally { |
| 3686 | Binder.restoreCallingIdentity(identity); |
| 3687 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3691 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3692 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3693 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3694 | callingFeatureId, "getPrimaryImei")) { |
| 3695 | throw new SecurityException("Caller does not have permission"); |
| 3696 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3697 | |
| 3698 | enforceTelephonyFeatureWithException(callingPackage, |
| 3699 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3700 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3701 | final long identity = Binder.clearCallingIdentity(); |
| 3702 | try { |
| 3703 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3704 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3705 | return phone.getImei(); |
| 3706 | } |
| 3707 | } |
| 3708 | throw new UnsupportedOperationException("Operation not supported"); |
| 3709 | } finally { |
| 3710 | Binder.restoreCallingIdentity(identity); |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3715 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3716 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3717 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3718 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3719 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3720 | String tac = null; |
| 3721 | if (phone != null) { |
| 3722 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3723 | try { |
| 3724 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3725 | } catch (IndexOutOfBoundsException e) { |
| 3726 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3727 | return null; |
| 3728 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3729 | } |
| 3730 | return tac; |
| 3731 | } |
| 3732 | |
| 3733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3734 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3735 | try { |
| 3736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3737 | } catch (SecurityException se) { |
| 3738 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3739 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3740 | + Binder.getCallingUid()); |
| 3741 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3742 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3743 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3744 | return null; |
| 3745 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3746 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3747 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3748 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3749 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3750 | return null; |
| 3751 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3752 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3753 | enforceTelephonyFeatureWithException(callingPackage, |
| 3754 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3756 | final long identity = Binder.clearCallingIdentity(); |
| 3757 | try { |
| 3758 | return phone.getMeid(); |
| 3759 | } finally { |
| 3760 | Binder.restoreCallingIdentity(identity); |
| 3761 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3765 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3766 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3767 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3768 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3769 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3770 | String manufacturerCode = null; |
| 3771 | if (phone != null) { |
| 3772 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3773 | try { |
| 3774 | manufacturerCode = |
| 3775 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3776 | } catch (IndexOutOfBoundsException e) { |
| 3777 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3778 | return null; |
| 3779 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3780 | } |
| 3781 | return manufacturerCode; |
| 3782 | } |
| 3783 | |
| 3784 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3785 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3786 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3787 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3788 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3789 | return null; |
| 3790 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3791 | int subId = phone.getSubId(); |
| 3792 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3793 | mApp, subId, callingPackage, callingFeatureId, |
| 3794 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3795 | return null; |
| 3796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3798 | enforceTelephonyFeatureWithException(callingPackage, |
| 3799 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3800 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3801 | final long identity = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | return phone.getDeviceSvn(); |
| 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
| 3806 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3809 | @Override |
| 3810 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3811 | if (!mApp.getResources().getBoolean( |
| 3812 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3813 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3814 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3815 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3817 | final long identity = Binder.clearCallingIdentity(); |
| 3818 | try { |
| 3819 | final Phone phone = getPhone(subId); |
| 3820 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3821 | } finally { |
| 3822 | Binder.restoreCallingIdentity(identity); |
| 3823 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | @Override |
| 3827 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3828 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3829 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 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 ? null : phone.getCarrierName(); |
| 3835 | } finally { |
| 3836 | Binder.restoreCallingIdentity(identity); |
| 3837 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3840 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3841 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3842 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3843 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3844 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | final Phone phone = getPhone(subId); |
| 3848 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3849 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3850 | } finally { |
| 3851 | Binder.restoreCallingIdentity(identity); |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3856 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3857 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3858 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3859 | "getSubscriptionSpecificCarrierName"); |
| 3860 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3861 | final long identity = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3864 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(identity); |
| 3867 | } |
| 3868 | } |
| 3869 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3870 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3871 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3872 | if (!isSubscriptionMccMnc) { |
| 3873 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3874 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3875 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3876 | if (phone == null) { |
| 3877 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3878 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3879 | |
| 3880 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3881 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3882 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3883 | final long identity = Binder.clearCallingIdentity(); |
| 3884 | try { |
| 3885 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(identity); |
| 3888 | } |
| 3889 | } |
| 3890 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3891 | // |
| 3892 | // Internal helper methods. |
| 3893 | // |
| 3894 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3895 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3896 | * Make sure the caller is the calling package itself |
| 3897 | * |
| 3898 | * @throws SecurityException if the caller is not the calling package |
| 3899 | */ |
| 3900 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3901 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3902 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3903 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3904 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3905 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3906 | } catch (PackageManager.NameNotFoundException e) { |
| 3907 | // packageUid is -1 |
| 3908 | } |
| 3909 | if (packageUid != callingUid) { |
| 3910 | throw new SecurityException(message + ": Package " + callingPackage |
| 3911 | + " does not belong to " + callingUid); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3916 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3917 | * |
| 3918 | * @throws SecurityException if the caller does not have the required permission |
| 3919 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3920 | @VisibleForTesting |
| 3921 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3922 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3923 | } |
| 3924 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3925 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3926 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3927 | * |
| 3928 | * @throws SecurityException if the caller does not have the required permission |
| 3929 | */ |
| 3930 | @VisibleForTesting |
| 3931 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3932 | enforceReadPermission(null); |
| 3933 | } |
| 3934 | |
| 3935 | /** |
| 3936 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3937 | * |
| 3938 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3939 | */ |
| 3940 | @VisibleForTesting |
| 3941 | public void enforceReadPermission(String msg) { |
| 3942 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3945 | private void enforceActiveEmergencySessionPermission() { |
| 3946 | mApp.enforceCallingOrSelfPermission( |
| 3947 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3948 | } |
| 3949 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3950 | /** |
| 3951 | * Make sure the caller has the CALL_PHONE permission. |
| 3952 | * |
| 3953 | * @throws SecurityException if the caller does not have the required permission |
| 3954 | */ |
| 3955 | private void enforceCallPermission() { |
| 3956 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3957 | } |
| 3958 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3959 | private void enforceSettingsPermission() { |
| 3960 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3963 | private void enforceRebootPermission() { |
| 3964 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3965 | } |
| 3966 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3967 | /** |
| 3968 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3969 | * @param message - log message to print. |
| 3970 | * @throws SecurityException if the caller does not have the required permission |
| 3971 | */ |
| 3972 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3973 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3974 | } |
| 3975 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3976 | /** |
| 3977 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3978 | * @param message - log message to print. |
| 3979 | * @throws SecurityException if the caller does not have the required permission |
| 3980 | */ |
| 3981 | private void enforcePackageUsageStatsPermission(String message) { |
| 3982 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3983 | } |
| 3984 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3985 | private String createTelUrl(String number) { |
| 3986 | if (TextUtils.isEmpty(number)) { |
| 3987 | return null; |
| 3988 | } |
| 3989 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3990 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3993 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3994 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3997 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3998 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4001 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4002 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4005 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4006 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4007 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4010 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4011 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4012 | if (!mApp.getResources().getBoolean( |
| 4013 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4014 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4015 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4016 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4018 | final long identity = Binder.clearCallingIdentity(); |
| 4019 | try { |
| 4020 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4021 | if (phone == null) { |
| 4022 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4023 | } else { |
| 4024 | return phone.getPhoneType(); |
| 4025 | } |
| 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | /** |
| 4032 | * Returns the CDMA ERI icon index to display |
| 4033 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4035 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4036 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4037 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4041 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4042 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4043 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4044 | mApp, subId, callingPackage, callingFeatureId, |
| 4045 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4046 | return -1; |
| 4047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4049 | enforceTelephonyFeatureWithException(callingPackage, |
| 4050 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4051 | "getCdmaEriIconIndexForSubscriber"); |
| 4052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | final Phone phone = getPhone(subId); |
| 4056 | if (phone != null) { |
| 4057 | return phone.getCdmaEriIconIndex(); |
| 4058 | } else { |
| 4059 | return -1; |
| 4060 | } |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Returns the CDMA ERI icon mode, |
| 4068 | * 0 - ON |
| 4069 | * 1 - FLASHING |
| 4070 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4071 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4072 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4073 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4074 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4077 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4078 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4079 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4080 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4081 | mApp, subId, callingPackage, callingFeatureId, |
| 4082 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4083 | return -1; |
| 4084 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | final Phone phone = getPhone(subId); |
| 4089 | if (phone != null) { |
| 4090 | return phone.getCdmaEriIconMode(); |
| 4091 | } else { |
| 4092 | return -1; |
| 4093 | } |
| 4094 | } finally { |
| 4095 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4096 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** |
| 4100 | * Returns the CDMA ERI text, |
| 4101 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4102 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4103 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4104 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4105 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4108 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4109 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4110 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4111 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4112 | mApp, subId, callingPackage, callingFeatureId, |
| 4113 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4114 | return null; |
| 4115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | |
| 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | final Phone phone = getPhone(subId); |
| 4120 | if (phone != null) { |
| 4121 | return phone.getCdmaEriText(); |
| 4122 | } else { |
| 4123 | return null; |
| 4124 | } |
| 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4131 | * Returns the CDMA MDN. |
| 4132 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4133 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4134 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4135 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4136 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4137 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4138 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4139 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4140 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4145 | return phone.getLine1Number(); |
| 4146 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4147 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | return null; |
| 4149 | } |
| 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | /** |
| 4156 | * Returns the CDMA MIN. |
| 4157 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4158 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4159 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4161 | mApp, subId, "getCdmaMin"); |
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, "getCdmaMin"); |
| 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); |
| 4169 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4170 | return phone.getCdmaMin(); |
| 4171 | } else { |
| 4172 | return null; |
| 4173 | } |
| 4174 | } finally { |
| 4175 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4176 | } |
| 4177 | } |
| 4178 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4179 | @Override |
| 4180 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4181 | INumberVerificationCallback callback, String callingPackage) { |
| 4182 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4183 | != PERMISSION_GRANTED) { |
| 4184 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4185 | } |
| 4186 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4187 | |
| 4188 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4189 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4190 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4191 | + "calling package: " + callingPackage |
| 4192 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4193 | } |
| 4194 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4195 | enforceTelephonyFeatureWithException(callingPackage, |
| 4196 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4197 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4198 | if (range == null) { |
| 4199 | throw new NullPointerException("Range must be non-null"); |
| 4200 | } |
| 4201 | |
| 4202 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4203 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4204 | |
| 4205 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4206 | } |
| 4207 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4208 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4209 | * Returns true if CDMA provisioning needs to run. |
| 4210 | */ |
| 4211 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4213 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4217 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4224 | * Sets the voice mail number of a given subId. |
| 4225 | */ |
| 4226 | @Override |
| 4227 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4228 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4229 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4230 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4231 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4232 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4234 | final long identity = Binder.clearCallingIdentity(); |
| 4235 | try { |
| 4236 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4237 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4238 | return success; |
| 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(identity); |
| 4241 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4244 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4245 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4246 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4247 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4248 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4249 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4250 | throw new SecurityException("caller must be system dialer"); |
| 4251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4253 | enforceTelephonyFeatureWithException(callingPackage, |
| 4254 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4255 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | final long identity = Binder.clearCallingIdentity(); |
| 4257 | try { |
| 4258 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4259 | if (phoneAccountHandle == null) { |
| 4260 | return null; |
| 4261 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4262 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4265 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4270 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4271 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4272 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4273 | mApp, subId, callingPackage, callingFeatureId, |
| 4274 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4275 | return null; |
| 4276 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4278 | enforceTelephonyFeatureWithException(callingPackage, |
| 4279 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4280 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4281 | final long identity = Binder.clearCallingIdentity(); |
| 4282 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4283 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(identity); |
| 4286 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4290 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4291 | VisualVoicemailSmsFilterSettings settings) { |
| 4292 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4293 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4294 | enforceTelephonyFeatureWithException(callingPackage, |
| 4295 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | final long identity = Binder.clearCallingIdentity(); |
| 4297 | try { |
| 4298 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4299 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4300 | } finally { |
| 4301 | Binder.restoreCallingIdentity(identity); |
| 4302 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4306 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4307 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4308 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4309 | enforceTelephonyFeatureWithException(callingPackage, |
| 4310 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4311 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4315 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4322 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4323 | String callingPackage, int subId) { |
| 4324 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | |
| 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4329 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4330 | } finally { |
| 4331 | Binder.restoreCallingIdentity(identity); |
| 4332 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4336 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4337 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | |
| 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
| 4341 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4342 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | } finally { |
| 4344 | Binder.restoreCallingIdentity(identity); |
| 4345 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4349 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4350 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4351 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4352 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4353 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4354 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4355 | |
| 4356 | enforceTelephonyFeatureWithException(callingPackage, |
| 4357 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4358 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4359 | SmsController smsController = PhoneFactory.getSmsController(); |
Nikhil Kumar | deebd75 | 2024-08-14 14:49:06 +0100 | [diff] [blame] | 4360 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, |
| 4361 | Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number, |
| 4362 | port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4363 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4364 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4365 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4366 | * Sets the voice activation state of a given subId. |
| 4367 | */ |
| 4368 | @Override |
| 4369 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4371 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4373 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4374 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | final long identity = Binder.clearCallingIdentity(); |
| 4377 | try { |
| 4378 | final Phone phone = getPhone(subId); |
| 4379 | if (phone != null) { |
| 4380 | phone.setVoiceActivationState(activationState); |
| 4381 | } else { |
| 4382 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4383 | } |
| 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * Sets the data activation state of a given subId. |
| 4391 | */ |
| 4392 | @Override |
| 4393 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4395 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4397 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4398 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | final long identity = Binder.clearCallingIdentity(); |
| 4401 | try { |
| 4402 | final Phone phone = getPhone(subId); |
| 4403 | if (phone != null) { |
| 4404 | phone.setDataActivationState(activationState); |
| 4405 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4406 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | } |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | /** |
| 4414 | * Returns the voice activation state of a given subId. |
| 4415 | */ |
| 4416 | @Override |
| 4417 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4418 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4419 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4420 | enforceTelephonyFeatureWithException(callingPackage, |
| 4421 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4422 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4423 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4424 | final long identity = Binder.clearCallingIdentity(); |
| 4425 | try { |
| 4426 | if (phone != null) { |
| 4427 | return phone.getVoiceActivationState(); |
| 4428 | } else { |
| 4429 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4430 | } |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | /** |
| 4437 | * Returns the data activation state of a given subId. |
| 4438 | */ |
| 4439 | @Override |
| 4440 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4441 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4443 | enforceTelephonyFeatureWithException(callingPackage, |
| 4444 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4445 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4446 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4447 | final long identity = Binder.clearCallingIdentity(); |
| 4448 | try { |
| 4449 | if (phone != null) { |
| 4450 | return phone.getDataActivationState(); |
| 4451 | } else { |
| 4452 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4453 | } |
| 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4460 | * Returns the unread count of voicemails for a subId |
| 4461 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4462 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4463 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4464 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4466 | mApp, subId, callingPackage, callingFeatureId, |
| 4467 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4468 | return 0; |
| 4469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
| 4472 | final Phone phone = getPhone(subId); |
| 4473 | if (phone != null) { |
| 4474 | return phone.getVoiceMessageCount(); |
| 4475 | } else { |
| 4476 | return 0; |
| 4477 | } |
| 4478 | } finally { |
| 4479 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4480 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4484 | * returns true, if the device is in a state where both voice and data |
| 4485 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4486 | */ |
| 4487 | @Override |
| 4488 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4489 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4490 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | final long identity = Binder.clearCallingIdentity(); |
| 4493 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4494 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(identity); |
| 4497 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4501 | * Send the dialer code if called from the current default dialer or the caller has |
| 4502 | * carrier privilege. |
| 4503 | * @param inputCode The dialer code to send |
| 4504 | */ |
| 4505 | @Override |
| 4506 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4507 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4509 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4510 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4511 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4512 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4513 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4516 | enforceTelephonyFeatureWithException(callingPackage, |
| 4517 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4521 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(identity); |
| 4524 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4525 | } |
| 4526 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4527 | @Override |
| 4528 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4529 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4530 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4531 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4532 | |
| 4533 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4534 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4535 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
| 4538 | if (!isActiveSubscription(subId)) { |
| 4539 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4540 | } |
| 4541 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4542 | } finally { |
| 4543 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4544 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4547 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4548 | public boolean isInEmergencySmsMode() { |
| 4549 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4550 | |
| 4551 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4552 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4553 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
| 4556 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4557 | if (phone.isInEmergencySmsMode()) { |
| 4558 | return true; |
| 4559 | } |
| 4560 | } |
| 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
| 4563 | } |
| 4564 | return false; |
| 4565 | } |
| 4566 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4567 | /** |
| 4568 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4569 | * @param subId The subscription to use to check the configuration. |
| 4570 | * @param c The callback that will be used to send the result. |
| 4571 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4572 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4573 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4574 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4575 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4576 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4577 | |
| 4578 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4579 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4580 | "IMS not available on device."); |
| 4581 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | final long token = Binder.clearCallingIdentity(); |
| 4583 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4584 | int slotId = getSlotIndexOrException(subId); |
| 4585 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4586 | |
| 4587 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4588 | if (controller != null) { |
| 4589 | ImsManager imsManager = controller.getImsManager(subId); |
| 4590 | if (imsManager != null) { |
| 4591 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4592 | } else { |
| 4593 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4594 | } |
| 4595 | } else { |
| 4596 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4597 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4598 | } catch (ImsException e) { |
| 4599 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(token); |
| 4602 | } |
| 4603 | } |
| 4604 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4605 | /** |
| 4606 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4607 | * @param subId The subscription to use to check the configuration. |
| 4608 | * @param c The callback that will be used to send the result. |
| 4609 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4610 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4611 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4612 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4613 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4614 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4615 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4616 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4617 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4618 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4619 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4620 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4621 | if (controller != null) { |
| 4622 | ImsManager imsManager = controller.getImsManager(subId); |
| 4623 | if (imsManager != null) { |
| 4624 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4625 | } else { |
| 4626 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4627 | + "is inactive, ignoring unregister."); |
| 4628 | // If the ImsManager is not valid, just return, since the callback |
| 4629 | // will already have been removed internally. |
| 4630 | } |
| 4631 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4632 | } finally { |
| 4633 | Binder.restoreCallingIdentity(token); |
| 4634 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4635 | } |
| 4636 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4637 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4638 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4639 | * @param subId The subscription to use to check the configuration. |
| 4640 | * @param c The callback that will be used to send the result. |
| 4641 | */ |
| 4642 | @Override |
| 4643 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4644 | throws RemoteException { |
| 4645 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4646 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4647 | |
| 4648 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4650 | "IMS not available on device."); |
| 4651 | } |
| 4652 | final long token = Binder.clearCallingIdentity(); |
| 4653 | try { |
| 4654 | int slotId = getSlotIndexOrException(subId); |
| 4655 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4656 | |
| 4657 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4658 | if (controller != null) { |
| 4659 | ImsManager imsManager = controller.getImsManager(subId); |
| 4660 | if (imsManager != null) { |
| 4661 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4662 | } else { |
| 4663 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4664 | } |
| 4665 | } else { |
| 4666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4667 | } |
| 4668 | } catch (ImsException e) { |
| 4669 | throw new ServiceSpecificException(e.getCode()); |
| 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(token); |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | /** |
| 4676 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4677 | * @param subId The subscription to use to check the configuration. |
| 4678 | * @param c The callback that will be used to send the result. |
| 4679 | */ |
| 4680 | @Override |
| 4681 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4682 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4683 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4684 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4685 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4686 | } |
| 4687 | final long token = Binder.clearCallingIdentity(); |
| 4688 | |
| 4689 | try { |
| 4690 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4691 | if (controller != null) { |
| 4692 | ImsManager imsManager = controller.getImsManager(subId); |
| 4693 | if (imsManager != null) { |
| 4694 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4695 | } else { |
| 4696 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4697 | + "is inactive, ignoring unregister."); |
| 4698 | // If the ImsManager is not valid, just return, since the callback |
| 4699 | // will already have been removed internally. |
| 4700 | } |
| 4701 | } |
| 4702 | } finally { |
| 4703 | Binder.restoreCallingIdentity(token); |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4708 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4709 | */ |
| 4710 | @Override |
| 4711 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4712 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4713 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4715 | "IMS not available on device."); |
| 4716 | } |
| 4717 | final long token = Binder.clearCallingIdentity(); |
| 4718 | try { |
| 4719 | Phone phone = getPhone(subId); |
| 4720 | if (phone == null) { |
| 4721 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4722 | + subId + "'"); |
| 4723 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4724 | } |
| 4725 | phone.getImsRegistrationState(regState -> { |
| 4726 | try { |
| 4727 | consumer.accept((regState == null) |
| 4728 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4729 | } catch (RemoteException e) { |
| 4730 | // Ignore if the remote process is no longer available to call back. |
| 4731 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4732 | } |
| 4733 | }); |
| 4734 | } finally { |
| 4735 | Binder.restoreCallingIdentity(token); |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | /** |
| 4740 | * Get the transport type for the IMS service registration state. |
| 4741 | */ |
| 4742 | @Override |
| 4743 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4744 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4745 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4746 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4747 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4748 | "IMS not available on device."); |
| 4749 | } |
| 4750 | final long token = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | Phone phone = getPhone(subId); |
| 4753 | if (phone == null) { |
| 4754 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4755 | + subId + "'"); |
| 4756 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4757 | } |
| 4758 | phone.getImsRegistrationTech(regTech -> { |
| 4759 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4760 | int regTechConverted = (regTech == null) |
| 4761 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4762 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4763 | regTechConverted); |
| 4764 | try { |
| 4765 | consumer.accept(regTechConverted); |
| 4766 | } catch (RemoteException e) { |
| 4767 | // Ignore if the remote process is no longer available to call back. |
| 4768 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4769 | } |
| 4770 | }); |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(token); |
| 4773 | } |
| 4774 | } |
| 4775 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4778 | * @param subId The subscription to use to check the configuration. |
| 4779 | * @param c The callback that will be used to send the result. |
| 4780 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4781 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4782 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4783 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4784 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4785 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4786 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4788 | "IMS not available on device."); |
| 4789 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4790 | final long token = Binder.clearCallingIdentity(); |
| 4791 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4792 | int slotId = getSlotIndexOrException(subId); |
| 4793 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4794 | |
| 4795 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4796 | if (controller != null) { |
| 4797 | ImsManager imsManager = controller.getImsManager(subId); |
| 4798 | if (imsManager != null) { |
| 4799 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4800 | } else { |
| 4801 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4802 | } |
| 4803 | } else { |
| 4804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4805 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4806 | } catch (ImsException e) { |
| 4807 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4808 | } finally { |
| 4809 | Binder.restoreCallingIdentity(token); |
| 4810 | } |
| 4811 | } |
| 4812 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4813 | /** |
| 4814 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4815 | * @param subId The subscription to use to check the configuration. |
| 4816 | * @param c The callback that will be used to send the result. |
| 4817 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4818 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4819 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4820 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4821 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4822 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4823 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4824 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4825 | |
| 4826 | final long token = Binder.clearCallingIdentity(); |
| 4827 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4828 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4829 | if (controller != null) { |
| 4830 | ImsManager imsManager = controller.getImsManager(subId); |
| 4831 | if (imsManager != null) { |
| 4832 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4833 | } else { |
| 4834 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4835 | + " is inactive, ignoring unregister."); |
| 4836 | // If the ImsManager is not valid, just return, since the callback |
| 4837 | // will already have been removed internally. |
| 4838 | } |
| 4839 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4840 | } finally { |
| 4841 | Binder.restoreCallingIdentity(token); |
| 4842 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4846 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4847 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4848 | |
| 4849 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4850 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4851 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4852 | final long token = Binder.clearCallingIdentity(); |
| 4853 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4854 | int slotId = getSlotIndexOrException(subId); |
| 4855 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4856 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4857 | } catch (com.android.ims.ImsException e) { |
| 4858 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4859 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4860 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4861 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4862 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4863 | } finally { |
| 4864 | Binder.restoreCallingIdentity(token); |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4869 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4870 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4871 | |
| 4872 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4873 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4874 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4875 | final long token = Binder.clearCallingIdentity(); |
| 4876 | try { |
| 4877 | Phone phone = getPhone(subId); |
| 4878 | if (phone == null) return false; |
| 4879 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4880 | } catch (com.android.ims.ImsException e) { |
| 4881 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4882 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(token); |
| 4885 | } |
| 4886 | } |
| 4887 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4888 | /** |
| 4889 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4890 | * subscription. |
| 4891 | * @param subId The subscription to use to check the configuration. |
| 4892 | * @param callback The callback that will be used to send the result. |
| 4893 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4894 | * @param transportType The transport type of the MmTelFeature capability. |
| 4895 | */ |
| 4896 | @Override |
| 4897 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4898 | int transportType) { |
| 4899 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4900 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4901 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4902 | "IMS not available on device."); |
| 4903 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4904 | final long token = Binder.clearCallingIdentity(); |
| 4905 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4906 | int slotId = getSlotIndex(subId); |
| 4907 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4908 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4909 | + subId + "'"); |
| 4910 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4911 | } |
| 4912 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4913 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4914 | transportType, aBoolean -> { |
| 4915 | try { |
| 4916 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4917 | } catch (RemoteException e) { |
| 4918 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4919 | + "running. Ignore"); |
| 4920 | } |
| 4921 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4922 | } catch (ImsException e) { |
| 4923 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4924 | } finally { |
| 4925 | Binder.restoreCallingIdentity(token); |
| 4926 | } |
| 4927 | } |
| 4928 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4929 | /** |
| 4930 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4931 | * @param subId The subscription to use to check the configuration. |
| 4932 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4933 | @Override |
| 4934 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4935 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4936 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4937 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4938 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4939 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4940 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4941 | final long token = Binder.clearCallingIdentity(); |
| 4942 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4943 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4944 | // 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] | 4945 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4946 | } catch (ImsException e) { |
| 4947 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(token); |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4954 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4956 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4957 | |
| 4958 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4959 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4960 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4961 | final long identity = Binder.clearCallingIdentity(); |
| 4962 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4963 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4964 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4965 | // 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] | 4966 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4967 | } catch (ImsException e) { |
| 4968 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
| 4972 | } |
| 4973 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4974 | /** |
| 4975 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4976 | * @param subId The subscription to use to check the configuration. |
| 4977 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4978 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4979 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4980 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4981 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4982 | |
| 4983 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4984 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4985 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4988 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4989 | // 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] | 4990 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4991 | } catch (ImsException e) { |
| 4992 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4999 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5001 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5002 | |
| 5003 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5004 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5005 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5008 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5009 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5010 | // 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] | 5011 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5012 | } catch (ImsException e) { |
| 5013 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(identity); |
| 5016 | } |
| 5017 | } |
| 5018 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5019 | /** |
| 5020 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5021 | * @param subId The subscription to use to check the configuration. |
| 5022 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5023 | @Override |
| 5024 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5025 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5026 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5027 | |
| 5028 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5029 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5030 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5031 | final long identity = Binder.clearCallingIdentity(); |
| 5032 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5033 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5034 | // 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] | 5035 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5036 | } catch (ImsException e) { |
| 5037 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5044 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5045 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5046 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5047 | |
| 5048 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5049 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5050 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5051 | final long identity = Binder.clearCallingIdentity(); |
| 5052 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5053 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5054 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5055 | // 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] | 5056 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5057 | } catch (ImsException e) { |
| 5058 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
| 5062 | } |
| 5063 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5064 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5065 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5066 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5067 | * @param subId The subscription to use to check the configuration. |
| 5068 | */ |
| 5069 | @Override |
| 5070 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5071 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5072 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5073 | |
| 5074 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5075 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5076 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5079 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5080 | // 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] | 5081 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5082 | } catch (ImsException e) { |
| 5083 | throw new ServiceSpecificException(e.getCode()); |
| 5084 | } finally { |
| 5085 | Binder.restoreCallingIdentity(identity); |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | /** |
| 5090 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5091 | * Requires MODIFY_PHONE_STATE permission. |
| 5092 | * @param subId The subscription to use to check the configuration. |
| 5093 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5094 | * false otherwise |
| 5095 | */ |
| 5096 | @Override |
| 5097 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5099 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5100 | |
| 5101 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5102 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5103 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5106 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5107 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5108 | // 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] | 5109 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5110 | } catch (ImsException e) { |
| 5111 | throw new ServiceSpecificException(e.getCode()); |
| 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
| 5115 | } |
| 5116 | |
| 5117 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5118 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5119 | * @param subId The subscription to use to check the configuration. |
| 5120 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5121 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5122 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5123 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5124 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5125 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5126 | |
| 5127 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5128 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5129 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5132 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5133 | // 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] | 5134 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5135 | } catch (ImsException e) { |
| 5136 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5137 | } finally { |
| 5138 | Binder.restoreCallingIdentity(identity); |
| 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5143 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5145 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5146 | |
| 5147 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5148 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5149 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5152 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5153 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5154 | // 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] | 5155 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5156 | } catch (ImsException e) { |
| 5157 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5158 | } finally { |
| 5159 | Binder.restoreCallingIdentity(identity); |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | @Override |
| 5164 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5166 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5167 | |
| 5168 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5169 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5170 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5171 | final long identity = Binder.clearCallingIdentity(); |
| 5172 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5173 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5174 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5175 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5176 | } catch (ImsException e) { |
| 5177 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5178 | } finally { |
| 5179 | Binder.restoreCallingIdentity(identity); |
| 5180 | } |
| 5181 | } |
| 5182 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5183 | /** |
| 5184 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5185 | * @param subId The subscription to use to check the configuration. |
| 5186 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5187 | @Override |
| 5188 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5189 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5190 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5191 | |
| 5192 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5193 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5194 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5195 | final long identity = Binder.clearCallingIdentity(); |
| 5196 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5197 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5198 | // 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] | 5199 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5200 | } catch (ImsException e) { |
| 5201 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5202 | } finally { |
| 5203 | Binder.restoreCallingIdentity(identity); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | @Override |
| 5208 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5210 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5211 | |
| 5212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5213 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5214 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5215 | final long identity = Binder.clearCallingIdentity(); |
| 5216 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5217 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5218 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5219 | // 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] | 5220 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5221 | } catch (ImsException e) { |
| 5222 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
| 5225 | } |
| 5226 | } |
| 5227 | |
| 5228 | @Override |
| 5229 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5230 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5231 | |
| 5232 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5233 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5234 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5235 | final long identity = Binder.clearCallingIdentity(); |
| 5236 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5237 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5238 | // 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] | 5239 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5240 | } catch (ImsException e) { |
| 5241 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5242 | } finally { |
| 5243 | Binder.restoreCallingIdentity(identity); |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | @Override |
| 5248 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5249 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5250 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5251 | |
| 5252 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5253 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5254 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5257 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5258 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5259 | // 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] | 5260 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5261 | } catch (ImsException e) { |
| 5262 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | @Override |
| 5269 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5271 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5272 | |
| 5273 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5274 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5275 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5276 | final long identity = Binder.clearCallingIdentity(); |
| 5277 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5278 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5279 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5280 | // 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] | 5281 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5282 | } catch (ImsException e) { |
| 5283 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
| 5287 | } |
| 5288 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5289 | /** |
| 5290 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5291 | * @param subId The subscription to use to check the configuration. |
| 5292 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5293 | @Override |
| 5294 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5295 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5296 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5297 | |
| 5298 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5299 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5300 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5303 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5304 | // 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] | 5305 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5306 | } catch (ImsException e) { |
| 5307 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5308 | } finally { |
| 5309 | Binder.restoreCallingIdentity(identity); |
| 5310 | } |
| 5311 | } |
| 5312 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5313 | @Override |
| 5314 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5315 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5316 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5317 | final long identity = Binder.clearCallingIdentity(); |
| 5318 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5319 | if (!isImsAvailableOnDevice()) { |
| 5320 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5321 | "IMS not available on device."); |
| 5322 | } |
| 5323 | int slotId = getSlotIndexOrException(subId); |
| 5324 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5325 | |
| 5326 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5327 | if (controller != null) { |
| 5328 | ImsManager imsManager = controller.getImsManager(subId); |
| 5329 | if (imsManager != null) { |
| 5330 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5331 | } else { |
| 5332 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5333 | } |
| 5334 | } else { |
| 5335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5336 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5337 | } catch (ImsException e) { |
| 5338 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | @Override |
| 5345 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5346 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
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(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5349 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5350 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5351 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5352 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5353 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5354 | if (controller != null) { |
| 5355 | ImsManager imsManager = controller.getImsManager(subId); |
| 5356 | if (imsManager != null) { |
| 5357 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5358 | } else { |
| 5359 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5360 | + " is inactive, ignoring unregister."); |
| 5361 | // If the ImsManager is not valid, just return, since the callback will already |
| 5362 | // have been removed internally. |
| 5363 | } |
| 5364 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
| 5367 | } |
| 5368 | } |
| 5369 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5370 | @Override |
| 5371 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5372 | IFeatureProvisioningCallback callback) { |
| 5373 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5374 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5375 | |
| 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5378 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5379 | } |
| 5380 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5381 | try { |
| 5382 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5383 | if (controller == null) { |
| 5384 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5385 | "Device does not support IMS"); |
| 5386 | } |
| 5387 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5388 | } finally { |
| 5389 | Binder.restoreCallingIdentity(identity); |
| 5390 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | @Override |
| 5394 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5395 | IFeatureProvisioningCallback callback) { |
| 5396 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5397 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5398 | |
| 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5401 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5402 | } |
| 5403 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5404 | try { |
| 5405 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5406 | if (controller == null) { |
| 5407 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5408 | return; |
| 5409 | } |
| 5410 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
| 5413 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5414 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5415 | |
| 5416 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5418 | message); |
| 5419 | } |
| 5420 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5421 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5422 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5423 | boolean isProvisioned) { |
| 5424 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5425 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5426 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5427 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5428 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5431 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5432 | if (controller == null) { |
| 5433 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5434 | return; |
| 5435 | } |
| 5436 | controller.setRcsProvisioningStatusForCapability( |
| 5437 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5438 | } finally { |
| 5439 | Binder.restoreCallingIdentity(identity); |
| 5440 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | |
| 5444 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5445 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5446 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5447 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5448 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5449 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5450 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5451 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5452 | final long identity = Binder.clearCallingIdentity(); |
| 5453 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5454 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5455 | if (controller == null) { |
| 5456 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5457 | |
| 5458 | // device does not support IMS, this method will return true always. |
| 5459 | return true; |
| 5460 | } |
| 5461 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5462 | } finally { |
| 5463 | Binder.restoreCallingIdentity(identity); |
| 5464 | } |
| 5465 | } |
| 5466 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5467 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5468 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5469 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5470 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5471 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5472 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5473 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5474 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5475 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5476 | final long identity = Binder.clearCallingIdentity(); |
| 5477 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5478 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5479 | if (controller == null) { |
| 5480 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5481 | return; |
| 5482 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5483 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5484 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | @Override |
| 5491 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5492 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5493 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5494 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5495 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5496 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5497 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5498 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5499 | final long identity = Binder.clearCallingIdentity(); |
| 5500 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5501 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5502 | if (controller == null) { |
| 5503 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5504 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5505 | // device does not support IMS, this method will return true always. |
| 5506 | return true; |
| 5507 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5508 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5509 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5510 | } finally { |
| 5511 | Binder.restoreCallingIdentity(identity); |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5516 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5517 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5518 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5519 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5520 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5521 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5522 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); |
| 5524 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5525 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5526 | if (controller == null) { |
| 5527 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5528 | |
| 5529 | // device does not support IMS, this method will return false |
| 5530 | return false; |
| 5531 | } |
| 5532 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5535 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5539 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5540 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5541 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5542 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5543 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5544 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5545 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5546 | final long identity = Binder.clearCallingIdentity(); |
| 5547 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5548 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5549 | if (controller == null) { |
| 5550 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5551 | |
| 5552 | // device does not support IMS, this method will return false |
| 5553 | return false; |
| 5554 | } |
| 5555 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5556 | } finally { |
| 5557 | Binder.restoreCallingIdentity(identity); |
| 5558 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5559 | } |
| 5560 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5561 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5562 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5563 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5564 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5565 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5566 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5567 | mApp, subId, "getImsProvisioningInt"); |
| 5568 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5569 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5570 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5571 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5572 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
| 5575 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5576 | int slotId = getSlotIndex(subId); |
| 5577 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5578 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5579 | + subId + "' for key:" + key); |
| 5580 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5581 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5582 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5583 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5584 | if (controller == null) { |
| 5585 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5586 | |
| 5587 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5588 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5589 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5590 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5591 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5592 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5593 | return retVal; |
| 5594 | } |
| 5595 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5596 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5597 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5598 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5599 | + subId + "' for key:" + key); |
| 5600 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5601 | } finally { |
| 5602 | Binder.restoreCallingIdentity(identity); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | @Override |
| 5607 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5609 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5610 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5611 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5612 | mApp, subId, "getImsProvisioningString"); |
| 5613 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5614 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5615 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5616 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5617 | final long identity = Binder.clearCallingIdentity(); |
| 5618 | try { |
| 5619 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5620 | int slotId = getSlotIndex(subId); |
| 5621 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5622 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5623 | + subId + "' for key:" + key); |
| 5624 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5625 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5626 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5627 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5628 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5629 | + subId + "' for key:" + key); |
| 5630 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(identity); |
| 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | @Override |
| 5637 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5638 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5639 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5640 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5642 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5643 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5644 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5645 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5646 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5647 | String displayPackageName = getCurrentPackageNameOrPhone(); |
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, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5654 | + subId + "' for key:" + key); |
| 5655 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5656 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5657 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5658 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5659 | if (controller == null) { |
| 5660 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5661 | |
| 5662 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5663 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5664 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5665 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5666 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5667 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5668 | return retVal; |
| 5669 | } |
| 5670 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5671 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5672 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5673 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5674 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5675 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5676 | } finally { |
| 5677 | Binder.restoreCallingIdentity(identity); |
| 5678 | } |
| 5679 | } |
| 5680 | |
| 5681 | @Override |
| 5682 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5684 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5685 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5687 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5688 | |
| 5689 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5690 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5691 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
| 5694 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5695 | int slotId = getSlotIndex(subId); |
| 5696 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5697 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5698 | + subId + "' for key:" + key); |
| 5699 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5700 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5701 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5702 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5703 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5704 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5705 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
| 5708 | } |
| 5709 | } |
| 5710 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5711 | /** |
| 5712 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5713 | * for the given slot ID or no ImsResolver instance has been created. |
| 5714 | * @param slotId The slot ID that the IMS service is created for. |
| 5715 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5716 | */ |
| 5717 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5718 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5719 | ImsFeature.FEATURE_MMTEL)) { |
| 5720 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5721 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5722 | } |
| 5723 | } |
| 5724 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5725 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5726 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5727 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5728 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5729 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5730 | } |
| 5731 | return slotId; |
| 5732 | } |
| 5733 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5734 | private int getSlotIndex(int subId) { |
| 5735 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5736 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5737 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5738 | } |
| 5739 | return slotId; |
| 5740 | } |
| 5741 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5742 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5743 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5744 | */ |
| 5745 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5746 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5747 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5748 | try { |
| 5749 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5750 | } catch (SecurityException se) { |
| 5751 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5752 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5753 | + Binder.getCallingUid()); |
| 5754 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5755 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5756 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5757 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5758 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5759 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5760 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5761 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5762 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5763 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5764 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5765 | enforceTelephonyFeatureWithException(callingPackage, |
| 5766 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5768 | final long identity = Binder.clearCallingIdentity(); |
| 5769 | try { |
| 5770 | final Phone phone = getPhone(subId); |
| 5771 | if (phone != null) { |
| 5772 | return phone.getServiceState().getDataNetworkType(); |
| 5773 | } else { |
| 5774 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5775 | } |
| 5776 | } finally { |
| 5777 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | /** |
| 5782 | * Returns the data network type |
| 5783 | */ |
| 5784 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5785 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5786 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5787 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | /** |
| 5791 | * Returns the data network type for a subId |
| 5792 | */ |
| 5793 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5794 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5795 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5796 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5797 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5798 | mApp, functionName)) { |
| 5799 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5800 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5801 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5802 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5803 | } |
| 5804 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5805 | enforceTelephonyFeatureWithException(callingPackage, |
| 5806 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5807 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5808 | final long identity = Binder.clearCallingIdentity(); |
| 5809 | try { |
| 5810 | final Phone phone = getPhone(subId); |
| 5811 | if (phone != null) { |
| 5812 | return phone.getServiceState().getDataNetworkType(); |
| 5813 | } else { |
| 5814 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5815 | } |
| 5816 | } finally { |
| 5817 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5818 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5822 | * Returns the Voice network type for a subId |
| 5823 | */ |
| 5824 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5825 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5826 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5827 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 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 | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5836 | enforceTelephonyFeatureWithException(callingPackage, |
| 5837 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 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().getVoiceNetworkType(); |
| 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 | /** |
| 5853 | * @return true if a ICC card is present |
| 5854 | */ |
| 5855 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5856 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5857 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5858 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5862 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5863 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5864 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5865 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5866 | if (!mApp.getResources().getBoolean( |
| 5867 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5868 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5869 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5870 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | final long identity = Binder.clearCallingIdentity(); |
| 5873 | try { |
| 5874 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5875 | if (phone != null) { |
| 5876 | return phone.getIccCard().hasIccCard(); |
| 5877 | } else { |
| 5878 | return false; |
| 5879 | } |
| 5880 | } finally { |
| 5881 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | /** |
| 5886 | * Return if the current radio is LTE on CDMA. This |
| 5887 | * is a tri-state return value as for a period of time |
| 5888 | * the mode may be unknown. |
| 5889 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5890 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5891 | * @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] | 5892 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5893 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5894 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5895 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5896 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5897 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5900 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5901 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5902 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5903 | try { |
| 5904 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5905 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5906 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5907 | } |
| 5908 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5909 | enforceTelephonyFeatureWithException(callingPackage, |
| 5910 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5911 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5912 | final long identity = Binder.clearCallingIdentity(); |
| 5913 | try { |
| 5914 | final Phone phone = getPhone(subId); |
| 5915 | if (phone == null) { |
| 5916 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5917 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5918 | return TelephonyProperties.lte_on_cdma_device() |
| 5919 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5920 | } |
| 5921 | } finally { |
| 5922 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5923 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5926 | /** |
| 5927 | * {@hide} |
| 5928 | * Returns Default subId, 0 in the case of single standby. |
| 5929 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5930 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5931 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5934 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5935 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5936 | } |
| 5937 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5938 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5939 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5940 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5941 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5942 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5943 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5944 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5945 | } |
| 5946 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5947 | /** |
| 5948 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5949 | */ |
| 5950 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | final long identity = Binder.clearCallingIdentity(); |
| 5952 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5953 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5955 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5956 | } finally { |
| 5957 | Binder.restoreCallingIdentity(identity); |
| 5958 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | /** |
| 5962 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5963 | */ |
| 5964 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | final long identity = Binder.clearCallingIdentity(); |
| 5966 | try { |
| 5967 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5968 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
| 5972 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5973 | } |
| 5974 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5975 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5976 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5977 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5978 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5979 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5980 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5981 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5982 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5983 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5984 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5985 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5986 | } |
| 5987 | return PhoneFactory.getPhone(phoneId); |
| 5988 | } |
| 5989 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5990 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5991 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5992 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5993 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5994 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5995 | /*message=*/ "iccOpenLogicalChannel"); |
| 5996 | |
| 5997 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5998 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5999 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 6000 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6001 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6002 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 6003 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6004 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6005 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6006 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6007 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6008 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6009 | Phone phone; |
| 6010 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6012 | mApp, request.subId, message); |
| 6013 | phone = getPhoneFromSubId(request.subId); |
| 6014 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6015 | enforceModifyPermission(); |
| 6016 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6017 | } else { |
| 6018 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6019 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6020 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6024 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6027 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6029 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6030 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6031 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6032 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | loge("The calling package is not allowed to access ISD-R."); |
| 6034 | throw new SecurityException( |
| 6035 | "The calling package is not allowed to access ISD-R."); |
| 6036 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6037 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6038 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6039 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6040 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6041 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | return response; |
| 6043 | } finally { |
| 6044 | Binder.restoreCallingIdentity(identity); |
| 6045 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6049 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6050 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6051 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6052 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6053 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6054 | /*message=*/"iccCloseLogicalChannel"); |
| 6055 | |
| 6056 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6057 | |
| 6058 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6059 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6060 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6061 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6062 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6063 | // before this feature is enabled, this API should only return false if |
| 6064 | // the operation fails instead of throwing runtime exception for |
| 6065 | // backward-compatibility. |
| 6066 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6067 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6070 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6071 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6073 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6074 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6075 | Boolean success = false; |
| 6076 | if (result instanceof RuntimeException) { |
| 6077 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6078 | if (shouldThrowExceptionOnFailure) { |
| 6079 | throw (RuntimeException) result; |
| 6080 | } else { |
| 6081 | return false; |
| 6082 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6083 | } else if (result instanceof Boolean) { |
| 6084 | success = (Boolean) result; |
| 6085 | } else { |
| 6086 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6087 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6088 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | return success; |
| 6090 | } finally { |
| 6091 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6092 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6093 | } |
| 6094 | |
| 6095 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6096 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6097 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6099 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6100 | |
| 6101 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6102 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6103 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6104 | if (DBG) { |
| 6105 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6106 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6107 | + p3 + " data=" + data); |
| 6108 | } |
| 6109 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6110 | command, p1, p2, p3, data); |
| 6111 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6112 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6113 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6114 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6115 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6116 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6117 | |
| 6118 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6119 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6120 | "iccTransmitApduLogicalChannelBySlot"); |
| 6121 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6122 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6123 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6124 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6125 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6126 | } |
| 6127 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6128 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6129 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6133 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6136 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | return ""; |
| 6138 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6141 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6142 | null /* workSource */); |
| 6143 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6144 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | // Append the returned status code to the end of the response payload. |
| 6146 | String s = Integer.toHexString( |
| 6147 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6148 | if (response.payload != null) { |
| 6149 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6150 | } |
| 6151 | return s; |
| 6152 | } finally { |
| 6153 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6154 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6155 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6156 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6157 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6158 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6159 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6161 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6163 | |
| 6164 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6165 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6166 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6167 | if (DBG) { |
| 6168 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6169 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6170 | } |
| 6171 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6172 | cla, command, p1, p2, p3, data); |
| 6173 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6174 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6175 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6176 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6177 | 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] | 6178 | enforceModifyPermission(); |
| 6179 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6180 | |
| 6181 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6182 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6183 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6184 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6185 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6186 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6187 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6191 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6192 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6196 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6197 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6198 | final long identity = Binder.clearCallingIdentity(); |
| 6199 | try { |
| 6200 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6201 | && TextUtils.equals(ISDR_AID, data)) { |
| 6202 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6203 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6204 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | if (bestComponent == null |
| 6206 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6207 | loge("The calling package is not allowed to select ISD-R."); |
| 6208 | throw new SecurityException( |
| 6209 | "The calling package is not allowed to select ISD-R."); |
| 6210 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6211 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6213 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6214 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6215 | null /* workSource */); |
| 6216 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6218 | // Append the returned status code to the end of the response payload. |
| 6219 | String s = Integer.toHexString( |
| 6220 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6221 | if (response.payload != null) { |
| 6222 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6223 | } |
| 6224 | return s; |
| 6225 | } finally { |
| 6226 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6227 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6231 | 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] | 6232 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6234 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6235 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6236 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6237 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6238 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | final long identity = Binder.clearCallingIdentity(); |
| 6240 | try { |
| 6241 | if (DBG) { |
| 6242 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6243 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6244 | } |
| 6245 | |
| 6246 | IccIoResult response = |
| 6247 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6248 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6249 | subId); |
| 6250 | |
| 6251 | if (DBG) { |
| 6252 | log("Exchange SIM_IO [R]" + response); |
| 6253 | } |
| 6254 | |
| 6255 | byte[] result = null; |
| 6256 | int length = 2; |
| 6257 | if (response.payload != null) { |
| 6258 | length = 2 + response.payload.length; |
| 6259 | result = new byte[length]; |
| 6260 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6261 | } else { |
| 6262 | result = new byte[length]; |
| 6263 | } |
| 6264 | |
| 6265 | result[length - 1] = (byte) response.sw2; |
| 6266 | result[length - 2] = (byte) response.sw1; |
| 6267 | return result; |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6270 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6271 | } |
| 6272 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6273 | /** |
| 6274 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6275 | * on a particular subscription |
| 6276 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6277 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6278 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6280 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6281 | return null; |
| 6282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6284 | enforceTelephonyFeatureWithException(callingPackage, |
| 6285 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 | final long identity = Binder.clearCallingIdentity(); |
| 6288 | try { |
| 6289 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6290 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6291 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6292 | return null; |
| 6293 | } |
| 6294 | Object response = sendRequest( |
| 6295 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6296 | if (response instanceof String[]) { |
| 6297 | return (String[]) response; |
| 6298 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6299 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6301 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6302 | } finally { |
| 6303 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6304 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6305 | } |
| 6306 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6307 | /** |
| 6308 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6309 | * subscription. |
| 6310 | * |
| 6311 | * @param subId the id of the subscription. |
| 6312 | * @param appType the uicc app type, must be USIM or SIM. |
| 6313 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6314 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6315 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6316 | * @return number of fplmns that is successfully written to the SIM. |
| 6317 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6318 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6319 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6321 | mApp, subId, "setForbiddenPlmns"); |
| 6322 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6323 | enforceTelephonyFeatureWithException(callingPackage, |
| 6324 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6325 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6326 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6327 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6328 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6329 | } |
| 6330 | if (fplmns == null) { |
| 6331 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6332 | } |
| 6333 | for (String fplmn : fplmns) { |
| 6334 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6335 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6336 | } |
| 6337 | } |
| 6338 | final long identity = Binder.clearCallingIdentity(); |
| 6339 | try { |
| 6340 | Object response = sendRequest( |
| 6341 | CMD_SET_FORBIDDEN_PLMNS, |
| 6342 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6343 | subId); |
| 6344 | return (int) response; |
| 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
| 6348 | } |
| 6349 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6350 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6351 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6353 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6354 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6355 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6356 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
| 6360 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6361 | if (response.payload == null) { |
| 6362 | return ""; |
| 6363 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | // Append the returned status code to the end of the response payload. |
| 6366 | String s = Integer.toHexString( |
| 6367 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6368 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6369 | return s; |
| 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6373 | } |
| 6374 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6375 | /** |
| 6376 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6377 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6378 | * |
| 6379 | * @param itemID the ID of the item to read |
| 6380 | * @return the NV item as a String, or null on error. |
| 6381 | */ |
| 6382 | @Override |
| 6383 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6384 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6386 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | |
| 6388 | final long identity = Binder.clearCallingIdentity(); |
| 6389 | try { |
| 6390 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6391 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6392 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6393 | return value; |
| 6394 | } finally { |
| 6395 | Binder.restoreCallingIdentity(identity); |
| 6396 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6401 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6402 | * |
| 6403 | * @param itemID the ID of the item to read |
| 6404 | * @param itemValue the value to write, as a String |
| 6405 | * @return true on success; false on any failure |
| 6406 | */ |
| 6407 | @Override |
| 6408 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6409 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6411 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | |
| 6413 | final long identity = Binder.clearCallingIdentity(); |
| 6414 | try { |
| 6415 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6416 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6417 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6418 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6419 | return success; |
| 6420 | } finally { |
| 6421 | Binder.restoreCallingIdentity(identity); |
| 6422 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6427 | * Used for device configuration by some CDMA operators. |
| 6428 | * |
| 6429 | * @param preferredRoamingList byte array containing the new PRL |
| 6430 | * @return true on success; false on any failure |
| 6431 | */ |
| 6432 | @Override |
| 6433 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6434 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6435 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | |
| 6437 | final long identity = Binder.clearCallingIdentity(); |
| 6438 | try { |
| 6439 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6440 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6441 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6442 | return success; |
| 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6449 | * 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] | 6450 | * Used for device configuration by some CDMA operators. |
| 6451 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6452 | * @param slotIndex - device slot. |
| 6453 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6454 | * @return true on success; false on any failure |
| 6455 | */ |
| 6456 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6457 | public boolean resetModemConfig(int slotIndex) { |
| 6458 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6459 | if (phone != null) { |
| 6460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6461 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6462 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6463 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6464 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6465 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6466 | final long identity = Binder.clearCallingIdentity(); |
| 6467 | try { |
| 6468 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6469 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6470 | return success; |
| 6471 | } finally { |
| 6472 | Binder.restoreCallingIdentity(identity); |
| 6473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6474 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6475 | return false; |
| 6476 | } |
| 6477 | |
| 6478 | /** |
| 6479 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6480 | * |
| 6481 | * @param slotIndex - device slot. |
| 6482 | * |
| 6483 | * @return true on success; false on any failure |
| 6484 | */ |
| 6485 | @Override |
| 6486 | public boolean rebootModem(int slotIndex) { |
| 6487 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6488 | if (phone != null) { |
| 6489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6490 | mApp, phone.getSubId(), "rebootModem"); |
| 6491 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6492 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6493 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6494 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6495 | final long identity = Binder.clearCallingIdentity(); |
| 6496 | try { |
| 6497 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6498 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6499 | return success; |
| 6500 | } finally { |
| 6501 | Binder.restoreCallingIdentity(identity); |
| 6502 | } |
| 6503 | } |
| 6504 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6505 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6506 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6507 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6508 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6509 | * {@link #disableIms(int)}. |
| 6510 | * @param slotIndex device slot. |
| 6511 | */ |
| 6512 | public void resetIms(int slotIndex) { |
| 6513 | enforceModifyPermission(); |
| 6514 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6515 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6516 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6517 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6518 | final long identity = Binder.clearCallingIdentity(); |
| 6519 | try { |
| 6520 | if (mImsResolver == null) { |
| 6521 | // may happen if the does not support IMS. |
| 6522 | return; |
| 6523 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6524 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6525 | } finally { |
| 6526 | Binder.restoreCallingIdentity(identity); |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6531 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6532 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6533 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6534 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6535 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6536 | |
| 6537 | final long identity = Binder.clearCallingIdentity(); |
| 6538 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6539 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6540 | // may happen if the device does not support IMS. |
| 6541 | return; |
| 6542 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6543 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6544 | } finally { |
| 6545 | Binder.restoreCallingIdentity(identity); |
| 6546 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6550 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6551 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6552 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6553 | public void disableIms(int slotId) { |
| 6554 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | |
| 6556 | final long identity = Binder.clearCallingIdentity(); |
| 6557 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6558 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6559 | // may happen if the device does not support IMS. |
| 6560 | return; |
| 6561 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6562 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6569 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6570 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6571 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6572 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6573 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6574 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6575 | |
| 6576 | final long identity = Binder.clearCallingIdentity(); |
| 6577 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6578 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6579 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6580 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6581 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6582 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
| 6585 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6586 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6587 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6588 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6589 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6590 | @Override |
| 6591 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6592 | enforceModifyPermission(); |
| 6593 | |
| 6594 | final long identity = Binder.clearCallingIdentity(); |
| 6595 | try { |
| 6596 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6597 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6598 | } finally { |
| 6599 | Binder.restoreCallingIdentity(identity); |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6604 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6605 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6606 | */ |
| 6607 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6608 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6609 | |
| 6610 | final long identity = Binder.clearCallingIdentity(); |
| 6611 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6612 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6613 | // may happen if the device does not support IMS. |
| 6614 | return null; |
| 6615 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6616 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | } finally { |
| 6618 | Binder.restoreCallingIdentity(identity); |
| 6619 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6620 | } |
| 6621 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6622 | /** |
| 6623 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6624 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6625 | */ |
| 6626 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6627 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6628 | |
| 6629 | final long identity = Binder.clearCallingIdentity(); |
| 6630 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6631 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6632 | // may happen if the device does not support IMS. |
| 6633 | return null; |
| 6634 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6635 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | } finally { |
| 6637 | Binder.restoreCallingIdentity(identity); |
| 6638 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6639 | } |
| 6640 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6641 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6642 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6643 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6644 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6645 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6646 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6647 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6648 | * @param packageName The name of the package that the current configuration will be replaced |
| 6649 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6650 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6651 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6653 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6656 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6660 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6661 | // may happen if the device does not support IMS. |
| 6662 | return false; |
| 6663 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6664 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6665 | for (int featureType : featureTypes) { |
| 6666 | featureConfig.put(featureType, packageName); |
| 6667 | } |
| 6668 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6669 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
| 6672 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6676 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6677 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6678 | * |
| 6679 | * This should only be used for testing. |
| 6680 | * |
| 6681 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6682 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6683 | */ |
| 6684 | @Override |
| 6685 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6686 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6687 | "clearCarrierImsServiceOverride"); |
| 6688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6689 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6690 | |
| 6691 | final long identity = Binder.clearCallingIdentity(); |
| 6692 | try { |
| 6693 | if (mImsResolver == null) { |
| 6694 | // may happen if the device does not support IMS. |
| 6695 | return false; |
| 6696 | } |
| 6697 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(identity); |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6704 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6705 | * |
| 6706 | * @param slotId The slot that the ImsService is associated with. |
| 6707 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6708 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6709 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6710 | * @return the package name of the ImsService configuration. |
| 6711 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6712 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6713 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6714 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6715 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6716 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | final long identity = Binder.clearCallingIdentity(); |
| 6719 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6720 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6721 | // may happen if the device does not support IMS. |
| 6722 | return ""; |
| 6723 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6724 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6725 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6726 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | } finally { |
| 6728 | Binder.restoreCallingIdentity(identity); |
| 6729 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6730 | } |
| 6731 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6732 | /** |
| 6733 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6734 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6735 | * @param callback A callback with an integer containing the |
| 6736 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6737 | */ |
| 6738 | @Override |
| 6739 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6740 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6741 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6742 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6743 | "IMS not available on device."); |
| 6744 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6745 | final long token = Binder.clearCallingIdentity(); |
| 6746 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6747 | int slotId = getSlotIndex(subId); |
| 6748 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6749 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6750 | + subId + "'"); |
| 6751 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6752 | } |
| 6753 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6754 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6755 | try { |
| 6756 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6757 | } catch (RemoteException e) { |
| 6758 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6759 | + "Ignore"); |
| 6760 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6761 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6762 | } catch (ImsException e) { |
| 6763 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6764 | } finally { |
| 6765 | Binder.restoreCallingIdentity(token); |
| 6766 | } |
| 6767 | } |
| 6768 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6769 | /** |
| 6770 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6771 | */ |
| 6772 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6773 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | |
| 6775 | final long identity = Binder.clearCallingIdentity(); |
| 6776 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6777 | // NOTE: Before S, this method only set the default phone. |
| 6778 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6779 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6780 | phone.setImsRegistrationState(registered); |
| 6781 | } |
| 6782 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6783 | } finally { |
| 6784 | Binder.restoreCallingIdentity(identity); |
| 6785 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6789 | * Set the network selection mode to automatic. |
| 6790 | * |
| 6791 | */ |
| 6792 | @Override |
| 6793 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6795 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6796 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6797 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6798 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6799 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6800 | final long identity = Binder.clearCallingIdentity(); |
| 6801 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6802 | if (!isActiveSubscription(subId)) { |
| 6803 | return; |
| 6804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6806 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6807 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6808 | } finally { |
| 6809 | Binder.restoreCallingIdentity(identity); |
| 6810 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6811 | } |
| 6812 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6813 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6814 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6815 | * |
| 6816 | * @param subId the id of the subscription. |
| 6817 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6818 | * the operator to attach to. |
| 6819 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6820 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6821 | * normal network selection next time. |
| 6822 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6823 | */ |
| 6824 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6825 | public boolean setNetworkSelectionModeManual( |
| 6826 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6828 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6829 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6830 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6831 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6832 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6833 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6834 | if (!isActiveSubscription(subId)) { |
| 6835 | return false; |
| 6836 | } |
| 6837 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6839 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6841 | if (DBG) { |
| 6842 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6843 | + " operator: " + operatorInfo); |
| 6844 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6846 | } finally { |
| 6847 | Binder.restoreCallingIdentity(identity); |
| 6848 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6849 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6850 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6851 | * Get the manual network selection |
| 6852 | * |
| 6853 | * @param subId the id of the subscription. |
| 6854 | * |
| 6855 | * @return the previously saved user selected PLMN |
| 6856 | */ |
| 6857 | @Override |
| 6858 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6859 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6860 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6861 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6862 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6863 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6864 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6865 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6866 | final long identity = Binder.clearCallingIdentity(); |
| 6867 | try { |
| 6868 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6869 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6870 | } |
| 6871 | |
| 6872 | final Phone phone = getPhone(subId); |
| 6873 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6874 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6875 | } |
| 6876 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6877 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6878 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
| 6882 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6883 | |
| 6884 | /** |
| 6885 | * Scans for available networks. |
| 6886 | */ |
| 6887 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6888 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6889 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6891 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6892 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6893 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6894 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6895 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6896 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6897 | .setCallingPid(Binder.getCallingPid()) |
| 6898 | .setCallingUid(Binder.getCallingUid()) |
| 6899 | .setMethod("getCellNetworkScanResults") |
| 6900 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6901 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6902 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6903 | .build()); |
| 6904 | switch (locationResult) { |
| 6905 | case DENIED_HARD: |
| 6906 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6907 | case DENIED_SOFT: |
| 6908 | return null; |
| 6909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6911 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6912 | try { |
| 6913 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6914 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6915 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | } finally { |
| 6917 | Binder.restoreCallingIdentity(identity); |
| 6918 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6919 | } |
| 6920 | |
| 6921 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6922 | * Get the call forwarding info, given the call forwarding reason. |
| 6923 | */ |
| 6924 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6925 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6926 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6927 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6928 | |
| 6929 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6930 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6931 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6932 | long identity = Binder.clearCallingIdentity(); |
| 6933 | try { |
| 6934 | if (DBG) { |
| 6935 | log("getCallForwarding: subId " + subId |
| 6936 | + " callForwardingReason" + callForwardingReason); |
| 6937 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6938 | |
| 6939 | Phone phone = getPhone(subId); |
| 6940 | if (phone == null) { |
| 6941 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6942 | callback.onError( |
| 6943 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6944 | } catch (RemoteException e) { |
| 6945 | // ignore |
| 6946 | } |
| 6947 | return; |
| 6948 | } |
| 6949 | |
| 6950 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6951 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6952 | @Override |
| 6953 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6954 | try { |
| 6955 | callback.onCallForwardingInfoAvailable(info); |
| 6956 | } catch (RemoteException e) { |
| 6957 | // ignore |
| 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | @Override |
| 6962 | public void onError(int error) { |
| 6963 | try { |
| 6964 | callback.onError(error); |
| 6965 | } catch (RemoteException e) { |
| 6966 | // ignore |
| 6967 | } |
| 6968 | } |
| 6969 | }); |
| 6970 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6971 | } finally { |
| 6972 | Binder.restoreCallingIdentity(identity); |
| 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | /** |
| 6977 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6978 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6979 | */ |
| 6980 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6981 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6982 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6983 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6984 | |
| 6985 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6986 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6987 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6988 | long identity = Binder.clearCallingIdentity(); |
| 6989 | try { |
| 6990 | if (DBG) { |
| 6991 | log("setCallForwarding: subId " + subId |
| 6992 | + " callForwardingInfo" + callForwardingInfo); |
| 6993 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6994 | |
| 6995 | Phone phone = getPhone(subId); |
| 6996 | if (phone == null) { |
| 6997 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6998 | callback.accept( |
| 6999 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7000 | } catch (RemoteException e) { |
| 7001 | // ignore |
| 7002 | } |
| 7003 | return; |
| 7004 | } |
| 7005 | |
| 7006 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7007 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7008 | |
| 7009 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7010 | } finally { |
| 7011 | Binder.restoreCallingIdentity(identity); |
| 7012 | } |
| 7013 | } |
| 7014 | |
| 7015 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7016 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7017 | */ |
| 7018 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7019 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7020 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7021 | |
| 7022 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7023 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7024 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7025 | long identity = Binder.clearCallingIdentity(); |
| 7026 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7027 | Phone phone = getPhone(subId); |
| 7028 | if (phone == null) { |
| 7029 | try { |
| 7030 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7031 | } catch (RemoteException e) { |
| 7032 | // ignore |
| 7033 | } |
| 7034 | return; |
| 7035 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7036 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7037 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7038 | boolean requireUssd = c.getBoolean( |
| 7039 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7040 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7041 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7042 | if (requireUssd) { |
| 7043 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7044 | getSubscriptionCarrierId(subId)); |
| 7045 | String newUssdCommand = ""; |
| 7046 | try { |
| 7047 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7048 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7049 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7050 | } catch (NullPointerException e) { |
| 7051 | loge("Failed to generate USSD number" + e); |
| 7052 | } |
| 7053 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7054 | mMainThreadHandler, callback, carrierXmlParser, |
| 7055 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7056 | final String ussdCommand = newUssdCommand; |
| 7057 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7058 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7059 | }); |
| 7060 | } else { |
| 7061 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7062 | callback::accept); |
| 7063 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7064 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7065 | } finally { |
| 7066 | Binder.restoreCallingIdentity(identity); |
| 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7071 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7072 | */ |
| 7073 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7074 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7075 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7076 | |
| 7077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7078 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7079 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7080 | long identity = Binder.clearCallingIdentity(); |
| 7081 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7082 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7083 | |
| 7084 | Phone phone = getPhone(subId); |
| 7085 | if (phone == null) { |
| 7086 | try { |
| 7087 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7088 | } catch (RemoteException e) { |
| 7089 | // ignore |
| 7090 | } |
| 7091 | return; |
| 7092 | } |
| 7093 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7094 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7095 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7096 | boolean requireUssd = c.getBoolean( |
| 7097 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7098 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7099 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7100 | if (requireUssd) { |
| 7101 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7102 | getSubscriptionCarrierId(subId)); |
| 7103 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7104 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7105 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7106 | String newUssdCommand = ""; |
| 7107 | try { |
| 7108 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7109 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7110 | .makeCommand(ssAction, null); |
| 7111 | } catch (NullPointerException e) { |
| 7112 | loge("Failed to generate USSD number" + e); |
| 7113 | } |
| 7114 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7115 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7116 | final String ussdCommand = newUssdCommand; |
| 7117 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7118 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7119 | }); |
| 7120 | } else { |
| 7121 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7122 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7123 | |
| 7124 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7125 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7126 | } finally { |
| 7127 | Binder.restoreCallingIdentity(identity); |
| 7128 | } |
| 7129 | } |
| 7130 | |
| 7131 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7132 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7133 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7134 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7135 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7136 | * location related information which will be sent if the caller already possess |
| 7137 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7138 | * @param request contains the radio access networks with bands/channels to scan |
| 7139 | * @param messenger callback messenger for scan results or errors |
| 7140 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7141 | * @return the id of the requested scan which can be used to stop the scan. |
| 7142 | */ |
| 7143 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7144 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7145 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7146 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7148 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7149 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7150 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7151 | if (!renounceFineLocationAccess) { |
| 7152 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7153 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7154 | .setCallingPackage(callingPackage) |
| 7155 | .setCallingFeatureId(callingFeatureId) |
| 7156 | .setCallingPid(Binder.getCallingPid()) |
| 7157 | .setCallingUid(Binder.getCallingUid()) |
| 7158 | .setMethod("requestNetworkScan") |
| 7159 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7160 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7161 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7162 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7163 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7164 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7165 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7166 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7167 | if (e != null) { |
| 7168 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7169 | throw e; |
| 7170 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7171 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7172 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7173 | } |
| 7174 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7175 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7176 | |
| 7177 | enforceTelephonyFeatureWithException(callingPackage, |
| 7178 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7179 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7180 | int callingUid = Binder.getCallingUid(); |
| 7181 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7182 | final long identity = Binder.clearCallingIdentity(); |
| 7183 | try { |
| 7184 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7185 | renounceFineLocationAccess, request, messenger, binder, |
| 7186 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7187 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
| 7190 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7191 | } |
| 7192 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7193 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7194 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7195 | boolean hasCarrierPriv; |
| 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7199 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7200 | } finally { |
| 7201 | Binder.restoreCallingIdentity(identity); |
| 7202 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7203 | boolean hasNetworkScanPermission = |
| 7204 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7205 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7206 | |
| 7207 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7208 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7209 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7213 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7214 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7215 | return new SecurityException("Specific channels must not be" |
| 7216 | + " scanned without location access."); |
| 7217 | } |
| 7218 | } |
| 7219 | } |
| 7220 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7221 | return null; |
| 7222 | } |
| 7223 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7224 | /** |
| 7225 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7226 | * |
| 7227 | * @param subId id of the subscription |
| 7228 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7229 | */ |
| 7230 | @Override |
| 7231 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7233 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7235 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7238 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | } finally { |
| 7240 | Binder.restoreCallingIdentity(identity); |
| 7241 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7245 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7246 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7247 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7248 | */ |
| 7249 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7250 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7251 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7252 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7253 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7255 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7256 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | final long identity = Binder.clearCallingIdentity(); |
| 7259 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7260 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7261 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7262 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7263 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7264 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7268 | } |
| 7269 | |
| 7270 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7271 | * Get the allowed network types for certain reason. |
| 7272 | * |
| 7273 | * @param subId the id of the subscription. |
| 7274 | * @param reason the reason the allowed network type change is taking place |
| 7275 | * @return the allowed network types. |
| 7276 | */ |
| 7277 | @Override |
| 7278 | public long getAllowedNetworkTypesForReason(int subId, |
| 7279 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7280 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7281 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7282 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7283 | if (!mApp.getResources().getBoolean( |
| 7284 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7285 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7286 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7287 | "getAllowedNetworkTypesForReason"); |
| 7288 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7289 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7290 | final long identity = Binder.clearCallingIdentity(); |
| 7291 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7292 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7293 | } finally { |
| 7294 | Binder.restoreCallingIdentity(identity); |
| 7295 | } |
| 7296 | } |
| 7297 | |
| 7298 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7299 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7300 | * @param subId subscription id of the sim card |
| 7301 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7302 | * This can be passed following states |
| 7303 | * <ol> |
| 7304 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7305 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7306 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7307 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7308 | * </ol> |
| 7309 | * @return operation result. |
| 7310 | */ |
| 7311 | @Override |
| 7312 | public int setNrDualConnectivityState(int subId, |
| 7313 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7314 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7315 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7316 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7317 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7318 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7319 | } |
| 7320 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7321 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7325 | nrDualConnectivityState, subId, |
| 7326 | workSource); |
| 7327 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7328 | return result; |
| 7329 | } finally { |
| 7330 | Binder.restoreCallingIdentity(identity); |
| 7331 | } |
| 7332 | } |
| 7333 | |
| 7334 | /** |
| 7335 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7336 | * @return true if dual connectivity is enabled else false |
| 7337 | */ |
| 7338 | @Override |
| 7339 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7340 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7341 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7342 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7343 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7344 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7345 | return false; |
| 7346 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7347 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7348 | final long identity = Binder.clearCallingIdentity(); |
| 7349 | try { |
| 7350 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7351 | null, subId, workSource); |
| 7352 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7353 | return isEnabled; |
| 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7360 | * Set the allowed network types of the device and |
| 7361 | * provide the reason triggering the allowed network change. |
| 7362 | * |
| 7363 | * @param subId the id of the subscription. |
| 7364 | * @param reason the reason the allowed network type change is taking place |
| 7365 | * @param allowedNetworkTypes the allowed network types. |
| 7366 | * @return true on success; false on any failure. |
| 7367 | */ |
| 7368 | @Override |
| 7369 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7370 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7371 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7373 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7374 | // If the caller only has carrier privileges, then they should not be able to override |
| 7375 | // any network types which were set for security reasons. |
| 7376 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7377 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7378 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7379 | throw new SecurityException( |
| 7380 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7381 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7382 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7383 | |
| 7384 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7385 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7386 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7387 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7388 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7389 | return false; |
| 7390 | } |
| 7391 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7392 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7393 | return false; |
| 7394 | } |
| 7395 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7396 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7397 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7398 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7399 | Phone phone = getPhone(subId); |
| 7400 | if (phone == null) { |
| 7401 | return false; |
| 7402 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7403 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7404 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7405 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7406 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7407 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7408 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7409 | final long identity = Binder.clearCallingIdentity(); |
| 7410 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7411 | Boolean success = (Boolean) sendRequest( |
| 7412 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7413 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7414 | |
| 7415 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7416 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7417 | } finally { |
| 7418 | Binder.restoreCallingIdentity(identity); |
| 7419 | } |
| 7420 | } |
| 7421 | |
| 7422 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7423 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7424 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7425 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7426 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7427 | * @hide |
| 7428 | */ |
| 7429 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7430 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7431 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7432 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7433 | if (!mApp.getResources().getBoolean( |
| 7434 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7435 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7436 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7437 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7440 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7441 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7442 | if (phone != null) { |
| 7443 | return phone.hasMatchedTetherApnSetting(); |
| 7444 | } else { |
| 7445 | return false; |
| 7446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | } finally { |
| 7448 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7449 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7453 | * Get the user enabled state of Mobile Data. |
| 7454 | * |
| 7455 | * TODO: remove and use isUserDataEnabled. |
| 7456 | * This can't be removed now because some vendor codes |
| 7457 | * calls through ITelephony directly while they should |
| 7458 | * use TelephonyManager. |
| 7459 | * |
| 7460 | * @return true on enabled |
| 7461 | */ |
| 7462 | @Override |
| 7463 | public boolean getDataEnabled(int subId) { |
| 7464 | return isUserDataEnabled(subId); |
| 7465 | } |
| 7466 | |
| 7467 | /** |
| 7468 | * Get whether mobile data is enabled per user setting. |
| 7469 | * |
| 7470 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7471 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7472 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7473 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7474 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7475 | * |
| 7476 | * @return {@code true} if data is enabled else {@code false} |
| 7477 | */ |
| 7478 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7479 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7480 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7481 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7482 | try { |
| 7483 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7484 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7485 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7486 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7487 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7488 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7490 | mApp, subId, functionName); |
| 7491 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7492 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | |
| 7494 | final long identity = Binder.clearCallingIdentity(); |
| 7495 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7496 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7498 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7499 | if (phone != null) { |
| 7500 | boolean retVal = phone.isUserDataEnabled(); |
| 7501 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7502 | return retVal; |
| 7503 | } else { |
| 7504 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7505 | return false; |
| 7506 | } |
| 7507 | } finally { |
| 7508 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7509 | } |
| 7510 | } |
| 7511 | |
| 7512 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7513 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7514 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7515 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7516 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7517 | * @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] | 7518 | */ |
| 7519 | @Override |
| 7520 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7521 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7522 | try { |
| 7523 | try { |
| 7524 | mApp.enforceCallingOrSelfPermission( |
| 7525 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7526 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7527 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7528 | try { |
| 7529 | mApp.enforceCallingOrSelfPermission( |
| 7530 | android.Manifest.permission.READ_PHONE_STATE, |
| 7531 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7532 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7533 | mApp.enforceCallingOrSelfPermission( |
| 7534 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7535 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7536 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7537 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7538 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7541 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7542 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | final long identity = Binder.clearCallingIdentity(); |
| 7545 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7546 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7548 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7549 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7550 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7551 | return retVal; |
| 7552 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7553 | if (DBG) { |
| 7554 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7555 | + subId + " retVal=false"); |
| 7556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | return false; |
| 7558 | } |
| 7559 | } finally { |
| 7560 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7561 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7562 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7563 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7564 | /** |
| 7565 | * Check if data is enabled for a specific reason |
| 7566 | * @param subId Subscription index |
| 7567 | * @param reason the reason the data enable change is taking place |
| 7568 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7569 | */ |
| 7570 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7571 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7572 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7573 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7574 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7575 | try { |
| 7576 | mApp.enforceCallingOrSelfPermission( |
| 7577 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7578 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7579 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7580 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7581 | functionName); |
| 7582 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7583 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7584 | try { |
| 7585 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7586 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7587 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7589 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7590 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7591 | } |
| 7592 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7593 | if (!mApp.getResources().getBoolean( |
| 7594 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7595 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7596 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7597 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7598 | |
| 7599 | final long identity = Binder.clearCallingIdentity(); |
| 7600 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7601 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7602 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7603 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7604 | + " reason=" + reason); |
| 7605 | } |
| 7606 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7607 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7608 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7609 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7610 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7611 | return retVal; |
| 7612 | } else { |
| 7613 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7614 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7615 | + subId + " retVal=false"); |
| 7616 | } |
| 7617 | return false; |
| 7618 | } |
| 7619 | } finally { |
| 7620 | Binder.restoreCallingIdentity(identity); |
| 7621 | } |
| 7622 | } |
| 7623 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7624 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7625 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7626 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7627 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7628 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7629 | // No permission needed; this only lets the caller inspect their own status. |
| 7630 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7631 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7632 | |
| 7633 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7634 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7635 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7636 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7637 | if (!mApp.getResources().getBoolean( |
| 7638 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7639 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7640 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7641 | "getCarrierPrivilegeStatusForUid"); |
| 7642 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7643 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7644 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7645 | } |
| 7646 | |
| 7647 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7648 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7649 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7650 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7651 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7652 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7653 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7654 | if (cpt == null) { |
| 7655 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7656 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7657 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7658 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7659 | } |
| 7660 | |
| 7661 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7662 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7663 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7664 | |
| 7665 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7666 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7667 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7668 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7669 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7670 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7671 | Phone phone = getPhone(subId); |
| 7672 | if (phone == null) { |
| 7673 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7674 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7675 | } |
| 7676 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7677 | if (cpt == null) { |
| 7678 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7679 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7680 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7681 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | @Override |
| 7685 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7686 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7687 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7688 | if (!mApp.getResources().getBoolean( |
| 7689 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7690 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7691 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7692 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7693 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7694 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7695 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7696 | } |
| 7697 | |
| 7698 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7699 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7700 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7701 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7702 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7703 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7704 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7705 | if (phone == null) { |
| 7706 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7707 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7708 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7709 | if (cpt == null) { |
| 7710 | continue; |
| 7711 | } |
| 7712 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7713 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7714 | break; |
| 7715 | } |
| 7716 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7717 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7718 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7719 | |
| 7720 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7721 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7722 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7723 | |
| 7724 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7725 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7726 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7727 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7728 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7729 | if (phone == null) { |
| 7730 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7731 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7732 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7733 | if (cpt == null) { |
| 7734 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7735 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7736 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7739 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7740 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7741 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7742 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7743 | if (phone == null) { |
| 7744 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7745 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7746 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7747 | if (cpt == null) { |
| 7748 | return Collections.emptyList(); |
| 7749 | } |
| 7750 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7751 | } |
| 7752 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7753 | @Override |
| 7754 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7755 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7756 | |
| 7757 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7758 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7759 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7760 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7761 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7762 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7763 | try { |
| 7764 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7765 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7766 | } |
| 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7769 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7770 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7771 | } |
| 7772 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7773 | @Override |
| 7774 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7775 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7776 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7777 | if (!mApp.getResources().getBoolean( |
| 7778 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7779 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7780 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7781 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7782 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7783 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7784 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7785 | if (phone == null) { |
| 7786 | return null; |
| 7787 | } |
| 7788 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7789 | if (cpt == null) { |
| 7790 | return null; |
| 7791 | } |
| 7792 | return cpt.getCarrierServicePackageName(); |
| 7793 | } |
| 7794 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7795 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7796 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7797 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7798 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7799 | return null; |
| 7800 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7801 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7802 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7803 | return null; |
| 7804 | } |
| 7805 | return iccId; |
| 7806 | } |
| 7807 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7808 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7809 | public void setCallComposerStatus(int subId, int status) { |
| 7810 | enforceModifyPermission(); |
| 7811 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7812 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7813 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7814 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | Phone phone = getPhone(subId); |
| 7818 | if (phone != null) { |
| 7819 | Phone defaultPhone = phone.getImsPhone(); |
| 7820 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7821 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7822 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7823 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7824 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7825 | } |
| 7826 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7827 | } catch (ImsException e) { |
| 7828 | throw new ServiceSpecificException(e.getCode()); |
| 7829 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | @Override |
| 7835 | public int getCallComposerStatus(int subId) { |
| 7836 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7837 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7838 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7839 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7840 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7841 | final long identity = Binder.clearCallingIdentity(); |
| 7842 | try { |
| 7843 | Phone phone = getPhone(subId); |
| 7844 | if (phone != null) { |
| 7845 | Phone defaultPhone = phone.getImsPhone(); |
| 7846 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7847 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7848 | return imsPhone.getCallComposerStatus(); |
| 7849 | } |
| 7850 | } |
| 7851 | } finally { |
| 7852 | Binder.restoreCallingIdentity(identity); |
| 7853 | } |
| 7854 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7855 | } |
| 7856 | |
| 7857 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7858 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7859 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7860 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7861 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7862 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7863 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7864 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7865 | "setLine1NumberForDisplayForSubscriber"); |
| 7866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7867 | final long identity = Binder.clearCallingIdentity(); |
| 7868 | try { |
| 7869 | final String iccId = getIccId(subId); |
| 7870 | final Phone phone = getPhone(subId); |
| 7871 | if (phone == null) { |
| 7872 | return false; |
| 7873 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7874 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7875 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7876 | return false; |
| 7877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7878 | final String subscriberId = phone.getSubscriberId(); |
| 7879 | |
| 7880 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7881 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7882 | + subscriberId + " to " + number); |
| 7883 | } |
| 7884 | |
| 7885 | if (TextUtils.isEmpty(iccId)) { |
| 7886 | return false; |
| 7887 | } |
| 7888 | |
| 7889 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7890 | |
| 7891 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7892 | if (alphaTag == null) { |
| 7893 | editor.remove(alphaTagPrefKey); |
| 7894 | } else { |
| 7895 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7896 | } |
| 7897 | |
| 7898 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7899 | // track all merged IMSIs based on line number |
| 7900 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7901 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7902 | if (number == null) { |
| 7903 | editor.remove(numberPrefKey); |
| 7904 | editor.remove(subscriberPrefKey); |
| 7905 | } else { |
| 7906 | editor.putString(numberPrefKey, number); |
| 7907 | editor.putString(subscriberPrefKey, subscriberId); |
| 7908 | } |
| 7909 | |
| 7910 | editor.commit(); |
| 7911 | return true; |
| 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7914 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7918 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7919 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7920 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7922 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7923 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7924 | return null; |
| 7925 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7926 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7927 | if (!mApp.getResources().getBoolean( |
| 7928 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7929 | enforceTelephonyFeatureWithException(callingPackage, |
| 7930 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7931 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7933 | final long identity = Binder.clearCallingIdentity(); |
| 7934 | try { |
| 7935 | String iccId = getIccId(subId); |
| 7936 | if (iccId != null) { |
| 7937 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7938 | if (DBG_MERGE) { |
| 7939 | log("getLine1NumberForDisplay returning " |
| 7940 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7941 | } |
| 7942 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7944 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7945 | return null; |
| 7946 | } finally { |
| 7947 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7948 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7949 | } |
| 7950 | |
| 7951 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7952 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7953 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7954 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7955 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7956 | return null; |
| 7957 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | final long identity = Binder.clearCallingIdentity(); |
| 7960 | try { |
| 7961 | String iccId = getIccId(subId); |
| 7962 | if (iccId != null) { |
| 7963 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7964 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7965 | } |
| 7966 | return null; |
| 7967 | } finally { |
| 7968 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7969 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7970 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7971 | |
| 7972 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7973 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7974 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7975 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7976 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7977 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7978 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7979 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7980 | return null; |
| 7981 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7982 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7983 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7984 | // the process, where TelephonyManager was instantiated. |
| 7985 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7986 | final long identity = Binder.clearCallingIdentity(); |
| 7987 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7988 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7989 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7990 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7991 | |
| 7992 | // Figure out what subscribers are currently active |
| 7993 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7994 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7995 | // Only consider subs which match the current subId |
| 7996 | // This logic can be simplified. See b/131189269 for progress. |
| 7997 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7998 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8000 | |
| 8001 | // First pass, find a number override for an active subscriber |
| 8002 | String mergeNumber = null; |
| 8003 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8004 | for (String key : prefs.keySet()) { |
| 8005 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8006 | final String subscriberId = (String) prefs.get(key); |
| 8007 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8008 | final String iccId = key.substring( |
| 8009 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8010 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8011 | mergeNumber = (String) prefs.get(numberKey); |
| 8012 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8013 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8014 | + " for active subscriber " + subscriberId); |
| 8015 | } |
| 8016 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8017 | break; |
| 8018 | } |
| 8019 | } |
| 8020 | } |
| 8021 | } |
| 8022 | |
| 8023 | // Shortcut when no active merged subscribers |
| 8024 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8025 | return null; |
| 8026 | } |
| 8027 | |
| 8028 | // Second pass, find all subscribers under that line override |
| 8029 | final ArraySet<String> result = new ArraySet<>(); |
| 8030 | for (String key : prefs.keySet()) { |
| 8031 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8032 | final String number = (String) prefs.get(key); |
| 8033 | if (mergeNumber.equals(number)) { |
| 8034 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8035 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8036 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8037 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8038 | result.add(subscriberId); |
| 8039 | } |
| 8040 | } |
| 8041 | } |
| 8042 | } |
| 8043 | |
| 8044 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8045 | Arrays.sort(resultArray); |
| 8046 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8047 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8049 | } |
| 8050 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8051 | } finally { |
| 8052 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8053 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8054 | } |
| 8055 | |
| 8056 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8057 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8058 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8059 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8060 | enforceTelephonyFeatureWithException(callingPackage, |
| 8061 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8062 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8063 | final long identity = Binder.clearCallingIdentity(); |
| 8064 | try { |
| 8065 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8066 | TelephonyManager.class); |
| 8067 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8068 | if (subscriberId == null) { |
| 8069 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8070 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8071 | + subId); |
| 8072 | } |
| 8073 | return null; |
| 8074 | } |
| 8075 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8076 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8077 | .getSubscriptionInfo(subId); |
| 8078 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8079 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8080 | if (groupUuid == null) { |
| 8081 | return new String[]{subscriberId}; |
| 8082 | } |
| 8083 | |
| 8084 | // Get all subscriberIds from the group. |
| 8085 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8086 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8087 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8088 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8089 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8090 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8091 | if (subscriberId != null) { |
| 8092 | mergedSubscriberIds.add(subscriberId); |
| 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8097 | } finally { |
| 8098 | Binder.restoreCallingIdentity(identity); |
| 8099 | |
| 8100 | } |
| 8101 | } |
| 8102 | |
| 8103 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8104 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8105 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8106 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8107 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8108 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8109 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8111 | final long identity = Binder.clearCallingIdentity(); |
| 8112 | try { |
| 8113 | final Phone phone = getPhone(subId); |
| 8114 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8115 | } finally { |
| 8116 | Binder.restoreCallingIdentity(identity); |
| 8117 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8118 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8119 | |
| 8120 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8121 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8122 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8123 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8124 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8125 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8126 | |
| 8127 | final long identity = Binder.clearCallingIdentity(); |
| 8128 | try { |
| 8129 | final Phone phone = getPhone(subId); |
| 8130 | if (phone == null) { |
| 8131 | return false; |
| 8132 | } |
| 8133 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8134 | cdmaNonRoamingList); |
| 8135 | } finally { |
| 8136 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8137 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8138 | } |
| 8139 | |
| 8140 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8141 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8142 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8143 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8144 | if (phone == null) { |
| 8145 | return raf; |
| 8146 | } |
| 8147 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8148 | try { |
| 8149 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8150 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8151 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8152 | } catch (SecurityException e) { |
| 8153 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8154 | throw e; |
| 8155 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8156 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8157 | if (!mApp.getResources().getBoolean( |
| 8158 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8159 | enforceTelephonyFeatureWithException(callingPackage, |
| 8160 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8161 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8163 | final long identity = Binder.clearCallingIdentity(); |
| 8164 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8165 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8166 | } finally { |
| 8167 | Binder.restoreCallingIdentity(identity); |
| 8168 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8169 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8170 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8171 | |
| 8172 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8173 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8174 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8175 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8176 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8177 | enforceTelephonyFeatureWithException(callingPackage, |
| 8178 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8179 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8180 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8181 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8182 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8183 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8184 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8185 | throw new SecurityException("App must be the dialer role holder to" |
| 8186 | + " upload a call composer pic"); |
| 8187 | } |
| 8188 | |
| 8189 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8190 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8191 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8192 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8193 | boolean readUntilEnd = false; |
| 8194 | int totalBytesRead = 0; |
| 8195 | byte[] buffer = new byte[16 * 1024]; |
| 8196 | while (true) { |
| 8197 | int numRead; |
| 8198 | try { |
| 8199 | numRead = input.read(buffer); |
| 8200 | } catch (IOException e) { |
| 8201 | try { |
| 8202 | fd.checkError(); |
| 8203 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8204 | null); |
| 8205 | } catch (IOException e1) { |
| 8206 | // This means that the other side closed explicitly with an error. If this |
| 8207 | // happens, log and ignore. |
| 8208 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8209 | } |
| 8210 | break; |
| 8211 | } |
| 8212 | if (numRead == -1) { |
| 8213 | readUntilEnd = true; |
| 8214 | break; |
| 8215 | } |
| 8216 | totalBytesRead += numRead; |
| 8217 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8218 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8219 | try { |
| 8220 | input.close(); |
| 8221 | } catch (IOException e) { |
| 8222 | // ignore |
| 8223 | } |
| 8224 | break; |
| 8225 | } |
| 8226 | output.write(buffer, 0, numRead); |
| 8227 | } |
| 8228 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8229 | // close is above, where the picture size is too big. |
| 8230 | |
| 8231 | try { |
| 8232 | fd.checkError(); |
| 8233 | } catch (IOException e) { |
| 8234 | loge("Remote end for call composer closed with an error: " + e); |
| 8235 | return; |
| 8236 | } |
| 8237 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8238 | if (!readUntilEnd) { |
| 8239 | loge("Did not finish reading entire image; aborting"); |
| 8240 | return; |
| 8241 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8242 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8243 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8244 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8245 | new CallComposerPictureTransfer.Factory() {}, |
| 8246 | imageData, |
| 8247 | (result) -> { |
| 8248 | if (result.first != null) { |
| 8249 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8250 | Bundle outputResult = new Bundle(); |
| 8251 | outputResult.putParcelable( |
| 8252 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8253 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8254 | outputResult); |
| 8255 | } else { |
| 8256 | callback.send(result.second, null); |
| 8257 | } |
| 8258 | } |
| 8259 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8260 | }); |
| 8261 | } |
| 8262 | |
| 8263 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8264 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8265 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8266 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8268 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8269 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8270 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8271 | final long identity = Binder.clearCallingIdentity(); |
| 8272 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8273 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8274 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | } finally { |
| 8276 | Binder.restoreCallingIdentity(identity); |
| 8277 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8281 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8282 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8283 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8284 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8285 | return false; |
| 8286 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8287 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8288 | enforceTelephonyFeatureWithException(callingPackage, |
| 8289 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8290 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | final long identity = Binder.clearCallingIdentity(); |
| 8292 | try { |
| 8293 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8294 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8295 | // In the long run, we may instead need to check if there exists a connection service |
| 8296 | // which can support video calling. |
| 8297 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8298 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | return imsManager.isVtEnabledByPlatform() |
| 8300 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8301 | && imsManager.isVtEnabledByUser(); |
| 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
| 8304 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8305 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8306 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8307 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8308 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8309 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8311 | mApp, subId, callingPackage, callingFeatureId, |
| 8312 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | return false; |
| 8314 | } |
| 8315 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8316 | enforceTelephonyFeatureWithException(callingPackage, |
| 8317 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8319 | final long identity = Binder.clearCallingIdentity(); |
| 8320 | try { |
| 8321 | CarrierConfigManager configManager = |
| 8322 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8323 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8324 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8325 | } finally { |
| 8326 | Binder.restoreCallingIdentity(identity); |
| 8327 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8328 | } |
| 8329 | |
| 8330 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8331 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8333 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | return false; |
| 8335 | } |
| 8336 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8337 | enforceTelephonyFeatureWithException(callingPackage, |
| 8338 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8340 | final long identity = Binder.clearCallingIdentity(); |
| 8341 | try { |
| 8342 | CarrierConfigManager configManager = |
| 8343 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8344 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8345 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8346 | } finally { |
| 8347 | Binder.restoreCallingIdentity(identity); |
| 8348 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8349 | } |
| 8350 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8351 | @Override |
| 8352 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8353 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8354 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8355 | } |
| 8356 | |
| 8357 | @Override |
| 8358 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8359 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8360 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8362 | final long identity = Binder.clearCallingIdentity(); |
| 8363 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8364 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8365 | } finally { |
| 8366 | Binder.restoreCallingIdentity(identity); |
| 8367 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8368 | } |
| 8369 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8370 | /** |
| 8371 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8372 | * support for the feature and device firmware support. |
| 8373 | * |
| 8374 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8375 | */ |
| 8376 | @Override |
| 8377 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8378 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8379 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8380 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8381 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8382 | final Phone phone = getPhone(subscriptionId); |
| 8383 | if (phone == null) { |
| 8384 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8385 | return false; |
| 8386 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8388 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8390 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8391 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8392 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8393 | return isCarrierSupported && isDeviceSupported; |
| 8394 | } finally { |
| 8395 | Binder.restoreCallingIdentity(identity); |
| 8396 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8397 | } |
| 8398 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8399 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8400 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8401 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8402 | * 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] | 8403 | */ |
| 8404 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | final long identity = Binder.clearCallingIdentity(); |
| 8406 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8407 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8408 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8409 | return false; |
| 8410 | } |
| 8411 | } |
| 8412 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8413 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8414 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8415 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8416 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8417 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8418 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8419 | } finally { |
| 8420 | Binder.restoreCallingIdentity(identity); |
| 8421 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8422 | } |
| 8423 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8424 | @Deprecated |
| 8425 | @Override |
| 8426 | public String getDeviceId(String callingPackage) { |
| 8427 | return getDeviceIdWithFeature(callingPackage, null); |
| 8428 | } |
| 8429 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8430 | /** |
| 8431 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8432 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8433 | * |
| 8434 | * <p>Requires Permission: |
| 8435 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8436 | */ |
| 8437 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8438 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8439 | try { |
| 8440 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8441 | } catch (SecurityException se) { |
| 8442 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8443 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8444 | + Binder.getCallingUid()); |
| 8445 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8446 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8447 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8448 | return null; |
| 8449 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8450 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8451 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8452 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8453 | return null; |
| 8454 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8455 | |
| 8456 | final long identity = Binder.clearCallingIdentity(); |
| 8457 | try { |
| 8458 | return phone.getDeviceId(); |
| 8459 | } finally { |
| 8460 | Binder.restoreCallingIdentity(identity); |
| 8461 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8462 | } |
| 8463 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8464 | /** |
| 8465 | * {@hide} |
| 8466 | * Returns the IMS Registration Status on a particular subid |
| 8467 | * |
| 8468 | * @param subId |
| 8469 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8470 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8471 | Phone phone = getPhone(subId); |
| 8472 | if (phone != null) { |
| 8473 | return phone.isImsRegistered(); |
| 8474 | } else { |
| 8475 | return false; |
| 8476 | } |
| 8477 | } |
| 8478 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8479 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8480 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8481 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8482 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8483 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8484 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8485 | } |
| 8486 | final long identity = Binder.clearCallingIdentity(); |
| 8487 | try { |
| 8488 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8489 | } finally { |
| 8490 | Binder.restoreCallingIdentity(identity); |
| 8491 | } |
| 8492 | } |
| 8493 | |
| 8494 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8495 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8496 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8497 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8498 | mApp, |
| 8499 | subscriptionId, |
| 8500 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8501 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8502 | |
| 8503 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8504 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8505 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8506 | final long identity = Binder.clearCallingIdentity(); |
| 8507 | try { |
| 8508 | Phone phone = getPhone(subscriptionId); |
| 8509 | if (phone == null) { |
| 8510 | return null; |
| 8511 | } |
| 8512 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8513 | } finally { |
| 8514 | Binder.restoreCallingIdentity(identity); |
| 8515 | } |
| 8516 | } |
| 8517 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8518 | /** |
| 8519 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8520 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8521 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8522 | final long identity = Binder.clearCallingIdentity(); |
| 8523 | try { |
| 8524 | Phone phone = getPhone(subId); |
| 8525 | if (phone != null) { |
| 8526 | return phone.isWifiCallingEnabled(); |
| 8527 | } else { |
| 8528 | return false; |
| 8529 | } |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8532 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8533 | } |
| 8534 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8535 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8536 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8537 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8538 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8539 | final long identity = Binder.clearCallingIdentity(); |
| 8540 | try { |
| 8541 | Phone phone = getPhone(subId); |
| 8542 | if (phone != null) { |
| 8543 | return phone.isVideoEnabled(); |
| 8544 | } else { |
| 8545 | return false; |
| 8546 | } |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8549 | } |
| 8550 | } |
| 8551 | |
| 8552 | /** |
| 8553 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8554 | * defined in {@link ImsRegistrationImplBase}. |
| 8555 | */ |
| 8556 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8557 | final long identity = Binder.clearCallingIdentity(); |
| 8558 | try { |
| 8559 | Phone phone = getPhone(subId); |
| 8560 | if (phone != null) { |
| 8561 | return phone.getImsRegistrationTech(); |
| 8562 | } else { |
| 8563 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8564 | } |
| 8565 | } finally { |
| 8566 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8567 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8568 | } |
| 8569 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8570 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8571 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8572 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8573 | |
| 8574 | enforceTelephonyFeatureWithException(callingPackage, |
| 8575 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8576 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8577 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8578 | return; |
| 8579 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8580 | Phone defaultPhone = getDefaultPhone(); |
| 8581 | if (defaultPhone != null) { |
| 8582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8583 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8584 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8585 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8586 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8587 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8588 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8589 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8590 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8591 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8592 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8593 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8594 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8595 | setDataRoamingEnabled(subId, phone == null ? false |
| 8596 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8597 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8598 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8599 | // There has been issues when Sms raw table somehow stores orphan |
| 8600 | // fragments. They lead to garbled message when new fragments come |
| 8601 | // in and combined with those stale ones. In case this happens again, |
| 8602 | // user can reset all network settings which will clean up this table. |
| 8603 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8604 | // Clean up IMS settings as well here. |
| 8605 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8606 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8607 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8608 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8609 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8610 | if (defaultPhone == null) { |
| 8611 | return; |
| 8612 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8613 | // Erase modem config if erase modem on network setting is enabled. |
| 8614 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8615 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8616 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8617 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8618 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8619 | |
| 8620 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8623 | } |
| 8624 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8625 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8626 | @VisibleForTesting |
| 8627 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8628 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8629 | return; |
| 8630 | } |
| 8631 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8632 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8633 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8634 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8635 | "user=" + defaultNetworkType); |
| 8636 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8637 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8638 | defaultNetworkType, null); |
| 8639 | } |
| 8640 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8641 | private void cleanUpSmsRawTable(Context context) { |
| 8642 | ContentResolver resolver = context.getContentResolver(); |
| 8643 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8644 | resolver.delete(uri, null, null); |
| 8645 | } |
| 8646 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8647 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8648 | public String getSimLocaleForSubscriber(int subId) { |
| 8649 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8650 | |
| 8651 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8652 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8653 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8654 | final Phone phone = getPhone(subId); |
| 8655 | if (phone == null) { |
| 8656 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8657 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8659 | final long identity = Binder.clearCallingIdentity(); |
| 8660 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8661 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8662 | phone.getContext().getOpPackageName(), |
| 8663 | phone.getContext().getAttributionTag()); |
| 8664 | if (info == null) { |
| 8665 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8666 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8668 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8669 | // preferences (EF-PL and EF-LI)... |
| 8670 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8671 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8672 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8673 | if (localeFromDefaultSim != null) { |
| 8674 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8675 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8676 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8677 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8678 | } else { |
| 8679 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8680 | } |
| 8681 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8683 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8684 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8685 | // the SIM and carrier preferences does not include a country we add the country |
| 8686 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8687 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8688 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8689 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8690 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8691 | } |
| 8692 | |
| 8693 | if (DBG) log("No locale found - returning null"); |
| 8694 | return null; |
| 8695 | } finally { |
| 8696 | Binder.restoreCallingIdentity(identity); |
| 8697 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8698 | } |
| 8699 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8700 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8701 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8702 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8703 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8704 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8705 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8706 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8707 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8708 | return localeTag; |
| 8709 | } |
| 8710 | } |
| 8711 | return inputLocale.toLanguageTag(); |
| 8712 | } |
| 8713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8714 | /** |
| 8715 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8716 | */ |
| 8717 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8718 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8719 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8720 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8721 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8722 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8723 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8724 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8725 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8726 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8727 | * representing the state of the modem. |
| 8728 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8729 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8730 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8731 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8732 | */ |
| 8733 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8734 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8735 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8736 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8737 | if (!mApp.getResources().getBoolean( |
| 8738 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8739 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8740 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8741 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8742 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8743 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8744 | |
| 8745 | final long identity = Binder.clearCallingIdentity(); |
| 8746 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8747 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8748 | } finally { |
| 8749 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8750 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8751 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8752 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8753 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8754 | // less than total activity duration. |
| 8755 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8756 | if (info == null) { |
| 8757 | return false; |
| 8758 | } |
| 8759 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8760 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8761 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8762 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8763 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8764 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8765 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8766 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8767 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8768 | } |
| 8769 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8770 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8771 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8772 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8773 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8774 | |
| 8775 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8776 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8777 | } |
| 8778 | |
| 8779 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8780 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8781 | rat, |
| 8782 | freq, |
| 8783 | info.getReceiveTimeMillis(rat, freq) |
| 8784 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8785 | } |
| 8786 | |
| 8787 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8788 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8789 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8790 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8791 | |
| 8792 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8793 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8794 | } |
| 8795 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8796 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8797 | rat, |
| 8798 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8799 | } |
| 8800 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8801 | /** |
| 8802 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8803 | * @param info recent ModemActivityInfo |
| 8804 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8805 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8806 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8807 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8808 | boolean matched; |
| 8809 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8810 | matched = false; |
| 8811 | int rat = info.getSpecificInfoRat(i); |
| 8812 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8813 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8814 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8815 | //if it already exists |
| 8816 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8817 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8818 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8819 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8820 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8821 | updateLastModemActivityInfo(info, rat, freq); |
| 8822 | matched = true; |
| 8823 | } |
| 8824 | } else { |
| 8825 | updateLastModemActivityInfo(info, rat); |
| 8826 | matched = true; |
| 8827 | } |
| 8828 | } |
| 8829 | } |
| 8830 | |
| 8831 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8832 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8833 | new ActivityStatsTechSpecificInfo( |
| 8834 | rat, |
| 8835 | freq, |
| 8836 | info.getTransmitTimeMillis(rat, freq), |
| 8837 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8838 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8839 | } |
| 8840 | } |
| 8841 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8842 | mLastModemActivitySpecificInfo = |
| 8843 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8844 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8845 | |
| 8846 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8847 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8848 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8849 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8850 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8851 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8852 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8853 | |
| 8854 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8855 | new ModemActivityInfo( |
| 8856 | mLastModemActivityInfo.getTimestampMillis(), |
| 8857 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8858 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8859 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8860 | } |
| 8861 | |
| 8862 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8863 | ActivityStatsTechSpecificInfo[] info) { |
| 8864 | int infoSize = info.length; |
| 8865 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8866 | for (int i = 0; i < infoSize; i++) { |
| 8867 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8868 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8869 | info[i].getTransmitTimeMillis(), |
| 8870 | (int) info[i].getReceiveTimeMillis()); |
| 8871 | } |
| 8872 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8873 | } |
| 8874 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8875 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8876 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8877 | */ |
| 8878 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8879 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8880 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8881 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8882 | if (phone == null) { |
| 8883 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8884 | return null; |
| 8885 | } |
| 8886 | |
| 8887 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8888 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8889 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8890 | return null; |
| 8891 | } |
| 8892 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8893 | enforceTelephonyFeatureWithException(callingPackage, |
| 8894 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8895 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8896 | boolean hasFinePermission = false; |
| 8897 | boolean hasCoarsePermission = false; |
| 8898 | if (!renounceFineLocationAccess) { |
| 8899 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8900 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8901 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8902 | .setCallingPackage(callingPackage) |
| 8903 | .setCallingFeatureId(callingFeatureId) |
| 8904 | .setCallingPid(Binder.getCallingPid()) |
| 8905 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8906 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8907 | .setLogAsInfo(true) |
| 8908 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8909 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8910 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8911 | .build()); |
| 8912 | hasFinePermission = |
| 8913 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8914 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8915 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8916 | if (!renounceCoarseLocationAccess) { |
| 8917 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8918 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8919 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8920 | .setCallingPackage(callingPackage) |
| 8921 | .setCallingFeatureId(callingFeatureId) |
| 8922 | .setCallingPid(Binder.getCallingPid()) |
| 8923 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8924 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8925 | .setLogAsInfo(true) |
| 8926 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8927 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8928 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8929 | .build()); |
| 8930 | hasCoarsePermission = |
| 8931 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8932 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8933 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8934 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8935 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8936 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8937 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8938 | if (subInfo != null && !subInfo.isActive()) { |
| 8939 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8940 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8941 | } |
| 8942 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8943 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8944 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8945 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8946 | |
| 8947 | // Scrub out the location info in ServiceState depending on what level of access |
| 8948 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8949 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8950 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8951 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8952 | } finally { |
| 8953 | Binder.restoreCallingIdentity(identity); |
| 8954 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8955 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8956 | |
| 8957 | /** |
| 8958 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8959 | * |
| 8960 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8961 | * voicemail ringtone. |
| 8962 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8963 | * PhoneAccount. |
| 8964 | */ |
| 8965 | @Override |
| 8966 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8967 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8968 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8970 | final long identity = Binder.clearCallingIdentity(); |
| 8971 | try { |
| 8972 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8973 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8974 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8977 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8978 | } finally { |
| 8979 | Binder.restoreCallingIdentity(identity); |
| 8980 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8981 | } |
| 8982 | |
| 8983 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8984 | * Sets the per-account voicemail ringtone. |
| 8985 | * |
| 8986 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8987 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8988 | * |
| 8989 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8990 | * voicemail ringtone. |
| 8991 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8992 | * PhoneAccount. |
| 8993 | */ |
| 8994 | @Override |
| 8995 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8996 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8997 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8998 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8999 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9000 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9002 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9003 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9005 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9006 | enforceTelephonyFeatureWithException(callingPackage, |
| 9007 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9009 | final long identity = Binder.clearCallingIdentity(); |
| 9010 | try { |
| 9011 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9012 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9013 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9014 | } |
| 9015 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9016 | } finally { |
| 9017 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9018 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9019 | } |
| 9020 | |
| 9021 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9022 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9023 | * |
| 9024 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9025 | * voicemail vibration setting. |
| 9026 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9027 | */ |
| 9028 | @Override |
| 9029 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9030 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9031 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9033 | final long identity = Binder.clearCallingIdentity(); |
| 9034 | try { |
| 9035 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9036 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9037 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9038 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9039 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9040 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9041 | } finally { |
| 9042 | Binder.restoreCallingIdentity(identity); |
| 9043 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9044 | } |
| 9045 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9046 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9047 | * Sets the per-account voicemail vibration. |
| 9048 | * |
| 9049 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9050 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9051 | * |
| 9052 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9053 | * voicemail vibration setting. |
| 9054 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9055 | * specific PhoneAccount. |
| 9056 | */ |
| 9057 | @Override |
| 9058 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9059 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9060 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9061 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9062 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9063 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9065 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9066 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9067 | } |
| 9068 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9069 | enforceTelephonyFeatureWithException(callingPackage, |
| 9070 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9072 | final long identity = Binder.clearCallingIdentity(); |
| 9073 | try { |
| 9074 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9075 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9076 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9077 | } |
| 9078 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9079 | } finally { |
| 9080 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9081 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9082 | } |
| 9083 | |
| 9084 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9085 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9086 | * |
| 9087 | * @throws SecurityException if the caller does not have the required permission |
| 9088 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9089 | @VisibleForTesting |
| 9090 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9091 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9092 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9093 | } |
| 9094 | |
| 9095 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9096 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9097 | * permission. |
| 9098 | * |
| 9099 | * @throws SecurityException if the caller does not have the required permission |
| 9100 | */ |
| 9101 | private void enforceSendSmsPermission() { |
| 9102 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9106 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9107 | * users permission. |
| 9108 | * |
| 9109 | * @throws SecurityException if the caller does not have the required permission |
| 9110 | */ |
| 9111 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9112 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9113 | } |
| 9114 | |
| 9115 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9116 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9117 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9118 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9119 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9120 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9121 | final long identity = Binder.clearCallingIdentity(); |
| 9122 | try { |
| 9123 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9124 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9125 | if (componentName == null) { |
| 9126 | throw new SecurityException( |
| 9127 | "Caller not current active visual voicemail package[null]"); |
| 9128 | } |
| 9129 | String vvmPackage = componentName.getPackageName(); |
| 9130 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9131 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9132 | } |
| 9133 | } finally { |
| 9134 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9135 | } |
| 9136 | } |
| 9137 | |
| 9138 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9139 | * Return the application ID for the app type. |
| 9140 | * |
| 9141 | * @param subId the subscription ID that this request applies to. |
| 9142 | * @param appType the uicc app type. |
| 9143 | * @return Application ID for specificied app type, or null if no uicc. |
| 9144 | */ |
| 9145 | @Override |
| 9146 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9147 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9148 | |
| 9149 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9150 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9151 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9152 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9153 | |
| 9154 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9155 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9156 | if (phone == null) { |
| 9157 | return null; |
| 9158 | } |
| 9159 | String aid = null; |
| 9160 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9161 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9162 | .getApplicationByType(appType).getAid(); |
| 9163 | } catch (Exception e) { |
| 9164 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9165 | } |
| 9166 | return aid; |
| 9167 | } finally { |
| 9168 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9169 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9170 | } |
| 9171 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9172 | /** |
| 9173 | * Return the Electronic Serial Number. |
| 9174 | * |
| 9175 | * @param subId the subscription ID that this request applies to. |
| 9176 | * @return ESN or null if error. |
| 9177 | */ |
| 9178 | @Override |
| 9179 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9180 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9181 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9182 | |
| 9183 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9184 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9185 | if (phone == null) { |
| 9186 | return null; |
| 9187 | } |
| 9188 | String esn = null; |
| 9189 | try { |
| 9190 | esn = phone.getEsn(); |
| 9191 | } catch (Exception e) { |
| 9192 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9193 | } |
| 9194 | return esn; |
| 9195 | } finally { |
| 9196 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9197 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9198 | } |
| 9199 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9200 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9201 | * Return the Preferred Roaming List Version. |
| 9202 | * |
| 9203 | * @param subId the subscription ID that this request applies to. |
| 9204 | * @return PRLVersion or null if error. |
| 9205 | */ |
| 9206 | @Override |
| 9207 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9208 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9209 | |
| 9210 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9211 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9212 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9213 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9214 | |
| 9215 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9216 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9217 | if (phone == null) { |
| 9218 | return null; |
| 9219 | } |
| 9220 | String cdmaPrlVersion = null; |
| 9221 | try { |
| 9222 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9223 | } catch (Exception e) { |
| 9224 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9225 | } |
| 9226 | return cdmaPrlVersion; |
| 9227 | } finally { |
| 9228 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9229 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9230 | } |
| 9231 | |
| 9232 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9233 | * Get snapshot of Telephony histograms |
| 9234 | * @return List of Telephony histograms |
| 9235 | * @hide |
| 9236 | */ |
| 9237 | @Override |
| 9238 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9240 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9241 | |
| 9242 | final long identity = Binder.clearCallingIdentity(); |
| 9243 | try { |
| 9244 | return RIL.getTelephonyRILTimingHistograms(); |
| 9245 | } finally { |
| 9246 | Binder.restoreCallingIdentity(identity); |
| 9247 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9248 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9249 | |
| 9250 | /** |
| 9251 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9252 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9253 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9254 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9255 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9256 | * @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] | 9257 | */ |
| 9258 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9259 | @TelephonyManager.SetCarrierRestrictionResult |
| 9260 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9261 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9262 | |
| 9263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9264 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9265 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9266 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9267 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9268 | if (carrierRestrictionRules == null) { |
| 9269 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9270 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9271 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9272 | final long identity = Binder.clearCallingIdentity(); |
| 9273 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9274 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9275 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9276 | } finally { |
| 9277 | Binder.restoreCallingIdentity(identity); |
| 9278 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9279 | } |
| 9280 | |
| 9281 | /** |
| 9282 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9283 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9284 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9285 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9286 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9287 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9288 | */ |
| 9289 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9290 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9291 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9292 | |
| 9293 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9294 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9295 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9296 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9297 | |
| 9298 | final long identity = Binder.clearCallingIdentity(); |
| 9299 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9300 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9301 | if (response instanceof CarrierRestrictionRules) { |
| 9302 | return (CarrierRestrictionRules) response; |
| 9303 | } |
| 9304 | // Response is an Exception of some kind, |
| 9305 | // which is signalled to the user as a NULL retval |
| 9306 | return null; |
| 9307 | } catch (Exception e) { |
| 9308 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9309 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9310 | } finally { |
| 9311 | Binder.restoreCallingIdentity(identity); |
| 9312 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9313 | } |
| 9314 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9315 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9316 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9317 | * through the callback. |
| 9318 | * |
| 9319 | * @param callback The callback that will be used to send the result. |
| 9320 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9321 | * the caller is not allowlisted. |
| 9322 | */ |
| 9323 | @Override |
| 9324 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9325 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9326 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9327 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9328 | try { |
| 9329 | mApp.enforceCallingOrSelfPermission( |
| 9330 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9331 | functionName); |
| 9332 | } catch (SecurityException e) { |
| 9333 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9334 | functionName); |
| 9335 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9336 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9337 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9338 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9339 | throw new SecurityException("Not an authorized caller"); |
| 9340 | } |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9344 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9345 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9346 | } finally { |
| 9347 | Binder.restoreCallingIdentity(identity); |
| 9348 | } |
| 9349 | } |
| 9350 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9351 | @Override |
| 9352 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9353 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9354 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9355 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9356 | } |
| 9357 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9358 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9359 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9360 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9361 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9365 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9366 | * @param subId the subscription ID that this action applies to. |
| 9367 | * @param enabled control enable or disable radio. |
| 9368 | * {@hide} |
| 9369 | */ |
| 9370 | @Override |
| 9371 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9372 | enforceModifyPermission(); |
| 9373 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9374 | |
| 9375 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9376 | if (phone == null) { |
| 9377 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9378 | return; |
| 9379 | } |
| 9380 | try { |
| 9381 | phone.carrierActionSetRadioEnabled(enabled); |
| 9382 | } catch (Exception e) { |
| 9383 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9384 | } finally { |
| 9385 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9386 | } |
| 9387 | } |
| 9388 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9389 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9390 | * Enable or disable Voice over NR (VoNR) |
| 9391 | * @param subId the subscription ID that this action applies to. |
| 9392 | * @param enabled enable or disable VoNR. |
| 9393 | * @return operation result. |
| 9394 | */ |
| 9395 | @Override |
| 9396 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9397 | enforceModifyPermission(); |
| 9398 | final Phone phone = getPhone(subId); |
| 9399 | |
| 9400 | final long identity = Binder.clearCallingIdentity(); |
| 9401 | if (phone == null) { |
| 9402 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9403 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9404 | } |
| 9405 | |
| 9406 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9407 | try { |
| 9408 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9409 | workSource); |
| 9410 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9411 | |
| 9412 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9413 | if (DBG) { |
| 9414 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9415 | } |
| 9416 | SubscriptionManager.setSubscriptionProperty( |
| 9417 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9418 | (enabled ? "1" : "0")); |
| 9419 | } |
| 9420 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9421 | return result; |
| 9422 | } finally { |
| 9423 | Binder.restoreCallingIdentity(identity); |
| 9424 | } |
| 9425 | } |
| 9426 | |
| 9427 | /** |
| 9428 | * Is voice over NR enabled |
| 9429 | * @return true if VoNR is enabled else false |
| 9430 | */ |
| 9431 | @Override |
| 9432 | public boolean isVoNrEnabled(int subId) { |
| 9433 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9434 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9435 | final long identity = Binder.clearCallingIdentity(); |
| 9436 | try { |
| 9437 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9438 | null, subId, workSource); |
| 9439 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9440 | return isEnabled; |
| 9441 | } finally { |
| 9442 | Binder.restoreCallingIdentity(identity); |
| 9443 | } |
| 9444 | } |
| 9445 | |
| 9446 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9447 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9448 | * network status based on which carrier apps could apply actions accordingly, |
| 9449 | * enable/disable default url handler for example. |
| 9450 | * |
| 9451 | * @param subId the subscription ID that this action applies to. |
| 9452 | * @param report control start/stop reporting the default network status. |
| 9453 | * {@hide} |
| 9454 | */ |
| 9455 | @Override |
| 9456 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9457 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9458 | |
| 9459 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9460 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9461 | "carrierActionReportDefaultNetworkStatus"); |
| 9462 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9463 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9464 | |
| 9465 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9466 | if (phone == null) { |
| 9467 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9468 | return; |
| 9469 | } |
| 9470 | try { |
| 9471 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9472 | } catch (Exception e) { |
| 9473 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9474 | } finally { |
| 9475 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9476 | } |
| 9477 | } |
| 9478 | |
| 9479 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9480 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9481 | * @param subId the subscription ID that this action applies to. |
| 9482 | * {@hide} |
| 9483 | */ |
| 9484 | @Override |
| 9485 | public void carrierActionResetAll(int subId) { |
| 9486 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9487 | |
| 9488 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9489 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9490 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9491 | final Phone phone = getPhone(subId); |
| 9492 | if (phone == null) { |
| 9493 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9494 | return; |
| 9495 | } |
| 9496 | try { |
| 9497 | phone.carrierActionResetAll(); |
| 9498 | } catch (Exception e) { |
| 9499 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9500 | } |
| 9501 | } |
| 9502 | |
| 9503 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9504 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9505 | * bug report is being generated. |
| 9506 | */ |
| 9507 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9508 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9509 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9510 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9511 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9512 | + Binder.getCallingPid() |
| 9513 | + ", uid=" + Binder.getCallingUid() |
| 9514 | + "without permission " |
| 9515 | + android.Manifest.permission.DUMP); |
| 9516 | return; |
| 9517 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9518 | try { |
| 9519 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9520 | } catch (Exception e) { |
| 9521 | writer.println("Failed to dump phone information: " + e); |
| 9522 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9523 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9524 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9525 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9526 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9527 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9528 | @NonNull String[] args) { |
| 9529 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9530 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9531 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9532 | } |
| 9533 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9534 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9535 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9536 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9537 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9538 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9539 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9540 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9541 | */ |
| 9542 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9543 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9544 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9545 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9546 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9547 | try { |
| 9548 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9549 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9550 | } catch (SecurityException se) { |
| 9551 | enforceModifyPermission(); |
| 9552 | } |
| 9553 | } else { |
| 9554 | enforceModifyPermission(); |
| 9555 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9556 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9557 | enforceTelephonyFeatureWithException(callingPackage, |
| 9558 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9559 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9560 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9561 | final long identity = Binder.clearCallingIdentity(); |
| 9562 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9563 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9564 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9565 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9566 | callingUid, callingPackage, null, null); |
| 9567 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9568 | Phone phone = getPhone(subId); |
| 9569 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9570 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9571 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9572 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9573 | phone.getDataSettingsManager().setDataEnabled( |
| 9574 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9575 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9576 | } |
| 9577 | } finally { |
| 9578 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9579 | } |
| 9580 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9581 | |
| 9582 | /** |
| 9583 | * Get Client request stats |
| 9584 | * @return List of Client Request Stats |
| 9585 | * @hide |
| 9586 | */ |
| 9587 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9588 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9589 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9591 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9592 | return null; |
| 9593 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9594 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | if (phone != null) { |
| 9599 | return phone.getClientRequestStats(); |
| 9600 | } |
| 9601 | |
| 9602 | return null; |
| 9603 | } finally { |
| 9604 | Binder.restoreCallingIdentity(identity); |
| 9605 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9606 | } |
| 9607 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9608 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9609 | PackageManager pm; |
| 9610 | if (mFeatureFlags.hsumPackageManager()) { |
| 9611 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9612 | .getPackageManager(); |
| 9613 | } else { |
| 9614 | pm = mApp.getPackageManager(); |
| 9615 | } |
| 9616 | |
| 9617 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9618 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9619 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9620 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9621 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9622 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9623 | // commands that plumb through the RIL as root, like so: |
| 9624 | // $ adb root |
| 9625 | // $ adb shell cmd phone ... |
| 9626 | packageName = "root"; |
| 9627 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9628 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9629 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9630 | |
| 9631 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9632 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9633 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9634 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9635 | * @param state State of SIM (power down, power up, pass through) |
| 9636 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9637 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9638 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9639 | * |
| 9640 | **/ |
| 9641 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9642 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9643 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9644 | |
| 9645 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9646 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9647 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9648 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9649 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9650 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9651 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9652 | final long identity = Binder.clearCallingIdentity(); |
| 9653 | try { |
| 9654 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9655 | phone.setSimPowerState(state, null, workSource); |
| 9656 | } |
| 9657 | } finally { |
| 9658 | Binder.restoreCallingIdentity(identity); |
| 9659 | } |
| 9660 | } |
| 9661 | |
| 9662 | /** |
| 9663 | * Set SIM card power state. |
| 9664 | * |
| 9665 | * @param slotIndex SIM slot id. |
| 9666 | * @param state State of SIM (power down, power up, pass through) |
| 9667 | * @param callback callback to trigger after success or failure |
| 9668 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9669 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9670 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9671 | * |
| 9672 | **/ |
| 9673 | @Override |
| 9674 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9675 | IIntegerConsumer callback) { |
| 9676 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9677 | |
| 9678 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9679 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9680 | "setSimPowerStateForSlotWithCallback"); |
| 9681 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9682 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9683 | |
| 9684 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9685 | |
| 9686 | final long identity = Binder.clearCallingIdentity(); |
| 9687 | try { |
| 9688 | if (phone != null) { |
| 9689 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9690 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9691 | } |
| 9692 | } finally { |
| 9693 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9694 | } |
| 9695 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9696 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9697 | private boolean isUssdApiAllowed(int subId) { |
| 9698 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9699 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9700 | if (configManager == null) { |
| 9701 | return false; |
| 9702 | } |
| 9703 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9704 | if (pb == null) { |
| 9705 | return false; |
| 9706 | } |
| 9707 | return pb.getBoolean( |
| 9708 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9709 | } |
| 9710 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9711 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9712 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9713 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9714 | * @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] | 9715 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9716 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9717 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9718 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9719 | |
| 9720 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9721 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9723 | final long identity = Binder.clearCallingIdentity(); |
| 9724 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9725 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9726 | } finally { |
| 9727 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9728 | } |
| 9729 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9730 | |
| 9731 | /** |
| 9732 | * Get the current signal strength information for the given subscription. |
| 9733 | * Because this information is not updated when the device is in a low power state |
| 9734 | * it should not be relied-upon to be current. |
| 9735 | * @param subId Subscription index |
| 9736 | * @return the most recent cached signal strength info from the modem |
| 9737 | */ |
| 9738 | @Override |
| 9739 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9740 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9741 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9742 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9743 | final long identity = Binder.clearCallingIdentity(); |
| 9744 | try { |
| 9745 | Phone p = getPhone(subId); |
| 9746 | if (p == null) { |
| 9747 | return null; |
| 9748 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9750 | return p.getSignalStrength(); |
| 9751 | } finally { |
| 9752 | Binder.restoreCallingIdentity(identity); |
| 9753 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9754 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9755 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9756 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9757 | * Get the current modem radio state for the given slot. |
| 9758 | * @param slotIndex slot index. |
| 9759 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9760 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9761 | * @return the current radio power state from the modem |
| 9762 | */ |
| 9763 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9764 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9766 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9768 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9769 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9770 | } |
| 9771 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9772 | enforceTelephonyFeatureWithException(callingPackage, |
| 9773 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9774 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9775 | final long identity = Binder.clearCallingIdentity(); |
| 9776 | try { |
| 9777 | return phone.getRadioPowerState(); |
| 9778 | } finally { |
| 9779 | Binder.restoreCallingIdentity(identity); |
| 9780 | } |
| 9781 | } |
| 9782 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9783 | } |
| 9784 | |
| 9785 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9786 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9787 | * |
| 9788 | * <p>Requires one of the following permissions: |
| 9789 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9790 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9791 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9792 | * privileges. |
| 9793 | * |
| 9794 | * @param subId subscription id |
| 9795 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9796 | * {@code false}. |
| 9797 | */ |
| 9798 | @Override |
| 9799 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9800 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9801 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9802 | try { |
| 9803 | mApp.enforceCallingOrSelfPermission( |
| 9804 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9805 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9806 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9807 | mApp.enforceCallingOrSelfPermission( |
| 9808 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9809 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9810 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9811 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9812 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9813 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9814 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9815 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9816 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9817 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9818 | boolean isEnabled = false; |
| 9819 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9820 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9821 | Phone phone = getPhone(subId); |
| 9822 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9823 | } finally { |
| 9824 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9825 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9826 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9827 | } |
| 9828 | |
| 9829 | |
| 9830 | /** |
| 9831 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9832 | * |
| 9833 | * <p> Requires permission: |
| 9834 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9835 | * privileges. |
| 9836 | * |
| 9837 | * @param subId subscription id |
| 9838 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9839 | */ |
| 9840 | @Override |
| 9841 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9842 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9843 | mApp, subId, "setDataRoamingEnabled"); |
| 9844 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9845 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9846 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9847 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9848 | final long identity = Binder.clearCallingIdentity(); |
| 9849 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9850 | Phone phone = getPhone(subId); |
| 9851 | if (phone != null) { |
| 9852 | phone.setDataRoamingEnabled(isEnabled); |
| 9853 | } |
| 9854 | } finally { |
| 9855 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9856 | } |
| 9857 | } |
| 9858 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9859 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9860 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9861 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9862 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9863 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9864 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9865 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9866 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9867 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9868 | boolean isAllowed = true; |
| 9869 | final long identity = Binder.clearCallingIdentity(); |
| 9870 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9871 | Phone phone = getPhone(subId); |
| 9872 | if (phone != null) { |
| 9873 | isAllowed = phone.isCspPlmnEnabled(); |
| 9874 | } |
| 9875 | } finally { |
| 9876 | Binder.restoreCallingIdentity(identity); |
| 9877 | } |
| 9878 | return isAllowed; |
| 9879 | } |
| 9880 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9881 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9882 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9883 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9884 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9885 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9886 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9887 | if (phone == null) { |
| 9888 | return false; |
| 9889 | } |
| 9890 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9891 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9892 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9893 | } |
| 9894 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9895 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9896 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9897 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9898 | mApp.getSystemService(AppOpsManager.class) |
| 9899 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9900 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9901 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9902 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9903 | try { |
| 9904 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9905 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9906 | } catch (SecurityException e) { |
| 9907 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9908 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9909 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9910 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9911 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9912 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9913 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9914 | |
| 9915 | enforceTelephonyFeatureWithException(callingPackage, |
| 9916 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9917 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9918 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9919 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9920 | Binder.getCallingUid())) { |
| 9921 | isIccIdAccessRestricted = true; |
| 9922 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9923 | final long identity = Binder.clearCallingIdentity(); |
| 9924 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9925 | UiccController uiccController = UiccController.getInstance(); |
| 9926 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9927 | if (hasReadPermission) { |
| 9928 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9929 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9930 | |
| 9931 | // Remove private info if the caller doesn't have access |
| 9932 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9933 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9934 | //setting the value after compatibility check |
| 9935 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9936 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9937 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9938 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9939 | if (card == null) { |
| 9940 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9941 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9942 | continue; |
| 9943 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9944 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9945 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9946 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9947 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9948 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9949 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9950 | for (UiccPortInfo portInfo : portInfos) { |
| 9951 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9952 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9953 | if (port == null) { |
| 9954 | // assume no access if port is null |
| 9955 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9956 | continue; |
| 9957 | } |
| 9958 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9959 | uiccPortInfos.add(portInfo); |
| 9960 | } else { |
| 9961 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9962 | } |
| 9963 | } |
| 9964 | filteredInfos.add(new UiccCardInfo( |
| 9965 | cardInfo.isEuicc(), |
| 9966 | cardInfo.getCardId(), |
| 9967 | null, |
| 9968 | cardInfo.getPhysicalSlotIndex(), |
| 9969 | cardInfo.isRemovable(), |
| 9970 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9971 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9972 | } |
| 9973 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9974 | } finally { |
| 9975 | Binder.restoreCallingIdentity(identity); |
| 9976 | } |
| 9977 | } |
| 9978 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9979 | /** |
| 9980 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9981 | * generally private and require carrier privileges to view. |
| 9982 | * |
| 9983 | * @hide |
| 9984 | */ |
| 9985 | @NonNull |
| 9986 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9987 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9988 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9989 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9990 | } |
| 9991 | return new UiccCardInfo( |
| 9992 | cardInfo.isEuicc(), |
| 9993 | cardInfo.getCardId(), |
| 9994 | null, |
| 9995 | cardInfo.getPhysicalSlotIndex(), |
| 9996 | cardInfo.isRemovable(), |
| 9997 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9998 | portinfo |
| 9999 | ); |
| 10000 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10001 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10002 | /** |
| 10003 | * @hide |
| 10004 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10005 | * These values are generally private and require carrier privileges to view. |
| 10006 | */ |
| 10007 | @NonNull |
| 10008 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10009 | return new UiccPortInfo( |
| 10010 | UiccPortInfo.ICCID_REDACTED, |
| 10011 | portInfo.getPortIndex(), |
| 10012 | portInfo.getLogicalSlotIndex(), |
| 10013 | portInfo.isActive() |
| 10014 | ); |
| 10015 | } |
| 10016 | @Override |
| 10017 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10018 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10019 | mApp.getSystemService(AppOpsManager.class) |
| 10020 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10021 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10022 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10023 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10024 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10025 | // we are reading iccId which is PII data. |
| 10026 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10027 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10028 | enforceTelephonyFeatureWithException(callingPackage, |
| 10029 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10030 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10031 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10032 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10033 | Binder.getCallingUid())) { |
| 10034 | isLogicalSlotAccessRestricted = true; |
| 10035 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
| 10038 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10039 | if (slots == null || slots.length == 0) { |
| 10040 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10041 | return null; |
| 10042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10043 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10044 | for (int i = 0; i < slots.length; i++) { |
| 10045 | UiccSlot slot = slots[i]; |
| 10046 | if (slot == null) { |
| 10047 | continue; |
| 10048 | } |
| 10049 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10050 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10051 | UiccCard card = slot.getUiccCard(); |
| 10052 | if (card != null) { |
| 10053 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10054 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10055 | cardId = slot.getEid(); |
| 10056 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10057 | // If cardId is null, use iccId of default port as cardId. |
| 10058 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10060 | } |
| 10061 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10062 | if (cardId != null) { |
| 10063 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10064 | // if cardId is an EID, it's all digits so this is fine |
| 10065 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10066 | } |
| 10067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10068 | int cardState = 0; |
| 10069 | switch (slot.getCardState()) { |
| 10070 | case CARDSTATE_ABSENT: |
| 10071 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10072 | break; |
| 10073 | case CARDSTATE_PRESENT: |
| 10074 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10075 | break; |
| 10076 | case CARDSTATE_ERROR: |
| 10077 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10078 | break; |
| 10079 | case CARDSTATE_RESTRICTED: |
| 10080 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10081 | break; |
| 10082 | default: |
| 10083 | break; |
| 10084 | |
| 10085 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10086 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10087 | int[] portIndexes = slot.getPortList(); |
| 10088 | for (int portIdx : portIndexes) { |
| 10089 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10090 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10091 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10092 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10093 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10094 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10095 | slot.isEuicc(), |
| 10096 | cardId, |
| 10097 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10098 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10099 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10100 | //setting the value after compatibility check |
| 10101 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10102 | } |
| 10103 | return infos; |
| 10104 | } finally { |
| 10105 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10106 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10107 | } |
| 10108 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10109 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10110 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10111 | boolean hasReadPermission) { |
| 10112 | String iccId = slot.getIccId(portIndex); |
| 10113 | if (hasReadPermission) { // if has read permission |
| 10114 | return iccId; |
| 10115 | } else { |
| 10116 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10117 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10118 | // if no read permission, checking carrier privilege access |
| 10119 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10120 | return iccId; |
| 10121 | } |
| 10122 | } |
| 10123 | } |
| 10124 | // No read permission or carrier privilege access. |
| 10125 | return UiccPortInfo.ICCID_REDACTED; |
| 10126 | } |
| 10127 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10128 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10129 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10130 | public boolean switchSlots(int[] physicalSlots) { |
| 10131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10132 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10133 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10134 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10136 | final long identity = Binder.clearCallingIdentity(); |
| 10137 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10138 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10139 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10140 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10141 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10142 | physicalSlots[i], i)); |
| 10143 | } |
| 10144 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10145 | } finally { |
| 10146 | Binder.restoreCallingIdentity(identity); |
| 10147 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10148 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10149 | |
| 10150 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10151 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10152 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10153 | enforceModifyPermission(); |
| 10154 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10155 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10156 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10157 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10158 | final long identity = Binder.clearCallingIdentity(); |
| 10159 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10160 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10161 | } finally { |
| 10162 | Binder.restoreCallingIdentity(identity); |
| 10163 | } |
| 10164 | } |
| 10165 | |
| 10166 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10167 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10168 | enforceTelephonyFeatureWithException(callingPackage, |
| 10169 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10170 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10171 | final long identity = Binder.clearCallingIdentity(); |
| 10172 | try { |
| 10173 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10174 | } finally { |
| 10175 | Binder.restoreCallingIdentity(identity); |
| 10176 | } |
| 10177 | } |
| 10178 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10179 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10180 | * A test API to reload the UICC profile. |
| 10181 | * |
| 10182 | * <p>Requires that the calling app has permission |
| 10183 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10184 | * @hide |
| 10185 | */ |
| 10186 | @Override |
| 10187 | public void refreshUiccProfile(int subId) { |
| 10188 | enforceModifyPermission(); |
| 10189 | |
| 10190 | final long identity = Binder.clearCallingIdentity(); |
| 10191 | try { |
| 10192 | Phone phone = getPhone(subId); |
| 10193 | if (phone == null) { |
| 10194 | return; |
| 10195 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10196 | UiccPort uiccPort = phone.getUiccPort(); |
| 10197 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10198 | return; |
| 10199 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10200 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10201 | if (uiccProfile == null) { |
| 10202 | return; |
| 10203 | } |
| 10204 | uiccProfile.refresh(); |
| 10205 | } finally { |
| 10206 | Binder.restoreCallingIdentity(identity); |
| 10207 | } |
| 10208 | } |
| 10209 | |
| 10210 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10211 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10212 | */ |
| 10213 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10214 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10215 | } |
| 10216 | |
| 10217 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10218 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10219 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10220 | */ |
| 10221 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10222 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10223 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10224 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10225 | return list.get(phoneId); |
| 10226 | } |
| 10227 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10228 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10229 | |
| 10230 | @Override |
| 10231 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10232 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10233 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10234 | |
| 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
| 10237 | final Phone phone = getPhone(subId); |
| 10238 | if (phone == null) { |
| 10239 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10240 | return; |
| 10241 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10242 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10243 | if (cpt != null) { |
| 10244 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10245 | } |
| 10246 | // 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] | 10247 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10248 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10249 | if (carrierPrivilegeRules == null) { |
| 10250 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10251 | } else { |
| 10252 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10253 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10254 | } finally { |
| 10255 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10256 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10257 | } |
| 10258 | |
| 10259 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10260 | public void setCarrierServicePackageOverride( |
| 10261 | int subId, String carrierServicePackage, String callingPackage) { |
| 10262 | TelephonyPermissions.enforceShellOnly( |
| 10263 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10264 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10265 | final long identity = Binder.clearCallingIdentity(); |
| 10266 | try { |
| 10267 | final Phone phone = getPhone(subId); |
| 10268 | if (phone == null || phone.getSubId() != subId) { |
| 10269 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10270 | throw new IllegalArgumentException("No phone for subid"); |
| 10271 | } |
| 10272 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10273 | if (cpt == null) { |
| 10274 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10275 | throw new IllegalStateException("No CPT for phone"); |
| 10276 | } |
| 10277 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10278 | } finally { |
| 10279 | Binder.restoreCallingIdentity(identity); |
| 10280 | } |
| 10281 | } |
| 10282 | |
| 10283 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10284 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10285 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10286 | |
| 10287 | final long identity = Binder.clearCallingIdentity(); |
| 10288 | try { |
| 10289 | final Phone phone = getPhone(subId); |
| 10290 | if (phone == null) { |
| 10291 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10292 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10293 | } |
| 10294 | return phone.getCarrierIdListVersion(); |
| 10295 | } finally { |
| 10296 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10297 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10298 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10299 | |
| 10300 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10301 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10302 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10304 | mApp, subId, callingPackage, callingFeatureId, |
| 10305 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10306 | return -1; |
| 10307 | } |
| 10308 | |
| 10309 | final long identity = Binder.clearCallingIdentity(); |
| 10310 | try { |
| 10311 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10312 | } finally { |
| 10313 | Binder.restoreCallingIdentity(identity); |
| 10314 | } |
| 10315 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10316 | |
| 10317 | @Override |
| 10318 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10319 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10320 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10321 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10322 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10323 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10324 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10325 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10326 | final long identity = Binder.clearCallingIdentity(); |
| 10327 | try { |
| 10328 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10329 | } finally { |
| 10330 | Binder.restoreCallingIdentity(identity); |
| 10331 | } |
| 10332 | } |
| 10333 | |
| 10334 | @Override |
| 10335 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10337 | mApp, subId, "setCdmaRoamingMode"); |
| 10338 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10339 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10340 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10341 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10342 | final long identity = Binder.clearCallingIdentity(); |
| 10343 | try { |
| 10344 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10345 | } finally { |
| 10346 | Binder.restoreCallingIdentity(identity); |
| 10347 | } |
| 10348 | } |
| 10349 | |
| 10350 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10351 | public int getCdmaSubscriptionMode(int subId) { |
| 10352 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10353 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10354 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10355 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10356 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10357 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10358 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10359 | final long identity = Binder.clearCallingIdentity(); |
| 10360 | try { |
| 10361 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10362 | } finally { |
| 10363 | Binder.restoreCallingIdentity(identity); |
| 10364 | } |
| 10365 | } |
| 10366 | |
| 10367 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10368 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10370 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10371 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10372 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10373 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10374 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10375 | final long identity = Binder.clearCallingIdentity(); |
| 10376 | try { |
| 10377 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10378 | } finally { |
| 10379 | Binder.restoreCallingIdentity(identity); |
| 10380 | } |
| 10381 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10382 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10383 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10384 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10385 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10387 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10388 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10389 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10390 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10391 | |
| 10392 | enforceTelephonyFeatureWithException(callingPackage, |
| 10393 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10394 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10395 | final long identity = Binder.clearCallingIdentity(); |
| 10396 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10397 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10398 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10399 | if (phone.getEmergencyNumberTracker() != null |
| 10400 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10401 | emergencyNumberListInternal.put( |
| 10402 | phone.getSubId(), |
| 10403 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10404 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10405 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10406 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10407 | } finally { |
| 10408 | Binder.restoreCallingIdentity(identity); |
| 10409 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10410 | } |
| 10411 | |
| 10412 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10413 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10414 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10415 | if (!exactMatch) { |
| 10416 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10417 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10418 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10419 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10420 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10421 | if (!mApp.getResources().getBoolean( |
| 10422 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10423 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10424 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10425 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10426 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10427 | final long identity = Binder.clearCallingIdentity(); |
| 10428 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10429 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10430 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10431 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10432 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10433 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10434 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10435 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10436 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10437 | } |
| 10438 | return false; |
| 10439 | } finally { |
| 10440 | Binder.restoreCallingIdentity(identity); |
| 10441 | } |
| 10442 | } |
| 10443 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10444 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10445 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10446 | */ |
| 10447 | @Override |
| 10448 | public void startEmergencyCallbackMode() { |
| 10449 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10450 | "startEmergencyCallbackMode"); |
| 10451 | enforceModifyPermission(); |
| 10452 | final long identity = Binder.clearCallingIdentity(); |
| 10453 | try { |
| 10454 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10455 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10456 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10457 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10458 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10459 | gsmCdmaPhone.obtainMessage( |
| 10460 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10461 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10462 | } |
| 10463 | } |
| 10464 | } finally { |
| 10465 | Binder.restoreCallingIdentity(identity); |
| 10466 | } |
| 10467 | } |
| 10468 | |
| 10469 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10470 | * Update emergency number list for test mode. |
| 10471 | */ |
| 10472 | @Override |
| 10473 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10474 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10475 | "updateEmergencyNumberListTestMode"); |
| 10476 | |
| 10477 | final long identity = Binder.clearCallingIdentity(); |
| 10478 | try { |
| 10479 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10480 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10481 | if (tracker != null) { |
| 10482 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10483 | } |
| 10484 | } |
| 10485 | } finally { |
| 10486 | Binder.restoreCallingIdentity(identity); |
| 10487 | } |
| 10488 | } |
| 10489 | |
| 10490 | /** |
| 10491 | * Get the full emergency number list for test mode. |
| 10492 | */ |
| 10493 | @Override |
| 10494 | public List<String> getEmergencyNumberListTestMode() { |
| 10495 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10496 | "getEmergencyNumberListTestMode"); |
| 10497 | |
| 10498 | final long identity = Binder.clearCallingIdentity(); |
| 10499 | try { |
| 10500 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10501 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10502 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10503 | if (tracker != null) { |
| 10504 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10505 | emergencyNumbers.add(num.getNumber()); |
| 10506 | } |
| 10507 | } |
| 10508 | } |
| 10509 | return new ArrayList<>(emergencyNumbers); |
| 10510 | } finally { |
| 10511 | Binder.restoreCallingIdentity(identity); |
| 10512 | } |
| 10513 | } |
| 10514 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10515 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10516 | public int getEmergencyNumberDbVersion(int subId) { |
| 10517 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10518 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10519 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10520 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10521 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10522 | final long identity = Binder.clearCallingIdentity(); |
| 10523 | try { |
| 10524 | final Phone phone = getPhone(subId); |
| 10525 | if (phone == null) { |
| 10526 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10527 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10528 | } |
| 10529 | return phone.getEmergencyNumberDbVersion(); |
| 10530 | } finally { |
| 10531 | Binder.restoreCallingIdentity(identity); |
| 10532 | } |
| 10533 | } |
| 10534 | |
| 10535 | @Override |
| 10536 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10537 | enforceModifyPermission(); |
| 10538 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10539 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10540 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10541 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10542 | final long identity = Binder.clearCallingIdentity(); |
| 10543 | try { |
| 10544 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10545 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10546 | if (tracker != null) { |
| 10547 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10548 | } |
| 10549 | } |
| 10550 | } finally { |
| 10551 | Binder.restoreCallingIdentity(identity); |
| 10552 | } |
| 10553 | } |
| 10554 | |
| 10555 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10556 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10557 | enforceActiveEmergencySessionPermission(); |
| 10558 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10559 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10560 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10561 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10562 | final long identity = Binder.clearCallingIdentity(); |
| 10563 | try { |
| 10564 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10565 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10566 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10567 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10568 | } |
| 10569 | } |
| 10570 | } finally { |
| 10571 | Binder.restoreCallingIdentity(identity); |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | @Override |
| 10576 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10577 | enforceActiveEmergencySessionPermission(); |
| 10578 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10579 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10580 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10581 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10582 | final long identity = Binder.clearCallingIdentity(); |
| 10583 | try { |
| 10584 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10585 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10586 | if (tracker != null) { |
| 10587 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10588 | } |
| 10589 | } |
| 10590 | } finally { |
| 10591 | Binder.restoreCallingIdentity(identity); |
| 10592 | } |
| 10593 | } |
| 10594 | |
| 10595 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10596 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10597 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10598 | Phone phone = getPhone(subId); |
| 10599 | if (phone == null) { |
| 10600 | return null; |
| 10601 | } |
| 10602 | final long identity = Binder.clearCallingIdentity(); |
| 10603 | try { |
| 10604 | UiccProfile profile = UiccController.getInstance() |
| 10605 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10606 | if (profile != null) { |
| 10607 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10608 | } |
| 10609 | } finally { |
| 10610 | Binder.restoreCallingIdentity(identity); |
| 10611 | } |
| 10612 | return null; |
| 10613 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10614 | |
| 10615 | /** |
| 10616 | * Enable or disable a modem stack. |
| 10617 | */ |
| 10618 | @Override |
| 10619 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10620 | enforceModifyPermission(); |
| 10621 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10622 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10623 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10624 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10625 | final long identity = Binder.clearCallingIdentity(); |
| 10626 | try { |
| 10627 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10628 | if (phone == null) { |
| 10629 | return false; |
| 10630 | } else { |
| 10631 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10632 | } |
| 10633 | } finally { |
| 10634 | Binder.restoreCallingIdentity(identity); |
| 10635 | } |
| 10636 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10637 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10638 | /** |
| 10639 | * Whether a modem stack is enabled or not. |
| 10640 | */ |
| 10641 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10642 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10643 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10644 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10645 | if (phone == null) return false; |
| 10646 | |
| 10647 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10648 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10649 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10650 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10651 | } |
| 10652 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10653 | enforceTelephonyFeatureWithException(callingPackage, |
| 10654 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10655 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10656 | final long identity = Binder.clearCallingIdentity(); |
| 10657 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10658 | try { |
| 10659 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10660 | } catch (NoSuchElementException ex) { |
| 10661 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10662 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10663 | } finally { |
| 10664 | Binder.restoreCallingIdentity(identity); |
| 10665 | } |
| 10666 | } |
| 10667 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10668 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10669 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10670 | enforceModifyPermission(); |
| 10671 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10672 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10673 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10674 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10675 | final long identity = Binder.clearCallingIdentity(); |
| 10676 | try { |
| 10677 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10678 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10679 | .commit(); |
| 10680 | } finally { |
| 10681 | Binder.restoreCallingIdentity(identity); |
| 10682 | } |
| 10683 | } |
| 10684 | |
| 10685 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10686 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10687 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10688 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10689 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10690 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10691 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10692 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10693 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10694 | enforceTelephonyFeatureWithException(callingPackage, |
| 10695 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10696 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10697 | final long identity = Binder.clearCallingIdentity(); |
| 10698 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10699 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10700 | } finally { |
| 10701 | Binder.restoreCallingIdentity(identity); |
| 10702 | } |
| 10703 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10704 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10705 | @TelephonyManager.IsMultiSimSupportedResult |
| 10706 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10707 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10708 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10709 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10710 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10711 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10712 | } |
| 10713 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10714 | // supported by the modem, indicate that it is restricted. |
| 10715 | PhoneCapability staticCapability = |
| 10716 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10717 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10718 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10719 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10720 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10721 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10722 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10723 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10724 | } |
| 10725 | // Check if support of multiple SIMs is restricted by carrier |
| 10726 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10727 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10728 | } |
| 10729 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10730 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10731 | } |
| 10732 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10733 | /** |
| 10734 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10735 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10736 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10737 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10738 | * @param numOfSims number of active sims we want to switch to |
| 10739 | */ |
| 10740 | @Override |
| 10741 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10742 | if (numOfSims == 1) { |
| 10743 | enforceModifyPermission(); |
| 10744 | } else { |
| 10745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10746 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10747 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10748 | |
| 10749 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10750 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10751 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10752 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10753 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10754 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10755 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10756 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10757 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10758 | return; |
| 10759 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10760 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10761 | } finally { |
| 10762 | Binder.restoreCallingIdentity(identity); |
| 10763 | } |
| 10764 | } |
| 10765 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10766 | @Override |
| 10767 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10768 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10769 | |
| 10770 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10771 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10772 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10773 | Phone phone = getPhone(subId); |
| 10774 | if (phone == null) { |
| 10775 | return false; |
| 10776 | } |
| 10777 | final long identity = Binder.clearCallingIdentity(); |
| 10778 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10779 | UiccPort uiccPort = phone.getUiccPort(); |
| 10780 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10781 | return false; |
| 10782 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10783 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10784 | if (uiccProfile == null) { |
| 10785 | return false; |
| 10786 | } |
| 10787 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10788 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10789 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10790 | } |
| 10791 | return false; |
| 10792 | } finally { |
| 10793 | Binder.restoreCallingIdentity(identity); |
| 10794 | } |
| 10795 | } |
| 10796 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10797 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10798 | * Get whether making changes to modem configurations will trigger reboot. |
| 10799 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10800 | */ |
| 10801 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10802 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10803 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10804 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10805 | mApp, subId, callingPackage, callingFeatureId, |
| 10806 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10807 | return false; |
| 10808 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10809 | |
| 10810 | enforceTelephonyFeatureWithException(callingPackage, |
| 10811 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10812 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10813 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10814 | final long identity = Binder.clearCallingIdentity(); |
| 10815 | try { |
| 10816 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10817 | } finally { |
| 10818 | Binder.restoreCallingIdentity(identity); |
| 10819 | } |
| 10820 | } |
| 10821 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10822 | private void updateModemStateMetrics() { |
| 10823 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10824 | // TODO: check the state for each modem if the api is ready. |
| 10825 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10826 | } |
| 10827 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10828 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10829 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10830 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10831 | // Verify that the callingPackage belongs to the calling UID |
| 10832 | mApp.getSystemService(AppOpsManager.class) |
| 10833 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10834 | |
| 10835 | enforceTelephonyFeatureWithException(callingPackage, |
| 10836 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10837 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10838 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10839 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10840 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10841 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10842 | if (slotInfos != null) { |
| 10843 | for (int i = 0; i < slotInfos.length; i++) { |
| 10844 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10845 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10846 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10847 | portInfo.getLogicalSlotIndex())); |
| 10848 | } |
| 10849 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10850 | } |
| 10851 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10852 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10853 | } finally { |
| 10854 | Binder.restoreCallingIdentity(identity); |
| 10855 | } |
| 10856 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10857 | |
| 10858 | /** |
| 10859 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10860 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10861 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10862 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10863 | @Override |
| 10864 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10865 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10866 | } |
| 10867 | |
| 10868 | /** |
| 10869 | * Get the HAL Version of a specific service |
| 10870 | */ |
| 10871 | @Override |
| 10872 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10873 | Phone phone = getDefaultPhone(); |
| 10874 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10875 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10876 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10877 | return hv.major * 100 + hv.minor; |
| 10878 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10879 | |
| 10880 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10881 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10882 | * |
| 10883 | * @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] | 10884 | */ |
| 10885 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10886 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10887 | if (mFeatureFlags.hsumPackageManager()) { |
| 10888 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10889 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10890 | if (pm == null) return null; |
| 10891 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10892 | return (callingUids == null) ? null : callingUids[0]; |
| 10893 | } |
| 10894 | if (mPackageManager == null) return null; |
| 10895 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10896 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10897 | } |
| 10898 | |
| 10899 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10900 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10901 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10902 | * actually always the caller. |
| 10903 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10904 | */ |
| 10905 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10906 | PackageManager pm; |
| 10907 | if (mFeatureFlags.hsumPackageManager()) { |
| 10908 | pm = mApp.getBaseContext().createContextAsUser( |
| 10909 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10910 | } else { |
| 10911 | pm = mApp.getPackageManager(); |
| 10912 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10913 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10914 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10915 | return getCurrentPackageName(); |
| 10916 | } |
| 10917 | |
| 10918 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10919 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10920 | * corresponding network requests on a subId. |
| 10921 | * |
| 10922 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10923 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10924 | * 2) APN is un-metered for this subscription, or |
| 10925 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10926 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10927 | * |
| 10928 | * @return whether data is allowed for a apn type. |
| 10929 | * |
| 10930 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10931 | */ |
| 10932 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10933 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10934 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10935 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10936 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10937 | enforceTelephonyFeatureWithException(callingPackage, |
| 10938 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10939 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10940 | // Now that all security checks passes, perform the operation as ourselves. |
| 10941 | final long identity = Binder.clearCallingIdentity(); |
| 10942 | try { |
| 10943 | Phone phone = getPhone(subId); |
| 10944 | if (phone == null) return false; |
| 10945 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10946 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10947 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10948 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10949 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10950 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10951 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10952 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10953 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10954 | } finally { |
| 10955 | Binder.restoreCallingIdentity(identity); |
| 10956 | } |
| 10957 | } |
| 10958 | |
| 10959 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10960 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10961 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10962 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10963 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10964 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10965 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10966 | // Now that all security checks passes, perform the operation as ourselves. |
| 10967 | final long identity = Binder.clearCallingIdentity(); |
| 10968 | try { |
| 10969 | Phone phone = getPhone(subId); |
| 10970 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10971 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10972 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10973 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10974 | } finally { |
| 10975 | Binder.restoreCallingIdentity(identity); |
| 10976 | } |
| 10977 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10978 | |
| 10979 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10980 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10981 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10982 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10983 | |
| 10984 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10985 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10986 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10987 | long token = Binder.clearCallingIdentity(); |
| 10988 | try { |
| 10989 | Phone phone = getPhone(subscriptionId); |
| 10990 | if (phone == null) { |
| 10991 | try { |
| 10992 | if (resultCallback != null) { |
| 10993 | resultCallback.accept(false); |
| 10994 | } |
| 10995 | } catch (RemoteException e) { |
| 10996 | // ignore |
| 10997 | } |
| 10998 | return; |
| 10999 | } |
| 11000 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11001 | Pair.create(specifiers, (x) -> { |
| 11002 | try { |
| 11003 | if (resultCallback != null) { |
| 11004 | resultCallback.accept(x); |
| 11005 | } |
| 11006 | } catch (RemoteException e) { |
| 11007 | // ignore |
| 11008 | } |
| 11009 | }); |
| 11010 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11011 | } finally { |
| 11012 | Binder.restoreCallingIdentity(token); |
| 11013 | } |
| 11014 | } |
| 11015 | |
| 11016 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11017 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11018 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11019 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11020 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11021 | |
| 11022 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11023 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11024 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11025 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11026 | final long identity = Binder.clearCallingIdentity(); |
| 11027 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11028 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11029 | if (result instanceof IllegalStateException) { |
| 11030 | throw (IllegalStateException) result; |
| 11031 | } |
| 11032 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11033 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11034 | return specifiers; |
| 11035 | } finally { |
| 11036 | Binder.restoreCallingIdentity(identity); |
| 11037 | } |
| 11038 | } |
| 11039 | |
| 11040 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11041 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11042 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11043 | |
| 11044 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11045 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11046 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11047 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11048 | } |
| 11049 | |
| 11050 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11051 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11052 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11053 | if (callingPackage == null) { |
| 11054 | callingPackage = getCurrentPackageName(); |
| 11055 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11056 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11057 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11058 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11059 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11060 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11061 | } |
| 11062 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11063 | Intent intent = new Intent(); |
| 11064 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11065 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11066 | // Bring up choose default SMS subscription dialog right now |
| 11067 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11068 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11069 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11070 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11071 | |
| 11072 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11073 | public void showSwitchToManagedProfileDialog() { |
| 11074 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11075 | try { |
| 11076 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11077 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11078 | // for work telephony. |
| 11079 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11080 | intent.setData(Uri.parse("smsto:")); |
| 11081 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11082 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11083 | } catch (ActivityNotFoundException e) { |
| 11084 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11085 | Intent intent = new Intent(); |
| 11086 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11087 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11088 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11089 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11090 | } |
| 11091 | |
| 11092 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11093 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11094 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11095 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11096 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11097 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11098 | final long identity = Binder.clearCallingIdentity(); |
| 11099 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11100 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11101 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11102 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11103 | return carrierUAProfUrl; |
| 11104 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11105 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11106 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11107 | } finally { |
| 11108 | Binder.restoreCallingIdentity(identity); |
| 11109 | } |
| 11110 | } |
| 11111 | |
| 11112 | @Override |
| 11113 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11114 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11115 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11116 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11117 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11118 | final long identity = Binder.clearCallingIdentity(); |
| 11119 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11120 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11121 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11122 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11123 | return carrierUserAgent; |
| 11124 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11125 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11126 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11127 | } finally { |
| 11128 | Binder.restoreCallingIdentity(identity); |
| 11129 | } |
| 11130 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11131 | |
| 11132 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11133 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11134 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11135 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11136 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11137 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11138 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11139 | final long identity = Binder.clearCallingIdentity(); |
| 11140 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11141 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11142 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11143 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11144 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11145 | } finally { |
| 11146 | Binder.restoreCallingIdentity(identity); |
| 11147 | } |
| 11148 | } |
| 11149 | |
| 11150 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11151 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11152 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11153 | enforceModifyPermission(); |
| 11154 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11155 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11156 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11157 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11158 | final long identity = Binder.clearCallingIdentity(); |
| 11159 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11160 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11161 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11162 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11163 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11164 | } finally { |
| 11165 | Binder.restoreCallingIdentity(identity); |
| 11166 | } |
| 11167 | } |
| 11168 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11169 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11170 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11171 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11172 | * otherwise. |
| 11173 | */ |
| 11174 | @Override |
| 11175 | public void setCepEnabled(boolean isCepEnabled) { |
| 11176 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11177 | |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11181 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11182 | Phone defaultPhone = phone.getImsPhone(); |
| 11183 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11184 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11185 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11186 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11187 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11188 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11189 | + imsPhone.getMsisdn()); |
| 11190 | } |
| 11191 | } |
| 11192 | } finally { |
| 11193 | Binder.restoreCallingIdentity(identity); |
| 11194 | } |
| 11195 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11196 | |
| 11197 | /** |
| 11198 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11199 | * |
| 11200 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11201 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11202 | * before being read. |
| 11203 | */ |
| 11204 | @Override |
| 11205 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11206 | isCompressed) { |
| 11207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11208 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11209 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11210 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11211 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11212 | |
| 11213 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11214 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11215 | Binder.getCallingUserHandle())) { |
| 11216 | if (!isImsAvailableOnDevice()) { |
| 11217 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11218 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11219 | throw new IllegalStateException("IMS not available on device."); |
| 11220 | } |
| 11221 | } else { |
| 11222 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11223 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11224 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11225 | } |
| 11226 | |
| 11227 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11228 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11229 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11230 | } finally { |
| 11231 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11232 | } |
| 11233 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11234 | |
| 11235 | @Override |
| 11236 | public boolean isIccLockEnabled(int subId) { |
| 11237 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11238 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11239 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11240 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11241 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11242 | // Now that all security checks passes, perform the operation as ourselves. |
| 11243 | final long identity = Binder.clearCallingIdentity(); |
| 11244 | try { |
| 11245 | Phone phone = getPhone(subId); |
| 11246 | if (phone != null && phone.getIccCard() != null) { |
| 11247 | return phone.getIccCard().getIccLockEnabled(); |
| 11248 | } else { |
| 11249 | return false; |
| 11250 | } |
| 11251 | } finally { |
| 11252 | Binder.restoreCallingIdentity(identity); |
| 11253 | } |
| 11254 | } |
| 11255 | |
| 11256 | /** |
| 11257 | * Set the ICC pin lock enabled or disabled. |
| 11258 | * |
| 11259 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11260 | * three cases: |
| 11261 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11262 | * successfully. |
| 11263 | * - Positive number and zero for remaining password attempts. |
| 11264 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11265 | * |
| 11266 | */ |
| 11267 | @Override |
| 11268 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11269 | enforceModifyPermission(); |
| 11270 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11272 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11273 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11274 | Phone phone = getPhone(subId); |
| 11275 | if (phone == null) { |
| 11276 | return 0; |
| 11277 | } |
| 11278 | // Now that all security checks passes, perform the operation as ourselves. |
| 11279 | final long identity = Binder.clearCallingIdentity(); |
| 11280 | try { |
| 11281 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11282 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11283 | return attemptsRemaining; |
| 11284 | |
| 11285 | } catch (Exception e) { |
| 11286 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11287 | } finally { |
| 11288 | Binder.restoreCallingIdentity(identity); |
| 11289 | } |
| 11290 | return 0; |
| 11291 | } |
| 11292 | |
| 11293 | /** |
| 11294 | * Change the ICC password used in ICC pin lock. |
| 11295 | * |
| 11296 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11297 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11298 | * - Positive number and zero for remaining password attempts. |
| 11299 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11300 | * |
| 11301 | */ |
| 11302 | @Override |
| 11303 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11304 | enforceModifyPermission(); |
| 11305 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11306 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11307 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11308 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11309 | Phone phone = getPhone(subId); |
| 11310 | if (phone == null) { |
| 11311 | return 0; |
| 11312 | } |
| 11313 | // Now that all security checks passes, perform the operation as ourselves. |
| 11314 | final long identity = Binder.clearCallingIdentity(); |
| 11315 | try { |
| 11316 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11317 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11318 | return attemptsRemaining; |
| 11319 | |
| 11320 | } catch (Exception e) { |
| 11321 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11322 | } finally { |
| 11323 | Binder.restoreCallingIdentity(identity); |
| 11324 | } |
| 11325 | return 0; |
| 11326 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11327 | |
| 11328 | /** |
| 11329 | * Request for receiving user activity notification |
| 11330 | */ |
| 11331 | @Override |
| 11332 | public void requestUserActivityNotification() { |
| 11333 | if (!mNotifyUserActivity.get() |
| 11334 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11335 | mNotifyUserActivity.set(true); |
| 11336 | } |
| 11337 | } |
| 11338 | |
| 11339 | /** |
| 11340 | * Called when userActivity is signalled in the power manager. |
| 11341 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11342 | */ |
| 11343 | @Override |
| 11344 | public void userActivity() { |
| 11345 | // *************************************** |
| 11346 | // * Inherited from PhoneWindowManager * |
| 11347 | // *************************************** |
| 11348 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11349 | // WITH ITS LOCKS HELD. |
| 11350 | // |
| 11351 | // This code must be VERY careful about the locks |
| 11352 | // it acquires. |
| 11353 | // In fact, the current code acquires way too many, |
| 11354 | // and probably has lurking deadlocks. |
| 11355 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11356 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11357 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11358 | } |
| 11359 | |
| 11360 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11361 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11362 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11363 | } |
| 11364 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11365 | |
| 11366 | @Override |
| 11367 | public boolean canConnectTo5GInDsdsMode() { |
| 11368 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11369 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11370 | |
| 11371 | @Override |
| 11372 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11373 | String callingFeatureId) { |
| 11374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11375 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11376 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11377 | } |
| 11378 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11379 | enforceTelephonyFeatureWithException(callingPackage, |
| 11380 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11381 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11382 | Phone phone = getPhone(subId); |
| 11383 | if (phone == null) { |
| 11384 | throw new RuntimeException("phone is not available"); |
| 11385 | } |
| 11386 | // Now that all security checks passes, perform the operation as ourselves. |
| 11387 | final long identity = Binder.clearCallingIdentity(); |
| 11388 | try { |
| 11389 | return phone.getEquivalentHomePlmns(); |
| 11390 | } finally { |
| 11391 | Binder.restoreCallingIdentity(identity); |
| 11392 | } |
| 11393 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11394 | |
| 11395 | @Override |
| 11396 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11397 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11398 | if (!mApp.getResources().getBoolean( |
| 11399 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11400 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11401 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11402 | "isRadioInterfaceCapabilitySupported"); |
| 11403 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11404 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11405 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11406 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11407 | if (radioInterfaceCapabilities == null) { |
| 11408 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11409 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11410 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11411 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11412 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11413 | @Override |
| 11414 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11415 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11416 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11417 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11418 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11419 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11420 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11421 | |
| 11422 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11423 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11424 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11425 | if (DBG) { |
| 11426 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11427 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11428 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11429 | } |
| 11430 | |
| 11431 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11432 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11433 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11434 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11435 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11436 | if (callback != null) { |
| 11437 | try { |
| 11438 | callback.onAuthenticationFailure( |
| 11439 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11440 | } catch (RemoteException exception) { |
| 11441 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11442 | } |
| 11443 | return; |
| 11444 | } |
| 11445 | } |
| 11446 | |
| 11447 | final long token = Binder.clearCallingIdentity(); |
| 11448 | try { |
| 11449 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11450 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11451 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11452 | } finally { |
| 11453 | Binder.restoreCallingIdentity(token); |
| 11454 | } |
| 11455 | } |
| 11456 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11457 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11458 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11459 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11460 | * requested radio power state will actually be set. See {@link |
| 11461 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11462 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11463 | * @param enable {@code true} if trying to turn radio on. |
| 11464 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11465 | * false}. |
| 11466 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11467 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11468 | boolean isPhoneAvailable = false; |
| 11469 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11470 | Phone phone = PhoneFactory.getPhone(i); |
| 11471 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11472 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11473 | isPhoneAvailable = true; |
| 11474 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11475 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11476 | |
| 11477 | // return true if successfully informed the phone object about the thermal radio power |
| 11478 | // request. |
| 11479 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11480 | } |
| 11481 | |
| 11482 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11483 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11484 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11485 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11486 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11487 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11488 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11489 | } |
| 11490 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11491 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11492 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11493 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11494 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11495 | } |
| 11496 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11497 | setDataEnabledForReason( |
| 11498 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11499 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11500 | if (isDataThrottlingSupported) { |
| 11501 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11502 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11503 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11504 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11505 | } else if (thermalMitigationResult |
| 11506 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11507 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11508 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11509 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11510 | } |
| 11511 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11512 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11513 | |
| 11514 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11515 | } |
| 11516 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11517 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11518 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11519 | for (String pckg : context.getResources() |
| 11520 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11521 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11522 | } |
| 11523 | } |
| 11524 | |
| 11525 | return sThermalMitigationAllowlistedPackages; |
| 11526 | } |
| 11527 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11528 | private boolean isAnyPhoneInEmergencyState() { |
| 11529 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11530 | if (tm.isInEmergencyCall()) { |
| 11531 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11532 | return true; |
| 11533 | } |
| 11534 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11535 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11536 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11537 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11538 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11539 | return true; |
| 11540 | } |
| 11541 | } |
| 11542 | |
| 11543 | return false; |
| 11544 | } |
| 11545 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11546 | /** |
| 11547 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11548 | * @param packageName name of package to be allowlisted |
| 11549 | * @param context |
| 11550 | */ |
| 11551 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11552 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11553 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11554 | } |
| 11555 | |
| 11556 | /** |
| 11557 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11558 | * @param packageName name of package to remove from allowlist |
| 11559 | * @param context |
| 11560 | */ |
| 11561 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11562 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11563 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11564 | } |
| 11565 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11566 | /** |
| 11567 | * Thermal mitigation request to control functionalities at modem. |
| 11568 | * |
| 11569 | * @param subId the id of the subscription. |
| 11570 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11571 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11572 | * |
| 11573 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11574 | */ |
| 11575 | @Override |
| 11576 | @ThermalMitigationResult |
| 11577 | public int sendThermalMitigationRequest( |
| 11578 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11579 | ThermalMitigationRequest thermalMitigationRequest, |
| 11580 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11581 | enforceModifyPermission(); |
| 11582 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11584 | |
| 11585 | enforceTelephonyFeatureWithException(callingPackage, |
| 11586 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11587 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11588 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11589 | .contains(callingPackage)) { |
| 11590 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11591 | + "calling package: " + callingPackage); |
| 11592 | } |
| 11593 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11594 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11595 | final long identity = Binder.clearCallingIdentity(); |
| 11596 | |
| 11597 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11598 | try { |
| 11599 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11600 | switch (thermalMitigationAction) { |
| 11601 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11602 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11603 | handleDataThrottlingRequest(subId, |
| 11604 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11605 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11606 | break; |
| 11607 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11608 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11609 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11610 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11611 | } |
| 11612 | |
| 11613 | // Ensure that radio is on. If not able to power on due to phone being |
| 11614 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11615 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11616 | thermalMitigationResult = |
| 11617 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11618 | break; |
| 11619 | } |
| 11620 | |
| 11621 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11622 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11623 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11624 | break; |
| 11625 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11626 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11627 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11628 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11629 | } |
| 11630 | |
| 11631 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11632 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11633 | Phone phone = getPhone(subId); |
| 11634 | if (phone == null) { |
| 11635 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11636 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11637 | break; |
| 11638 | } |
| 11639 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11640 | TelephonyConnectionService service = |
| 11641 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11642 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11643 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11644 | thermalMitigationResult = |
| 11645 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11646 | break; |
| 11647 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11648 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11649 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11650 | break; |
| 11651 | } |
| 11652 | } else { |
| 11653 | thermalMitigationResult = |
| 11654 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11655 | break; |
| 11656 | } |
| 11657 | |
| 11658 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11659 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11660 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11661 | thermalMitigationResult = |
| 11662 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11663 | break; |
| 11664 | } |
| 11665 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11666 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11667 | break; |
| 11668 | default: |
| 11669 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11670 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11671 | } |
| 11672 | } catch (IllegalArgumentException e) { |
| 11673 | throw e; |
| 11674 | } catch (Exception e) { |
| 11675 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11676 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11677 | } finally { |
| 11678 | Binder.restoreCallingIdentity(identity); |
| 11679 | } |
| 11680 | |
| 11681 | if (DBG) { |
| 11682 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11683 | + thermalMitigationResult); |
| 11684 | } |
| 11685 | |
| 11686 | return thermalMitigationResult; |
| 11687 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11688 | |
| 11689 | /** |
| 11690 | * Set the GbaService Package Name that Telephony will bind to. |
| 11691 | * |
| 11692 | * @param subId The sim that the GbaService is associated with. |
| 11693 | * @param packageName The name of the package to be replaced with. |
| 11694 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11695 | */ |
| 11696 | @Override |
| 11697 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11698 | enforceModifyPermission(); |
| 11699 | |
| 11700 | final long identity = Binder.clearCallingIdentity(); |
| 11701 | try { |
| 11702 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11703 | } finally { |
| 11704 | Binder.restoreCallingIdentity(identity); |
| 11705 | } |
| 11706 | } |
| 11707 | |
| 11708 | /** |
| 11709 | * Return the package name of the currently bound GbaService. |
| 11710 | * |
| 11711 | * @param subId The sim that the GbaService is associated with. |
| 11712 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11713 | */ |
| 11714 | @Override |
| 11715 | public String getBoundGbaService(int subId) { |
| 11716 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11717 | |
| 11718 | final long identity = Binder.clearCallingIdentity(); |
| 11719 | try { |
| 11720 | return getGbaManager(subId).getServicePackage(); |
| 11721 | } finally { |
| 11722 | Binder.restoreCallingIdentity(identity); |
| 11723 | } |
| 11724 | } |
| 11725 | |
| 11726 | /** |
| 11727 | * Set the release time for telephony to unbind GbaService. |
| 11728 | * |
| 11729 | * @param subId The sim that the GbaService is associated with. |
| 11730 | * @param interval The release time to unbind GbaService by millisecond. |
| 11731 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11732 | */ |
| 11733 | @Override |
| 11734 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11735 | enforceModifyPermission(); |
| 11736 | |
| 11737 | final long identity = Binder.clearCallingIdentity(); |
| 11738 | try { |
| 11739 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11740 | } finally { |
| 11741 | Binder.restoreCallingIdentity(identity); |
| 11742 | } |
| 11743 | } |
| 11744 | |
| 11745 | /** |
| 11746 | * Return the release time for telephony to unbind GbaService. |
| 11747 | * |
| 11748 | * @param subId The sim that the GbaService is associated with. |
| 11749 | * @return The release time to unbind GbaService by millisecond. |
| 11750 | */ |
| 11751 | @Override |
| 11752 | public int getGbaReleaseTime(int subId) { |
| 11753 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11754 | |
| 11755 | final long identity = Binder.clearCallingIdentity(); |
| 11756 | try { |
| 11757 | return getGbaManager(subId).getReleaseTime(); |
| 11758 | } finally { |
| 11759 | Binder.restoreCallingIdentity(identity); |
| 11760 | } |
| 11761 | } |
| 11762 | |
| 11763 | private GbaManager getGbaManager(int subId) { |
| 11764 | GbaManager instance = GbaManager.getInstance(subId); |
| 11765 | if (instance == null) { |
| 11766 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11767 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11768 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11769 | } |
| 11770 | return instance; |
| 11771 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11772 | |
| 11773 | /** |
| 11774 | * indicate whether the device and the carrier can support |
| 11775 | * RCS VoLTE single registration. |
| 11776 | */ |
| 11777 | @Override |
| 11778 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11779 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11780 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11781 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11782 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11783 | |
| 11784 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11785 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11786 | } |
| 11787 | |
| 11788 | final long identity = Binder.clearCallingIdentity(); |
| 11789 | try { |
| 11790 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11791 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11792 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11793 | if (isCapable != null) { |
| 11794 | return isCapable; |
| 11795 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11796 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11798 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11799 | } finally { |
| 11800 | Binder.restoreCallingIdentity(identity); |
| 11801 | } |
| 11802 | } |
| 11803 | |
| 11804 | /** |
| 11805 | * Register RCS provisioning callback. |
| 11806 | */ |
| 11807 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11808 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11809 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11810 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11811 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11812 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11813 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11814 | |
| 11815 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11816 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11817 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11818 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11819 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11820 | Binder.getCallingUserHandle())) { |
| 11821 | if (!isImsAvailableOnDevice()) { |
| 11822 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11823 | "IMS not available on device."); |
| 11824 | } |
| 11825 | } else { |
| 11826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11827 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11828 | } |
| 11829 | |
| 11830 | final long identity = Binder.clearCallingIdentity(); |
| 11831 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11832 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11833 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11834 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11835 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11836 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11837 | } finally { |
| 11838 | Binder.restoreCallingIdentity(identity); |
| 11839 | } |
| 11840 | } |
| 11841 | |
| 11842 | /** |
| 11843 | * Unregister RCS provisioning callback. |
| 11844 | */ |
| 11845 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11846 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11847 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11848 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11849 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11850 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11851 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11852 | |
| 11853 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11854 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11855 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11856 | |
| 11857 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11858 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11859 | Binder.getCallingUserHandle())) { |
| 11860 | if (!isImsAvailableOnDevice()) { |
| 11861 | // operation failed silently |
| 11862 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11863 | return; |
| 11864 | } |
| 11865 | } else { |
| 11866 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11867 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11868 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11869 | } |
| 11870 | |
| 11871 | final long identity = Binder.clearCallingIdentity(); |
| 11872 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11873 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11874 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11875 | } finally { |
| 11876 | Binder.restoreCallingIdentity(identity); |
| 11877 | } |
| 11878 | } |
| 11879 | |
| 11880 | /** |
| 11881 | * trigger RCS reconfiguration. |
| 11882 | */ |
| 11883 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11884 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11885 | "triggerRcsReconfiguration", |
| 11886 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11887 | |
| 11888 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11889 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11890 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11891 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11892 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11893 | Binder.getCallingUserHandle())) { |
| 11894 | if (!isImsAvailableOnDevice()) { |
| 11895 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11896 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11897 | throw new IllegalStateException("IMS not available on device."); |
| 11898 | } |
| 11899 | } else { |
| 11900 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11901 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11902 | } |
| 11903 | |
| 11904 | final long identity = Binder.clearCallingIdentity(); |
| 11905 | try { |
| 11906 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11907 | } finally { |
| 11908 | Binder.restoreCallingIdentity(identity); |
| 11909 | } |
| 11910 | } |
| 11911 | |
| 11912 | /** |
| 11913 | * Provide the client configuration parameters of the RCS application. |
| 11914 | */ |
| 11915 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11916 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11917 | "setRcsClientConfiguration", |
| 11918 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11919 | |
| 11920 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11921 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11922 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11923 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11924 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11925 | Binder.getCallingUserHandle())) { |
| 11926 | if (!isImsAvailableOnDevice()) { |
| 11927 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11928 | "IMS not available on device."); |
| 11929 | } |
| 11930 | } else { |
| 11931 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11932 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11933 | } |
| 11934 | |
| 11935 | final long identity = Binder.clearCallingIdentity(); |
| 11936 | |
| 11937 | try { |
| 11938 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11939 | if (configBinder == null) { |
| 11940 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11942 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11943 | } else { |
| 11944 | configBinder.setRcsClientConfiguration(rcc); |
| 11945 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11946 | |
| 11947 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11948 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11949 | } catch (RemoteException e) { |
| 11950 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11951 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11952 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11953 | } finally { |
| 11954 | Binder.restoreCallingIdentity(identity); |
| 11955 | } |
| 11956 | } |
| 11957 | |
| 11958 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11959 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11960 | */ |
| 11961 | @Override |
| 11962 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11963 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11964 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11965 | |
| 11966 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11967 | } |
| 11968 | |
| 11969 | /** |
| 11970 | * Gets the test mode for RCS VoLTE single registration. |
| 11971 | */ |
| 11972 | @Override |
| 11973 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11974 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11975 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11976 | |
| 11977 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11978 | } |
| 11979 | |
| 11980 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11981 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11982 | */ |
| 11983 | @Override |
| 11984 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11985 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11986 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11987 | enforceModifyPermission(); |
| 11988 | |
| 11989 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11990 | : Boolean.parseBoolean(enabledStr); |
| 11991 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11992 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11993 | } |
| 11994 | |
| 11995 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11996 | * Sends a device to device communication message. Only usable via shell. |
| 11997 | * @param message message to send. |
| 11998 | * @param value message value. |
| 11999 | */ |
| 12000 | @Override |
| 12001 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12002 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12003 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12004 | enforceModifyPermission(); |
| 12005 | |
| 12006 | final long identity = Binder.clearCallingIdentity(); |
| 12007 | try { |
| 12008 | TelephonyConnectionService service = |
| 12009 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12010 | if (service == null) { |
| 12011 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12012 | return; |
| 12013 | } |
| 12014 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12015 | } finally { |
| 12016 | Binder.restoreCallingIdentity(identity); |
| 12017 | } |
| 12018 | } |
| 12019 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12020 | /** |
| 12021 | * Sets the specified device to device transport active. |
| 12022 | * @param transport The transport to set active. |
| 12023 | */ |
| 12024 | @Override |
| 12025 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12026 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12027 | "setActiveDeviceToDeviceTransport"); |
| 12028 | enforceModifyPermission(); |
| 12029 | |
| 12030 | final long identity = Binder.clearCallingIdentity(); |
| 12031 | try { |
| 12032 | TelephonyConnectionService service = |
| 12033 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12034 | if (service == null) { |
| 12035 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12036 | return; |
| 12037 | } |
| 12038 | service.setActiveDeviceToDeviceTransport(transport); |
| 12039 | } finally { |
| 12040 | Binder.restoreCallingIdentity(identity); |
| 12041 | } |
| 12042 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12043 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12044 | @Override |
| 12045 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12046 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12047 | "setDeviceToDeviceForceEnabled"); |
| 12048 | |
| 12049 | final long identity = Binder.clearCallingIdentity(); |
| 12050 | try { |
| 12051 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12052 | p -> { |
| 12053 | Phone thePhone = p.getImsPhone(); |
| 12054 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12055 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12056 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12057 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12058 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12059 | (ImsPhoneCallTracker) tracker; |
| 12060 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12061 | } |
| 12062 | } |
| 12063 | } |
| 12064 | ); |
| 12065 | } finally { |
| 12066 | Binder.restoreCallingIdentity(identity); |
| 12067 | } |
| 12068 | } |
| 12069 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12070 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12071 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12072 | */ |
| 12073 | @Override |
| 12074 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12075 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12076 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12077 | } |
| 12078 | |
| 12079 | /** |
| 12080 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12081 | */ |
| 12082 | @Override |
| 12083 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12084 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12085 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12086 | enforceModifyPermission(); |
| 12087 | |
| 12088 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12089 | : Boolean.parseBoolean(enabledStr); |
| 12090 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12091 | subId, enabled); |
| 12092 | } |
| 12093 | |
| 12094 | /** |
| 12095 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12096 | */ |
| 12097 | @Override |
| 12098 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12099 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12100 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12101 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12102 | |
| 12103 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12104 | * Overrides the ims feature validation result |
| 12105 | */ |
| 12106 | @Override |
| 12107 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12108 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12109 | "setImsFeatureValidationOverride"); |
| 12110 | |
| 12111 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12112 | : Boolean.parseBoolean(enabledStr); |
| 12113 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12114 | subId, enabled); |
| 12115 | } |
| 12116 | |
| 12117 | /** |
| 12118 | * Gets the ims feature validation override value |
| 12119 | */ |
| 12120 | @Override |
| 12121 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12122 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12123 | "getImsFeatureValidationOverride"); |
| 12124 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12125 | } |
| 12126 | |
| 12127 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12128 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12129 | * their mobile plan. |
| 12130 | */ |
| 12131 | @Override |
| 12132 | public String getMobileProvisioningUrl() { |
| 12133 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12134 | final long identity = Binder.clearCallingIdentity(); |
| 12135 | try { |
| 12136 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12137 | } finally { |
| 12138 | Binder.restoreCallingIdentity(identity); |
| 12139 | } |
| 12140 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12141 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12142 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12143 | * Get the EAB contact from the EAB database. |
| 12144 | */ |
| 12145 | @Override |
| 12146 | public String getContactFromEab(String contact) { |
| 12147 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12148 | enforceModifyPermission(); |
| 12149 | final long identity = Binder.clearCallingIdentity(); |
| 12150 | try { |
| 12151 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12152 | } finally { |
| 12153 | Binder.restoreCallingIdentity(identity); |
| 12154 | } |
| 12155 | } |
| 12156 | |
| 12157 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12158 | * Get the EAB capability from the EAB database. |
| 12159 | */ |
| 12160 | @Override |
| 12161 | public String getCapabilityFromEab(String contact) { |
| 12162 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12163 | enforceModifyPermission(); |
| 12164 | final long identity = Binder.clearCallingIdentity(); |
| 12165 | try { |
| 12166 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12167 | } finally { |
| 12168 | Binder.restoreCallingIdentity(identity); |
| 12169 | } |
| 12170 | } |
| 12171 | |
| 12172 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12173 | * Remove the EAB contacts from the EAB database. |
| 12174 | */ |
| 12175 | @Override |
| 12176 | public int removeContactFromEab(int subId, String contacts) { |
| 12177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12178 | enforceModifyPermission(); |
| 12179 | final long identity = Binder.clearCallingIdentity(); |
| 12180 | try { |
| 12181 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12182 | } finally { |
| 12183 | Binder.restoreCallingIdentity(identity); |
| 12184 | } |
| 12185 | } |
| 12186 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12187 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12188 | public boolean getDeviceUceEnabled() { |
| 12189 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12190 | final long identity = Binder.clearCallingIdentity(); |
| 12191 | try { |
| 12192 | return mApp.getDeviceUceEnabled(); |
| 12193 | } finally { |
| 12194 | Binder.restoreCallingIdentity(identity); |
| 12195 | } |
| 12196 | } |
| 12197 | |
| 12198 | @Override |
| 12199 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12201 | final long identity = Binder.clearCallingIdentity(); |
| 12202 | try { |
| 12203 | mApp.setDeviceUceEnabled(isEnabled); |
| 12204 | } finally { |
| 12205 | Binder.restoreCallingIdentity(identity); |
| 12206 | } |
| 12207 | } |
| 12208 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12209 | /** |
| 12210 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12211 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12212 | */ |
| 12213 | // Used for SHELL command only right now. |
| 12214 | @Override |
| 12215 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12216 | List<String> featureTags) { |
| 12217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12218 | "addUceRegistrationOverrideShell"); |
| 12219 | final long identity = Binder.clearCallingIdentity(); |
| 12220 | try { |
| 12221 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12222 | new ArraySet<>(featureTags)); |
| 12223 | } catch (ImsException e) { |
| 12224 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12225 | } finally { |
| 12226 | Binder.restoreCallingIdentity(identity); |
| 12227 | } |
| 12228 | } |
| 12229 | |
| 12230 | /** |
| 12231 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12232 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12233 | */ |
| 12234 | // Used for SHELL command only right now. |
| 12235 | @Override |
| 12236 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12237 | List<String> featureTags) { |
| 12238 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12239 | "removeUceRegistrationOverrideShell"); |
| 12240 | final long identity = Binder.clearCallingIdentity(); |
| 12241 | try { |
| 12242 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12243 | new ArraySet<>(featureTags)); |
| 12244 | } catch (ImsException e) { |
| 12245 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12246 | } finally { |
| 12247 | Binder.restoreCallingIdentity(identity); |
| 12248 | } |
| 12249 | } |
| 12250 | |
| 12251 | /** |
| 12252 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12253 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12254 | */ |
| 12255 | // Used for SHELL command only right now. |
| 12256 | @Override |
| 12257 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12258 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12259 | "clearUceRegistrationOverrideShell"); |
| 12260 | final long identity = Binder.clearCallingIdentity(); |
| 12261 | try { |
| 12262 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12263 | } catch (ImsException e) { |
| 12264 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12265 | } finally { |
| 12266 | Binder.restoreCallingIdentity(identity); |
| 12267 | } |
| 12268 | } |
| 12269 | |
| 12270 | /** |
| 12271 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12272 | */ |
| 12273 | // Used for SHELL command only right now. |
| 12274 | @Override |
| 12275 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12276 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12277 | "getLatestRcsContactUceCapabilityShell"); |
| 12278 | final long identity = Binder.clearCallingIdentity(); |
| 12279 | try { |
| 12280 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12281 | } catch (ImsException e) { |
| 12282 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12283 | } finally { |
| 12284 | Binder.restoreCallingIdentity(identity); |
| 12285 | } |
| 12286 | } |
| 12287 | |
| 12288 | /** |
| 12289 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12290 | * device does not have an active PUBLISH. |
| 12291 | */ |
| 12292 | // Used for SHELL command only right now. |
| 12293 | @Override |
| 12294 | public String getLastUcePidfXmlShell(int subId) { |
| 12295 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12296 | final long identity = Binder.clearCallingIdentity(); |
| 12297 | try { |
| 12298 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12299 | } catch (ImsException e) { |
| 12300 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12301 | } finally { |
| 12302 | Binder.restoreCallingIdentity(identity); |
| 12303 | } |
| 12304 | } |
| 12305 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12306 | /** |
| 12307 | * Remove UCE requests cannot be sent to the network status. |
| 12308 | */ |
| 12309 | // Used for SHELL command only right now. |
| 12310 | @Override |
| 12311 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12312 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12313 | final long identity = Binder.clearCallingIdentity(); |
| 12314 | try { |
| 12315 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12316 | } catch (ImsException e) { |
| 12317 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12318 | } finally { |
| 12319 | Binder.restoreCallingIdentity(identity); |
| 12320 | } |
| 12321 | } |
| 12322 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12323 | /** |
| 12324 | * Remove UCE requests cannot be sent to the network status. |
| 12325 | */ |
| 12326 | // Used for SHELL command only. |
| 12327 | @Override |
| 12328 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12329 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12330 | final long identity = Binder.clearCallingIdentity(); |
| 12331 | try { |
| 12332 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12333 | } catch (ImsException e) { |
| 12334 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12335 | } finally { |
| 12336 | Binder.restoreCallingIdentity(identity); |
| 12337 | } |
| 12338 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12339 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12340 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12341 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12342 | String callingPackage) { |
| 12343 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12344 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12345 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12346 | enforceTelephonyFeatureWithException(callingPackage, |
| 12347 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12348 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12349 | final int callingUid = Binder.getCallingUid(); |
| 12350 | // Verify that tha callingPackage belongs to the calling UID |
| 12351 | mApp.getSystemService(AppOpsManager.class) |
| 12352 | .checkPackage(callingUid, callingPackage); |
| 12353 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12354 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12355 | |
| 12356 | final long identity = Binder.clearCallingIdentity(); |
| 12357 | try { |
| 12358 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12359 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12360 | |
| 12361 | if (result instanceof IllegalStateException) { |
| 12362 | throw (IllegalStateException) result; |
| 12363 | } |
| 12364 | } finally { |
| 12365 | Binder.restoreCallingIdentity(identity); |
| 12366 | } |
| 12367 | } |
| 12368 | |
| 12369 | @Override |
| 12370 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12371 | String callingPackage) { |
| 12372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12373 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12374 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12375 | enforceTelephonyFeatureWithException(callingPackage, |
| 12376 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12377 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12378 | final int callingUid = Binder.getCallingUid(); |
| 12379 | // Verify that tha callingPackage belongs to the calling UID |
| 12380 | mApp.getSystemService(AppOpsManager.class) |
| 12381 | .checkPackage(callingUid, callingPackage); |
| 12382 | |
| 12383 | final long identity = Binder.clearCallingIdentity(); |
| 12384 | try { |
| 12385 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12386 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12387 | |
| 12388 | if (result instanceof IllegalStateException) { |
| 12389 | throw (IllegalStateException) result; |
| 12390 | } |
| 12391 | } finally { |
| 12392 | Binder.restoreCallingIdentity(identity); |
| 12393 | } |
| 12394 | } |
| 12395 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12396 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12397 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12398 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12399 | // phone/system process do not have further restriction on request |
| 12400 | return; |
| 12401 | } |
| 12402 | |
| 12403 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12404 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12405 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12406 | context.enforceCallingOrSelfPermission( |
| 12407 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12408 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12409 | } |
| 12410 | |
| 12411 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12412 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12413 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12414 | || info.isEnabled()) { |
| 12415 | throw new IllegalArgumentException( |
| 12416 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12417 | } |
| 12418 | |
| 12419 | // Thresholds length for each RAN need in range. This has been validated in |
| 12420 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12421 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12422 | final int[] thresholds = info.getThresholds(); |
| 12423 | Objects.requireNonNull(thresholds); |
| 12424 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12425 | || thresholds.length |
| 12426 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12427 | throw new IllegalArgumentException( |
| 12428 | "thresholds length is out of range: " + thresholds.length); |
| 12429 | } |
| 12430 | } |
| 12431 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12432 | |
| 12433 | /** |
| 12434 | * Gets the current phone capability. |
| 12435 | * |
| 12436 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12437 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12438 | * It's used to evaluate possible phone config change, for example from single |
| 12439 | * SIM device to multi-SIM device. |
| 12440 | */ |
| 12441 | @Override |
| 12442 | public PhoneCapability getPhoneCapability() { |
| 12443 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12444 | |
| 12445 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12446 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12447 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12448 | final long identity = Binder.clearCallingIdentity(); |
| 12449 | try { |
| 12450 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12451 | } finally { |
| 12452 | Binder.restoreCallingIdentity(identity); |
| 12453 | } |
| 12454 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12455 | |
| 12456 | /** |
| 12457 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12458 | * required to be done shortly after the API is invoked. |
| 12459 | */ |
| 12460 | @Override |
| 12461 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12462 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12463 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12464 | enforceRebootPermission(); |
| 12465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12466 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12467 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12468 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12469 | final long identity = Binder.clearCallingIdentity(); |
| 12470 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12471 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12472 | } finally { |
| 12473 | Binder.restoreCallingIdentity(identity); |
| 12474 | } |
| 12475 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12476 | |
| 12477 | /** |
| 12478 | * Request to get the current slicing configuration including URSP rules and |
| 12479 | * NSSAIs (configured, allowed and rejected). |
| 12480 | * |
| 12481 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12482 | */ |
| 12483 | @Override |
| 12484 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12485 | TelephonyPermissions |
| 12486 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12487 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12488 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12489 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12490 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12491 | "getSlicingConfig"); |
| 12492 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12493 | final long identity = Binder.clearCallingIdentity(); |
| 12494 | try { |
| 12495 | Phone phone = getDefaultPhone(); |
| 12496 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12497 | } finally { |
| 12498 | Binder.restoreCallingIdentity(identity); |
| 12499 | } |
| 12500 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12501 | |
| 12502 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12503 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12504 | * |
| 12505 | * @param capability The premium capability to check. |
| 12506 | * @param subId The subId to check the premium capability for. |
| 12507 | * |
| 12508 | * @return Whether the given premium capability is available to purchase. |
| 12509 | */ |
| 12510 | @Override |
| 12511 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12512 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12513 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12514 | log("Premium capability " |
| 12515 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12516 | + " is not available for purchase due to missing permissions."); |
| 12517 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12518 | + "permission READ_BASIC_PHONE_STATE."); |
| 12519 | } |
| 12520 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12522 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12523 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12524 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12525 | if (phone == null) { |
| 12526 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12527 | return false; |
| 12528 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12529 | final long identity = Binder.clearCallingIdentity(); |
| 12530 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12531 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12532 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12533 | } finally { |
| 12534 | Binder.restoreCallingIdentity(identity); |
| 12535 | } |
| 12536 | } |
| 12537 | |
| 12538 | /** |
| 12539 | * Purchase the given premium capability from the carrier. |
| 12540 | * |
| 12541 | * @param capability The premium capability to purchase. |
| 12542 | * @param callback The result of the purchase request. |
| 12543 | * @param subId The subId to purchase the premium capability for. |
| 12544 | */ |
| 12545 | @Override |
| 12546 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12547 | log("purchasePremiumCapability: capability=" |
| 12548 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12549 | + getCurrentPackageName()); |
| 12550 | |
| 12551 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12552 | mApp, "purchasePremiumCapability")) { |
| 12553 | log("purchasePremiumCapability " |
| 12554 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12555 | + " failed due to missing permissions."); |
| 12556 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12557 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12558 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12559 | mApp, "purchasePremiumCapability")) { |
| 12560 | log("purchasePremiumCapability " |
| 12561 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12562 | + " failed due to missing permissions."); |
| 12563 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12564 | } |
| 12565 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12566 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12567 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12568 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12569 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12570 | if (phone == null) { |
| 12571 | try { |
| 12572 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12573 | callback.accept(result); |
| 12574 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12575 | } catch (RemoteException e) { |
| 12576 | String logStr = "Purchase premium capability " |
| 12577 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12578 | + " failed due to RemoteException handling null phone: " + e; |
| 12579 | if (DBG) log(logStr); |
| 12580 | AnomalyReporter.reportAnomaly( |
| 12581 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12582 | } |
| 12583 | return; |
| 12584 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12585 | |
| 12586 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12587 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12588 | if (mFeatureFlags.hsumPackageManager()) { |
| 12589 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12590 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12591 | } else { |
| 12592 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12593 | getCurrentPackageName(), 0).processName; |
| 12594 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12595 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12596 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12597 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12598 | |
| 12599 | boolean isVisible = false; |
| 12600 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12601 | if (am != null) { |
| 12602 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12603 | if (processes != null) { |
| 12604 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12605 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12606 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12607 | if (process.processName.equals(callingProcess) && process.importance |
| 12608 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12609 | isVisible = true; |
| 12610 | break; |
| 12611 | } |
| 12612 | } |
| 12613 | } |
| 12614 | } |
| 12615 | |
| 12616 | if (!isVisible) { |
| 12617 | try { |
| 12618 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12619 | callback.accept(result); |
| 12620 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12621 | } catch (RemoteException e) { |
| 12622 | String logStr = "Purchase premium capability " |
| 12623 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12624 | + " failed due to RemoteException handling background application: " + e; |
| 12625 | if (DBG) log(logStr); |
| 12626 | AnomalyReporter.reportAnomaly( |
| 12627 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12628 | } |
| 12629 | return; |
| 12630 | } |
| 12631 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12632 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12633 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12634 | } |
| 12635 | |
| 12636 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12637 | * Register an IMS connection state callback |
| 12638 | */ |
| 12639 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12640 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12641 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12642 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12643 | // ImsMmTelManager |
| 12644 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12645 | TelephonyPermissions |
| 12646 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12647 | mApp, subId, "registerImsStateCallback"); |
| 12648 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12649 | // ImsRcsManager or SipDelegateManager |
| 12650 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12651 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12652 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12653 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12654 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12655 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12656 | } |
| 12657 | |
| 12658 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12659 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12660 | "IMS not available on device."); |
| 12661 | } |
| 12662 | |
| 12663 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12665 | } |
| 12666 | |
| 12667 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12668 | if (controller == null) { |
| 12669 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12670 | "IMS not available on device."); |
| 12671 | } |
| 12672 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12673 | if (callingPackage == null) { |
| 12674 | callingPackage = getCurrentPackageName(); |
| 12675 | } |
| 12676 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12677 | final long token = Binder.clearCallingIdentity(); |
| 12678 | try { |
| 12679 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12680 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12681 | } catch (ImsException e) { |
| 12682 | throw new ServiceSpecificException(e.getCode()); |
| 12683 | } finally { |
| 12684 | Binder.restoreCallingIdentity(token); |
| 12685 | } |
| 12686 | } |
| 12687 | |
| 12688 | /** |
| 12689 | * Unregister an IMS connection state callback |
| 12690 | */ |
| 12691 | @Override |
| 12692 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12693 | final long token = Binder.clearCallingIdentity(); |
| 12694 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12695 | if (controller == null) { |
| 12696 | return; |
| 12697 | } |
| 12698 | try { |
| 12699 | controller.unregisterImsStateCallback(cb); |
| 12700 | } finally { |
| 12701 | Binder.restoreCallingIdentity(token); |
| 12702 | } |
| 12703 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12704 | |
| 12705 | /** |
| 12706 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12707 | * |
| 12708 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12709 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12710 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12711 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12712 | * If there is current registered network this value will be same as the registered cell |
| 12713 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12714 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12715 | * it will be cleared and null will be returned. |
| 12716 | * |
| 12717 | */ |
| 12718 | @Override |
| 12719 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12720 | String callingFeatureId) { |
| 12721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12722 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12723 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12724 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12725 | .setCallingPackage(callingPackage) |
| 12726 | .setCallingFeatureId(callingFeatureId) |
| 12727 | .setCallingPid(Binder.getCallingPid()) |
| 12728 | .setCallingUid(Binder.getCallingUid()) |
| 12729 | .setMethod("getLastKnownCellIdentity") |
| 12730 | .setLogAsInfo(true) |
| 12731 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12732 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12733 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12734 | .build()); |
| 12735 | |
| 12736 | boolean hasFinePermission = |
| 12737 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12738 | if (!hasFinePermission |
| 12739 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12740 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12741 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12742 | } |
| 12743 | |
| 12744 | final long identity = Binder.clearCallingIdentity(); |
| 12745 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12746 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12747 | if (sst == null) return null; |
| 12748 | return sst.getLastKnownCellIdentity(); |
| 12749 | } finally { |
| 12750 | Binder.restoreCallingIdentity(identity); |
| 12751 | } |
| 12752 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12753 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12754 | /** |
| 12755 | * Sets the modem service class Name that Telephony will bind to. |
| 12756 | * |
| 12757 | * @param serviceName The class name of the modem service. |
| 12758 | * @return true if the operation is succeed, otherwise false. |
| 12759 | */ |
| 12760 | public boolean setModemService(String serviceName) { |
| 12761 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12762 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12764 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12765 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12766 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12767 | } |
| 12768 | |
| 12769 | /** |
| 12770 | * Return the class name of the currently bounded modem service. |
| 12771 | * |
| 12772 | * @return the class name of the modem service. |
| 12773 | */ |
| 12774 | public String getModemService() { |
| 12775 | String result; |
| 12776 | Log.d(LOG_TAG, "getModemService"); |
| 12777 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12778 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12779 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12780 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12781 | "getModemService"); |
| 12782 | result = mPhoneConfigurationManager.getModemService(); |
| 12783 | Log.d(LOG_TAG, "result = " + result); |
| 12784 | return result; |
| 12785 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12786 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12787 | /** |
| 12788 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12789 | * including carrier config, entitlement server, and config update. |
| 12790 | * |
| 12791 | * @param subId subId The subscription ID of the carrier. |
| 12792 | * |
| 12793 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12794 | * be returned. |
| 12795 | * |
| 12796 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12797 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12798 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12799 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12800 | final long identity = Binder.clearCallingIdentity(); |
| 12801 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12802 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12803 | } finally { |
| 12804 | Binder.restoreCallingIdentity(identity); |
| 12805 | } |
| 12806 | } |
| 12807 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12808 | @Override |
| 12809 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12810 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12811 | mApp.enforceCallingOrSelfPermission( |
| 12812 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12813 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12814 | |
| 12815 | final long identity = Binder.clearCallingIdentity(); |
| 12816 | try { |
| 12817 | Phone phone = getPhone(subId); |
| 12818 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12819 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12820 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12821 | phone.setVoiceServiceStateOverride(hasService); |
| 12822 | } finally { |
| 12823 | Binder.restoreCallingIdentity(identity); |
| 12824 | } |
| 12825 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12826 | |
| 12827 | /** |
| 12828 | * set removable eSIM as default eUICC. |
| 12829 | * |
| 12830 | * @hide |
| 12831 | */ |
| 12832 | @Override |
| 12833 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12834 | enforceModifyPermission(); |
| 12835 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12836 | |
| 12837 | final long identity = Binder.clearCallingIdentity(); |
| 12838 | try { |
| 12839 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12840 | } finally { |
| 12841 | Binder.restoreCallingIdentity(identity); |
| 12842 | } |
| 12843 | } |
| 12844 | |
| 12845 | /** |
| 12846 | * Returns whether the removable eSIM is default eUICC or not. |
| 12847 | * |
| 12848 | * @hide |
| 12849 | */ |
| 12850 | @Override |
| 12851 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12852 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12853 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12854 | |
| 12855 | final long identity = Binder.clearCallingIdentity(); |
| 12856 | try { |
| 12857 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12858 | } finally { |
| 12859 | Binder.restoreCallingIdentity(identity); |
| 12860 | } |
| 12861 | } |
| 12862 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12863 | /** |
| 12864 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12865 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12866 | * application currently configured for this user. |
| 12867 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12868 | * {@code null} if the functionality is not supported. |
| 12869 | * @hide |
| 12870 | */ |
| 12871 | @Override |
| 12872 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12873 | boolean updateIfNeeded) { |
| 12874 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12875 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12876 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12877 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12878 | "getDefaultRespondViaMessageApplication"); |
| 12879 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12880 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12881 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12882 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12883 | UserHandle mainUser = null; |
| 12884 | Context userContext = null; |
| 12885 | final long identity = Binder.clearCallingIdentity(); |
| 12886 | try { |
| 12887 | mainUser = mUserManager.getMainUser(); |
| 12888 | userContext = context.createContextAsUser(mainUser, 0); |
| 12889 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12890 | } finally { |
| 12891 | Binder.restoreCallingIdentity(identity); |
| 12892 | } |
| 12893 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12894 | updateIfNeeded, mainUser); |
| 12895 | } else { |
| 12896 | UserHandle userHandle = null; |
| 12897 | final long identity = Binder.clearCallingIdentity(); |
| 12898 | try { |
| 12899 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12900 | } finally { |
| 12901 | Binder.restoreCallingIdentity(identity); |
| 12902 | } |
| 12903 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12904 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12905 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12906 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12907 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12908 | |
| 12909 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12910 | * Set whether the device is able to connect with null ciphering or integrity |
| 12911 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12912 | * and all new subscriptions after this. |
| 12913 | * |
| 12914 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12915 | * @hide |
| 12916 | */ |
| 12917 | @Override |
| 12918 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12919 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12920 | enforceModifyPermission(); |
| 12921 | checkForNullCipherAndIntegritySupport(); |
| 12922 | |
| 12923 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12924 | // for listening to these preference changes and applying them immediately. |
| 12925 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12926 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12927 | editor.apply(); |
| 12928 | |
| 12929 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12930 | phone.handleNullCipherEnabledChange(); |
| 12931 | } |
| 12932 | } |
| 12933 | |
| 12934 | |
| 12935 | /** |
| 12936 | * Get whether the device is able to connect with null ciphering or integrity |
| 12937 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12938 | * the state of the radio. |
| 12939 | * |
| 12940 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12941 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12942 | * version for this feature. |
| 12943 | * @hide |
| 12944 | */ |
| 12945 | @Override |
| 12946 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12947 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12948 | enforceReadPermission(); |
| 12949 | checkForNullCipherAndIntegritySupport(); |
| 12950 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12951 | } |
| 12952 | |
| 12953 | private void checkForNullCipherAndIntegritySupport() { |
| 12954 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12955 | throw new UnsupportedOperationException( |
| 12956 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12957 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12958 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12959 | throw new UnsupportedOperationException( |
| 12960 | "Null cipher and integrity operations unsupported by modem"); |
| 12961 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12962 | } |
| 12963 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12964 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12965 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12966 | throw new UnsupportedOperationException( |
| 12967 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12968 | + "above"); |
| 12969 | } |
| 12970 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12971 | throw new UnsupportedOperationException( |
| 12972 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12973 | } |
| 12974 | } |
| 12975 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12976 | private void checkForNullCipherNotificationSupport() { |
| 12977 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12978 | throw new UnsupportedOperationException( |
| 12979 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12980 | } |
| 12981 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12982 | throw new UnsupportedOperationException( |
| 12983 | "Null cipher notification operations unsupported by modem"); |
| 12984 | } |
| 12985 | } |
| 12986 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12987 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12988 | * Get the SIM state for the slot index. |
| 12989 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12990 | * |
| 12991 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12992 | */ |
| 12993 | @Override |
| 12994 | @SimState |
| 12995 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 12996 | if (!mApp.getResources().getBoolean( |
| 12997 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 12998 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12999 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13000 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13001 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13002 | IccCardConstants.State simState; |
| 13003 | if (slotIndex < 0) { |
| 13004 | simState = IccCardConstants.State.UNKNOWN; |
| 13005 | } else { |
| 13006 | Phone phone = null; |
| 13007 | try { |
| 13008 | phone = PhoneFactory.getPhone(slotIndex); |
| 13009 | } catch (IllegalStateException e) { |
| 13010 | // ignore |
| 13011 | } |
| 13012 | if (phone == null) { |
| 13013 | simState = IccCardConstants.State.UNKNOWN; |
| 13014 | } else { |
| 13015 | IccCard icc = phone.getIccCard(); |
| 13016 | if (icc == null) { |
| 13017 | simState = IccCardConstants.State.UNKNOWN; |
| 13018 | } else { |
| 13019 | simState = icc.getState(); |
| 13020 | } |
| 13021 | } |
| 13022 | } |
| 13023 | return simState.ordinal(); |
| 13024 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13025 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13026 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13027 | boolean enableLogcat, |
| 13028 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13029 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13030 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13031 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13032 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13033 | ecdDataBuilder |
| 13034 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13035 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13036 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13037 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13038 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13039 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13040 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13041 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13042 | Executors.newCachedThreadPool(), db, |
| 13043 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13044 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13045 | } |
| 13046 | |
| 13047 | /** |
| 13048 | * Request telephony to persist state for debugging emergency call failures. |
| 13049 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13050 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13051 | * @param enableLogcat whether to collect logcat output |
| 13052 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13053 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13054 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13055 | */ |
| 13056 | @Override |
| 13057 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13058 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13059 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13060 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13061 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13062 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13063 | && Flags.enableReadDropboxPermission()) { |
| 13064 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13065 | "persistEmergencyCallDiagnosticData"); |
| 13066 | } else { |
| 13067 | // Otherwise, enforce legacy permission. |
| 13068 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13069 | "persistEmergencyCallDiagnosticData"); |
| 13070 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13071 | final long identity = Binder.clearCallingIdentity(); |
| 13072 | try { |
| 13073 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13074 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13075 | |
| 13076 | } finally { |
| 13077 | Binder.restoreCallingIdentity(identity); |
| 13078 | } |
| 13079 | } |
| 13080 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13081 | /** |
| 13082 | * Get current cell broadcast ranges. |
| 13083 | */ |
| 13084 | @Override |
| 13085 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13086 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13087 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13088 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13089 | |
| 13090 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13091 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13092 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13093 | final long identity = Binder.clearCallingIdentity(); |
| 13094 | try { |
| 13095 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13096 | } finally { |
| 13097 | Binder.restoreCallingIdentity(identity); |
| 13098 | } |
| 13099 | } |
| 13100 | |
| 13101 | /** |
| 13102 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13103 | * |
| 13104 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13105 | */ |
| 13106 | @Override |
| 13107 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13108 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13109 | @Nullable IIntegerConsumer callback) { |
| 13110 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13111 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13112 | |
| 13113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13114 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13115 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13116 | final long identity = Binder.clearCallingIdentity(); |
| 13117 | try { |
| 13118 | Phone phone = getPhoneFromSubId(subId); |
| 13119 | if (DBG) { |
| 13120 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13121 | } |
| 13122 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13123 | if (callback != null) { |
| 13124 | try { |
| 13125 | callback.accept(result); |
| 13126 | } catch (RemoteException e) { |
| 13127 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13128 | } |
| 13129 | } |
| 13130 | }); |
| 13131 | } finally { |
| 13132 | Binder.restoreCallingIdentity(identity); |
| 13133 | } |
| 13134 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13135 | |
| 13136 | /** |
| 13137 | * Returns whether the device supports the domain selection service. |
| 13138 | * |
| 13139 | * @return {@code true} if the device supports the domain selection service. |
| 13140 | */ |
| 13141 | @Override |
| 13142 | public boolean isDomainSelectionSupported() { |
| 13143 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13144 | "isDomainSelectionSupported"); |
| 13145 | |
| 13146 | final long identity = Binder.clearCallingIdentity(); |
| 13147 | try { |
| 13148 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13149 | } finally { |
| 13150 | Binder.restoreCallingIdentity(identity); |
| 13151 | } |
| 13152 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13153 | |
| 13154 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13155 | * Returns whether the AOSP domain selection service is supported. |
| 13156 | * |
| 13157 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13158 | * {@code false} otherwise. |
| 13159 | */ |
| 13160 | @Override |
| 13161 | public boolean isAospDomainSelectionService() { |
| 13162 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13163 | "isAospDomainSelectionService"); |
| 13164 | |
| 13165 | final long identity = Binder.clearCallingIdentity(); |
| 13166 | try { |
| 13167 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13168 | String dssComponentName = mApp.getResources().getString( |
| 13169 | R.string.config_domain_selection_service_component_name); |
| 13170 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13171 | TelephonyDomainSelectionService.class.getName()); |
| 13172 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13173 | + ", aosp=" + componentName.flattenToString()); |
| 13174 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13175 | } |
| 13176 | } finally { |
| 13177 | Binder.restoreCallingIdentity(identity); |
| 13178 | } |
| 13179 | return false; |
| 13180 | } |
| 13181 | |
| 13182 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13183 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13184 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13185 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13186 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13187 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13188 | * {@code false} to disable. |
| 13189 | * @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] | 13190 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13191 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13192 | * |
| 13193 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13194 | */ |
| 13195 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13196 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13197 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13198 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13199 | if (enableSatellite) { |
| 13200 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13201 | @Override |
| 13202 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13203 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13204 | + ", resultData=" + resultData); |
| 13205 | boolean isAllowed = false; |
| 13206 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13207 | callback::accept); |
| 13208 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13209 | if (resultData != null |
| 13210 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13211 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13212 | } else { |
| 13213 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13214 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13215 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13216 | result.accept(resultCode); |
| 13217 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13218 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13219 | if (isAllowed) { |
| 13220 | mSatelliteController.requestSatelliteEnabled( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13221 | enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13222 | } else { |
| 13223 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13224 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13225 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13226 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13227 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
youngtaecha | 2e6cfdd | 2024-09-04 04:59:10 +0000 | [diff] [blame] | 13228 | resultReceiver, true); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13229 | } else { |
| 13230 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13231 | mSatelliteController.requestSatelliteEnabled( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13232 | enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13233 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13234 | } |
| 13235 | |
| 13236 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13237 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13238 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13239 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13240 | * 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] | 13241 | * |
| 13242 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13243 | */ |
| 13244 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13245 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13246 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13247 | mSatelliteController.requestIsSatelliteEnabled(result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13248 | } |
| 13249 | |
| 13250 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13251 | * Request to get whether the satellite service demo mode is enabled. |
| 13252 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13253 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13254 | * if the request is successful or an error code if the request failed. |
| 13255 | * |
| 13256 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13257 | */ |
| 13258 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13259 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13260 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13261 | mSatelliteController.requestIsDemoModeEnabled(result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13262 | } |
| 13263 | |
| 13264 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13265 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13266 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13267 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13268 | * enabled if the request is successful or an error code if the request failed. |
| 13269 | * |
| 13270 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13271 | */ |
| 13272 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13273 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13274 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13275 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13276 | } |
| 13277 | |
| 13278 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13279 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13280 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13281 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13282 | * 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] | 13283 | */ |
| 13284 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13285 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
| 13286 | mSatelliteController.requestIsSatelliteSupported(result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13287 | } |
| 13288 | |
| 13289 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13290 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13291 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13292 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13293 | * 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] | 13294 | * |
| 13295 | * @throws SecurityException if the caller doesn't have required permission. |
| 13296 | */ |
| 13297 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13298 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13299 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13300 | mSatelliteController.requestSatelliteCapabilities(result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13301 | } |
| 13302 | |
| 13303 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13304 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13305 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13306 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13307 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13308 | * @param resultCallback The callback to get the result of the request. |
| 13309 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13310 | * |
| 13311 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13312 | */ |
| 13313 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13314 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13315 | @NonNull IIntegerConsumer resultCallback, |
| 13316 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13317 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13318 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13319 | } |
| 13320 | |
| 13321 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13322 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13323 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13324 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13325 | * @param resultCallback The callback to get the result of the request. |
| 13326 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13327 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13328 | * |
| 13329 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13330 | */ |
| 13331 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13332 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13333 | @NonNull IIntegerConsumer resultCallback, |
| 13334 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13335 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13336 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13337 | } |
| 13338 | |
| 13339 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13340 | * Register the subscription with a satellite provider. |
| 13341 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13342 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13343 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13344 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13345 | * @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] | 13346 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13347 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13348 | * @return The signal transport used by the caller to cancel the provision request, |
| 13349 | * or {@code null} if the request failed. |
| 13350 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13351 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13352 | */ |
| 13353 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13354 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13355 | @NonNull String token, @NonNull byte[] provisionData, |
| 13356 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13357 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13358 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13359 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13360 | } |
| 13361 | |
| 13362 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13363 | * Unregister the device/subscription with the satellite provider. |
| 13364 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13365 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13366 | * should report as deprovisioned. |
| 13367 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13368 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13369 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13370 | * |
| 13371 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13372 | */ |
| 13373 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13374 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13375 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13376 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13377 | mSatelliteController.deprovisionSatelliteService(token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13378 | } |
| 13379 | |
| 13380 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13381 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13382 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13383 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13384 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13385 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13386 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13387 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13388 | */ |
| 13389 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13390 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13391 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13392 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13393 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13394 | } |
| 13395 | |
| 13396 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13397 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13398 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13399 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13400 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13401 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13402 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13403 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13404 | */ |
| 13405 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13406 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13407 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13408 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13409 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13410 | } |
| 13411 | |
| 13412 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13413 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13414 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13415 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13416 | * satellite provider if the request is successful or an error code if the |
| 13417 | * request failed. |
| 13418 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13419 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13420 | */ |
| 13421 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13422 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13423 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13424 | mSatelliteController.requestIsSatelliteProvisioned(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13425 | } |
| 13426 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13427 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13428 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13429 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13430 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13431 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13432 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13433 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13434 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13435 | */ |
| 13436 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13437 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13438 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13439 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13440 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13441 | } |
| 13442 | |
| 13443 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13444 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13445 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13446 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13447 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13448 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13449 | * |
| 13450 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13451 | */ |
| 13452 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13453 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13454 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13455 | mSatelliteController.unregisterForModemStateChanged(callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13456 | } |
| 13457 | |
| 13458 | /** |
| 13459 | * Register to receive incoming datagrams over satellite. |
| 13460 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13461 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13462 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13463 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13464 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13465 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13466 | */ |
| 13467 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13468 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13469 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13470 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13471 | return mSatelliteController.registerForIncomingDatagram(callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13472 | } |
| 13473 | |
| 13474 | /** |
| 13475 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13476 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13477 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13478 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13479 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13480 | * |
| 13481 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13482 | */ |
| 13483 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13484 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13485 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13486 | mSatelliteController.unregisterForIncomingDatagram(callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13487 | } |
| 13488 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13489 | /** |
| 13490 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13491 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13492 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13493 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13494 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13495 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13496 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13497 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13498 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13499 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13500 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13501 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13502 | mSatelliteController.pollPendingDatagrams(callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13503 | } |
| 13504 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13505 | /** |
| 13506 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13507 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13508 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13509 | * input to this method. Datagram received here will be passed down to modem without any |
| 13510 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13511 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13512 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13513 | * SOS_SMS or LOCATION_SHARING. |
| 13514 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13515 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13516 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13517 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13518 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13519 | * |
| 13520 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13521 | */ |
| 13522 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13523 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13524 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13525 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13526 | enforceSatelliteCommunicationPermission("sendDatagram"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13527 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13528 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13529 | } |
| 13530 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13531 | /** |
| 13532 | * Request to get whether satellite communication is allowed for the current location. |
| 13533 | * |
| 13534 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13535 | * allowed for the current location for. |
| 13536 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13537 | * for the current location if the request is successful or an error code |
| 13538 | * if the request failed. |
| 13539 | * |
| 13540 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13541 | */ |
| 13542 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13543 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13544 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13545 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
youngtaecha | 2e6cfdd | 2024-09-04 04:59:10 +0000 | [diff] [blame] | 13546 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, false); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13547 | } |
| 13548 | |
| 13549 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13550 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13551 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13552 | * @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] | 13553 | * be visible if the request is successful or an error code if the request failed. |
| 13554 | * |
| 13555 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13556 | */ |
| 13557 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13558 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13559 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13560 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13561 | } |
| 13562 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13563 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13564 | * Inform that Device is aligned to satellite for demo mode. |
| 13565 | * |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13566 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13567 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13568 | * |
| 13569 | * @throws SecurityException if the caller doesn't have required permission. |
| 13570 | */ |
| 13571 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13572 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13573 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13574 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13575 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13576 | } |
| 13577 | |
| 13578 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13579 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13580 | * by modem. |
| 13581 | * |
| 13582 | * @param subId The subId of the subscription to request for. |
| 13583 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13584 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13585 | * operation. |
| 13586 | * |
| 13587 | * @throws SecurityException if the caller doesn't have required permission. |
| 13588 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13589 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13590 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13591 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13592 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13593 | final long identity = Binder.clearCallingIdentity(); |
| 13594 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13595 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13596 | } finally { |
| 13597 | Binder.restoreCallingIdentity(identity); |
| 13598 | } |
| 13599 | } |
| 13600 | |
| 13601 | /** |
| 13602 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13603 | * by modem. |
| 13604 | * |
| 13605 | * @param subId The subId of the subscription to request for. |
| 13606 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13607 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13608 | * operation. |
| 13609 | * |
| 13610 | * @throws SecurityException if the caller doesn't have required permission. |
| 13611 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13612 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13613 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13614 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13615 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13616 | final long identity = Binder.clearCallingIdentity(); |
| 13617 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13618 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13619 | } finally { |
| 13620 | Binder.restoreCallingIdentity(identity); |
| 13621 | } |
| 13622 | } |
| 13623 | |
| 13624 | /** |
| 13625 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13626 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13627 | * |
| 13628 | * @param subId The subId of the subscription to request for. |
| 13629 | * |
| 13630 | * @return Integer array of reasons for disallowing satellite communication. |
| 13631 | * |
| 13632 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13633 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13634 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13635 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13636 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13637 | final long identity = Binder.clearCallingIdentity(); |
| 13638 | try { |
| 13639 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13640 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13641 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13642 | } finally { |
| 13643 | Binder.restoreCallingIdentity(identity); |
| 13644 | } |
| 13645 | } |
| 13646 | |
| 13647 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13648 | * Request to get the signal strength of the satellite connection. |
| 13649 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13650 | * @param result Result receiver to get the error code of the request and the current signal |
| 13651 | * strength of the satellite connection. |
| 13652 | * |
| 13653 | * @throws SecurityException if the caller doesn't have required permission. |
| 13654 | */ |
| 13655 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13656 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13657 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13658 | final long identity = Binder.clearCallingIdentity(); |
| 13659 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13660 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13661 | } finally { |
| 13662 | Binder.restoreCallingIdentity(identity); |
| 13663 | } |
| 13664 | } |
| 13665 | |
| 13666 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13667 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13668 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13669 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13670 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13671 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13672 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13673 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13674 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13675 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13676 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13677 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13678 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13679 | */ |
| 13680 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13681 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13682 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13683 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13684 | final long identity = Binder.clearCallingIdentity(); |
| 13685 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13686 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13687 | } finally { |
| 13688 | Binder.restoreCallingIdentity(identity); |
| 13689 | } |
| 13690 | } |
| 13691 | |
| 13692 | /** |
| 13693 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13694 | * If callback was not registered before, the request will be ignored. |
| 13695 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13696 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13697 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13698 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13699 | * |
| 13700 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13701 | */ |
| 13702 | @Override |
| 13703 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13704 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13705 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13706 | final long identity = Binder.clearCallingIdentity(); |
| 13707 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13708 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13709 | } finally { |
| 13710 | Binder.restoreCallingIdentity(identity); |
| 13711 | } |
| 13712 | } |
| 13713 | |
| 13714 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13715 | * Registers for satellite capabilities change event from the satellite service. |
| 13716 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13717 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13718 | * |
| 13719 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13720 | * |
| 13721 | * @throws SecurityException if the caller doesn't have required permission. |
| 13722 | */ |
| 13723 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13724 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13725 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13726 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13727 | final long identity = Binder.clearCallingIdentity(); |
| 13728 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13729 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13730 | } finally { |
| 13731 | Binder.restoreCallingIdentity(identity); |
| 13732 | } |
| 13733 | } |
| 13734 | |
| 13735 | /** |
| 13736 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13737 | * If callback was not registered before, the request will be ignored. |
| 13738 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13739 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13740 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13741 | * |
| 13742 | * @throws SecurityException if the caller doesn't have required permission. |
| 13743 | */ |
| 13744 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13745 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13746 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13747 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13748 | final long identity = Binder.clearCallingIdentity(); |
| 13749 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13750 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13751 | } finally { |
| 13752 | Binder.restoreCallingIdentity(identity); |
| 13753 | } |
| 13754 | } |
| 13755 | |
| 13756 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13757 | * Registers for the satellite supported state changed. |
| 13758 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13759 | * @param callback The callback to handle the satellite supported state changed event. |
| 13760 | * |
| 13761 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13762 | * |
| 13763 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13764 | */ |
| 13765 | @Override |
| 13766 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13767 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13768 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13769 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13770 | } |
| 13771 | |
| 13772 | /** |
| 13773 | * Unregisters for the satellite supported state changed. |
| 13774 | * If callback was not registered before, the request will be ignored. |
| 13775 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13776 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13777 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13778 | * |
| 13779 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13780 | */ |
| 13781 | @Override |
| 13782 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13783 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13784 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13785 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13786 | } |
| 13787 | |
| 13788 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13789 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13790 | * |
| 13791 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13792 | * @param provisioned Whether satellite should be provisioned or not. |
| 13793 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13794 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13795 | * {@code false} otherwise. |
| 13796 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13797 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 13798 | String provisioned) { |
| 13799 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 13800 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13801 | TelephonyPermissions.enforceShellOnly( |
| 13802 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13804 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13805 | "setSatelliteServicePackageName"); |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13806 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 13807 | provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13808 | } |
| 13809 | |
| 13810 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13811 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13812 | * |
| 13813 | * @param servicePackageName The package name of the satellite gateway service. |
| 13814 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13815 | * {@code false} otherwise. |
| 13816 | */ |
| 13817 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13818 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13819 | TelephonyPermissions.enforceShellOnly( |
| 13820 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13822 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13823 | "setSatelliteGatewayServicePackageName"); |
| 13824 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13825 | } |
| 13826 | |
| 13827 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13828 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13829 | * |
| 13830 | * @param packageName The package name of the satellite pointing UI app. |
| 13831 | * @param className The class name of the satellite pointing UI app. |
| 13832 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13833 | * {@code false} otherwise. |
| 13834 | */ |
| 13835 | public boolean setSatellitePointingUiClassName( |
| 13836 | @Nullable String packageName, @Nullable String className) { |
| 13837 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13838 | + ", className=" + className); |
| 13839 | TelephonyPermissions.enforceShellOnly( |
| 13840 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13842 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13843 | "setSatelliteGatewayServicePackageName"); |
| 13844 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13845 | } |
| 13846 | |
| 13847 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13848 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13849 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13850 | * listening mode. |
| 13851 | * |
| 13852 | * @param timeoutMillis The timeout duration in millisecond. |
| 13853 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13854 | */ |
| 13855 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13856 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13857 | TelephonyPermissions.enforceShellOnly( |
| 13858 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13860 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13861 | "setSatelliteListeningTimeoutDuration"); |
| 13862 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13863 | } |
| 13864 | |
| 13865 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13866 | * This API can be used by only CTS to override the timeout durations used by the |
| 13867 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13868 | * |
| 13869 | * @param timeoutMillis The timeout duration in millisecond. |
| 13870 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13871 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13872 | public boolean setDatagramControllerTimeoutDuration( |
| 13873 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13874 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13875 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13876 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13877 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13879 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13880 | "setDatagramControllerTimeoutDuration"); |
| 13881 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13882 | reset, timeoutType, timeoutMillis); |
| 13883 | } |
| 13884 | |
| 13885 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 13886 | * This API can be used by only CTS to override the boolean configs used by the |
| 13887 | * DatagramController module. |
| 13888 | * |
| 13889 | * @param enable Whether to enable or disable boolean config. |
| 13890 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 13891 | */ |
| 13892 | public boolean setDatagramControllerBooleanConfig( |
| 13893 | boolean reset, int booleanType, boolean enable) { |
| 13894 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 13895 | + ", reset=" + reset + ", enable=" + enable); |
| 13896 | TelephonyPermissions.enforceShellOnly( |
| 13897 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 13898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13899 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13900 | "ssetDatagramControllerBooleanConfig"); |
| 13901 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable); |
| 13902 | } |
| 13903 | |
| 13904 | |
| 13905 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13906 | * This API can be used by only CTS to override the timeout durations used by the |
| 13907 | * SatelliteController module. |
| 13908 | * |
| 13909 | * @param timeoutMillis The timeout duration in millisecond. |
| 13910 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13911 | */ |
| 13912 | public boolean setSatelliteControllerTimeoutDuration( |
| 13913 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13914 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13915 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13916 | TelephonyPermissions.enforceShellOnly( |
| 13917 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13919 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13920 | "setSatelliteControllerTimeoutDuration"); |
| 13921 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13922 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13923 | } |
| 13924 | |
| 13925 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13926 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13927 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13928 | * |
| 13929 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13930 | * of the following values to enable the override: |
| 13931 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13932 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13933 | * To disable the override, use -1 for handoverType. |
| 13934 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13935 | * delaySeconds after the emergency call starts. |
| 13936 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13937 | */ |
| 13938 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13939 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13940 | TelephonyPermissions.enforceShellOnly( |
| 13941 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13943 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13944 | "setEmergencyCallToSatelliteHandoverType"); |
| 13945 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13946 | handoverType, delaySeconds); |
| 13947 | } |
| 13948 | |
| 13949 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13950 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13951 | * |
| 13952 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13953 | * otherwise. |
| 13954 | * @param isProvisioned The overriding provision status. |
| 13955 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13956 | */ |
| 13957 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13958 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13959 | + ", isProvisioned=" + isProvisioned); |
| 13960 | TelephonyPermissions.enforceShellOnly( |
| 13961 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13963 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13964 | "setOemEnabledSatelliteProvisionStatus"); |
| 13965 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13966 | } |
| 13967 | |
| 13968 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13969 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13970 | * |
| 13971 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13972 | */ |
| 13973 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13974 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13975 | long locationCountryCodeTimestampNanos) { |
| 13976 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13977 | + String.join(", ", currentNetworkCountryCodes) |
| 13978 | + ", locationCountryCode=" + locationCountryCode |
| 13979 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13980 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13981 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13982 | TelephonyPermissions.enforceShellOnly( |
| 13983 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13985 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13986 | "setCachedLocationCountryCode"); |
youngtaecha | 31b141d | 2024-07-15 12:01:39 +0000 | [diff] [blame] | 13987 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), mFeatureFlags) |
| 13988 | .setCountryCodes(reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, |
| 13989 | locationCountryCode, locationCountryCodeTimestampNanos); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13990 | } |
| 13991 | |
| 13992 | /** |
| 13993 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13994 | * access controller. |
| 13995 | * |
| 13996 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13997 | * otherwise. |
| 13998 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13999 | */ |
| 14000 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14001 | String s2CellFile, long locationFreshDurationNanos, |
| 14002 | List<String> satelliteCountryCodes) { |
| 14003 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14004 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14005 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14006 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 14007 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 14008 | TelephonyPermissions.enforceShellOnly( |
| 14009 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14011 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14012 | "setSatelliteAccessControlOverlayConfigs"); |
| 14013 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 14014 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 14015 | } |
| 14016 | |
| 14017 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14018 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14019 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14020 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14021 | * |
| 14022 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14023 | * satellite modem or not. |
| 14024 | * |
| 14025 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14026 | */ |
| 14027 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14028 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14029 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14030 | + "disabled"); |
| 14031 | return false; |
| 14032 | } |
| 14033 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14034 | TelephonyPermissions.enforceShellOnly( |
| 14035 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14037 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14038 | "setShouldSendDatagramToModemInDemoMode"); |
| 14039 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14040 | shouldSendToModemInDemoMode); |
| 14041 | } |
| 14042 | |
| 14043 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14044 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14045 | * |
| 14046 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14047 | * the allowed state. |
| 14048 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14049 | */ |
| 14050 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14051 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14052 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14053 | + "oemEnabledSatelliteFlag is disabled"); |
| 14054 | return false; |
| 14055 | } |
| 14056 | |
| 14057 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14058 | + "state=" + state); |
| 14059 | TelephonyPermissions.enforceShellOnly( |
| 14060 | Binder.getCallingUid(), |
| 14061 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14062 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14063 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14064 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14065 | return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache( |
| 14066 | state); |
| 14067 | } |
| 14068 | |
| 14069 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14070 | * Sets the service defined in ComponentName to be bound. |
| 14071 | * |
| 14072 | * This should only be used for testing. |
| 14073 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14074 | * {@code false} otherwise. |
| 14075 | */ |
| 14076 | @Override |
| 14077 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14078 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14079 | |
| 14080 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14081 | "setDomainSelectionServiceOverride"); |
| 14082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14083 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14084 | |
| 14085 | final long identity = Binder.clearCallingIdentity(); |
| 14086 | try { |
| 14087 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14088 | return DomainSelectionResolver.getInstance() |
| 14089 | .setDomainSelectionServiceOverride(componentName); |
| 14090 | } |
| 14091 | } finally { |
| 14092 | Binder.restoreCallingIdentity(identity); |
| 14093 | } |
| 14094 | return false; |
| 14095 | } |
| 14096 | |
| 14097 | /** |
| 14098 | * Clears the DomainSelectionService override. |
| 14099 | * |
| 14100 | * This should only be used for testing. |
| 14101 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14102 | * {@code false} otherwise. |
| 14103 | */ |
| 14104 | @Override |
| 14105 | public boolean clearDomainSelectionServiceOverride() { |
| 14106 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14107 | |
| 14108 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14109 | "clearDomainSelectionServiceOverride"); |
| 14110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14111 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14112 | |
| 14113 | final long identity = Binder.clearCallingIdentity(); |
| 14114 | try { |
| 14115 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14116 | return DomainSelectionResolver.getInstance() |
| 14117 | .clearDomainSelectionServiceOverride(); |
| 14118 | } |
| 14119 | } finally { |
| 14120 | Binder.restoreCallingIdentity(identity); |
| 14121 | } |
| 14122 | return false; |
| 14123 | } |
| 14124 | |
| 14125 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14126 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14127 | * |
| 14128 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14129 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14130 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14131 | * |
| 14132 | * @param enable if notifications about disclosure events should be enabled |
| 14133 | * @throws SecurityException if the caller does not have the required privileges |
| 14134 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14135 | */ |
| 14136 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14137 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14138 | enforceModifyPermission(); |
| 14139 | checkForIdentifierDisclosureNotificationSupport(); |
| 14140 | |
| 14141 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14142 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14143 | editor.apply(); |
| 14144 | |
| 14145 | // Each phone instance is responsible for updating its respective modem immediately |
| 14146 | // after we've made a preference change. |
| 14147 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14148 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14149 | } |
| 14150 | } |
| 14151 | |
| 14152 | /** |
| 14153 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14154 | * |
| 14155 | * @throws SecurityException if the caller does not have the required privileges |
| 14156 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14157 | */ |
| 14158 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14159 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14160 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14161 | checkForIdentifierDisclosureNotificationSupport(); |
| 14162 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14163 | } |
| 14164 | |
| 14165 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14166 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14167 | * are in use by the cellular modem. |
| 14168 | * |
| 14169 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14170 | * @throws SecurityException if the caller does not have the required privileges |
| 14171 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14172 | * and integrity algorithms in use |
| 14173 | * @hide |
| 14174 | */ |
| 14175 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14176 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14177 | enforceModifyPermission(); |
| 14178 | checkForNullCipherNotificationSupport(); |
| 14179 | |
| 14180 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14181 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14182 | editor.apply(); |
| 14183 | |
| 14184 | // Each phone instance is responsible for updating its respective modem immediately |
| 14185 | // after a preference change. |
| 14186 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14187 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14188 | } |
| 14189 | } |
| 14190 | |
| 14191 | /** |
| 14192 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14193 | * cellular modem. |
| 14194 | * |
| 14195 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14196 | * @throws SecurityException if the caller does not have the required privileges |
| 14197 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14198 | * and integrity algorithms in use |
| 14199 | * @hide |
| 14200 | */ |
| 14201 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14202 | public boolean isNullCipherNotificationsEnabled() { |
| 14203 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14204 | checkForNullCipherNotificationSupport(); |
| 14205 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14206 | } |
| 14207 | |
| 14208 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14209 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14210 | * |
| 14211 | * <p>This method behaves in one of the following ways: |
| 14212 | * <ul> |
| 14213 | * <li>return true : if the calling package has the appop permission {@link |
| 14214 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14215 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14216 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14217 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14218 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14219 | * </ul> |
| 14220 | */ |
| 14221 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14222 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14223 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14224 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14225 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14226 | return true; |
| 14227 | } |
| 14228 | } |
| 14229 | return false; |
| 14230 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14231 | |
| 14232 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14233 | * @return The subscription manager service instance. |
| 14234 | */ |
| 14235 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14236 | return SubscriptionManagerService.getInstance(); |
| 14237 | } |
| 14238 | |
| 14239 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14240 | * Class binds the consumer[callback] and carrierId. |
| 14241 | */ |
| 14242 | private static class CallerCallbackInfo { |
| 14243 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14244 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14245 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14246 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14247 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14248 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14249 | } |
| 14250 | |
| 14251 | public Consumer<Integer> getConsumer() { |
| 14252 | return mConsumer; |
| 14253 | } |
| 14254 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14255 | public Set<Integer> getCarrierIds() { |
| 14256 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14257 | } |
| 14258 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14259 | |
| 14260 | /* |
| 14261 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14262 | * But the context that is passed in is unused if the phone app is already alive. |
| 14263 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14264 | */ |
| 14265 | @VisibleForTesting |
| 14266 | public void setPackageManager(PackageManager packageManager) { |
| 14267 | mPackageManager = packageManager; |
| 14268 | } |
| 14269 | |
| 14270 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14271 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14272 | * But the context that is passed in is unused if the phone app is already alive. |
| 14273 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14274 | */ |
| 14275 | @VisibleForTesting |
| 14276 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14277 | mAppOps = appOps; |
| 14278 | } |
| 14279 | |
| 14280 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14281 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14282 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14283 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14284 | */ |
| 14285 | @VisibleForTesting |
| 14286 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14287 | mFeatureFlags = featureFlags; |
| 14288 | } |
| 14289 | |
| 14290 | /** |
| 14291 | * Make sure the device has required telephony feature |
| 14292 | * |
| 14293 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14294 | */ |
| 14295 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14296 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14297 | if (callingPackage == null || mPackageManager == null) { |
| 14298 | return; |
| 14299 | } |
| 14300 | |
| 14301 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14302 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14303 | Binder.getCallingUserHandle()) |
| 14304 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14305 | // Skip to check associated telephony feature, |
| 14306 | // if compatibility change is not enabled for the current process or |
| 14307 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14308 | return; |
| 14309 | } |
| 14310 | |
| 14311 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14312 | throw new UnsupportedOperationException( |
| 14313 | methodName + " is unsupported without " + telephonyFeature); |
| 14314 | } |
| 14315 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14316 | |
| 14317 | /** |
| 14318 | * Registers for the satellite communication allowed state changed. |
| 14319 | * |
| 14320 | * @param subId The subId of the subscription to register for the satellite communication |
| 14321 | * allowed state changed. |
| 14322 | * @param callback The callback to handle the satellite communication allowed |
| 14323 | * state changed event. |
| 14324 | * |
| 14325 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14326 | * |
| 14327 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14328 | */ |
| 14329 | @Override |
| 14330 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14331 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14332 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14333 | final long identity = Binder.clearCallingIdentity(); |
| 14334 | try { |
| 14335 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14336 | subId, callback); |
| 14337 | } finally { |
| 14338 | Binder.restoreCallingIdentity(identity); |
| 14339 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14340 | } |
| 14341 | |
| 14342 | /** |
| 14343 | * Unregisters for the satellite communication allowed state changed. |
| 14344 | * If callback was not registered before, the request will be ignored. |
| 14345 | * |
| 14346 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14347 | * allowed state changed. |
| 14348 | * @param callback The callback that was passed to |
| 14349 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14350 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14351 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14352 | */ |
| 14353 | @Override |
| 14354 | public void unregisterForCommunicationAllowedStateChanged( |
| 14355 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14356 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14357 | final long identity = Binder.clearCallingIdentity(); |
| 14358 | try { |
| 14359 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14360 | callback); |
| 14361 | } finally { |
| 14362 | Binder.restoreCallingIdentity(identity); |
| 14363 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14364 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14365 | |
| 14366 | /** |
| 14367 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14368 | * |
| 14369 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14370 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14371 | * if the request is successful or an error code if the request failed. |
| 14372 | * |
| 14373 | * @throws SecurityException if the caller doesn't have required permission. |
| 14374 | */ |
| 14375 | @Override |
| 14376 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14377 | enforceModifyPermission(); |
| 14378 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14379 | final long identity = Binder.clearCallingIdentity(); |
| 14380 | try { |
| 14381 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14382 | } finally { |
| 14383 | Binder.restoreCallingIdentity(identity); |
| 14384 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14385 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14386 | |
| 14387 | /** |
| 14388 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14389 | * |
| 14390 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14391 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14392 | * |
| 14393 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14394 | */ |
| 14395 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14396 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14397 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14398 | final long identity = Binder.clearCallingIdentity(); |
| 14399 | try { |
| 14400 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14401 | } finally { |
| 14402 | Binder.restoreCallingIdentity(identity); |
| 14403 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14404 | } |
| 14405 | |
| 14406 | /** |
| 14407 | * Deliver the list of provisioned satellite subscriber ids. |
| 14408 | * |
| 14409 | * @param list List of provisioned satellite subscriber ids. |
| 14410 | * @param result The result receiver that returns whether deliver success or fail. |
| 14411 | * |
| 14412 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14413 | */ |
| 14414 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14415 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14416 | @NonNull ResultReceiver result) { |
| 14417 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14418 | final long identity = Binder.clearCallingIdentity(); |
| 14419 | try { |
| 14420 | mSatelliteController.provisionSatellite(list, result); |
| 14421 | } finally { |
| 14422 | Binder.restoreCallingIdentity(identity); |
| 14423 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14424 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14425 | |
| 14426 | /** |
| 14427 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14428 | * value : |
| 14429 | * config_satellite_gateway_service_package and |
| 14430 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14431 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14432 | * subscriber informations. |
| 14433 | * |
| 14434 | * @param name the name is one of the following that constitute an intent. |
| 14435 | * Component package name, or component class name. |
| 14436 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14437 | */ |
| 14438 | @Override |
| 14439 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14440 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14441 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14442 | + " carrierRoamingNbIotNtn is disabled"); |
| 14443 | return false; |
| 14444 | } |
| 14445 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14446 | TelephonyPermissions.enforceShellOnly( |
| 14447 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14449 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14450 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14451 | final long identity = Binder.clearCallingIdentity(); |
| 14452 | try { |
| 14453 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14454 | } finally { |
| 14455 | Binder.restoreCallingIdentity(identity); |
| 14456 | } |
| 14457 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14458 | } |