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); |
| 2616 | mApp.startActivity(intent); |
| 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 |
| 2631 | // need to do a permission check since we're calling startActivity() |
| 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); |
| 2667 | mApp.startActivity(intent); |
| 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 | |
| 2997 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2998 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2999 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3000 | /* |
| 3001 | * If any of the Radios are available, it will need to be |
| 3002 | * shutdown. So return true if any Radio is available. |
| 3003 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3007 | Phone phone = PhoneFactory.getPhone(i); |
| 3008 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3009 | } |
| 3010 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3011 | return false; |
| 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3014 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3018 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | enforceModifyPermission(); |
| 3020 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3021 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3022 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3023 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3027 | logv("Shutting down Phone " + i); |
| 3028 | shutdownRadioUsingPhoneId(i); |
| 3029 | } |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3036 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3037 | if (phone != null && phone.isRadioAvailable()) { |
| 3038 | phone.shutdownRadio(); |
| 3039 | } |
| 3040 | } |
| 3041 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3042 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3045 | if (!turnOn) { |
| 3046 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3047 | } |
| 3048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3052 | if (defaultPhone != null) { |
| 3053 | defaultPhone.setRadioPower(turnOn); |
| 3054 | return true; |
| 3055 | } else { |
| 3056 | loge("There's no default phone."); |
| 3057 | return false; |
| 3058 | } |
| 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3061 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3064 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3065 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3066 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3067 | if (!turnOn) { |
| 3068 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3069 | + ",callingPackage=" + getCurrentPackageName()); |
| 3070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | final Phone phone = getPhone(subId); |
| 3074 | if (phone != null) { |
| 3075 | phone.setRadioPower(turnOn); |
| 3076 | return true; |
| 3077 | } else { |
| 3078 | return false; |
| 3079 | } |
| 3080 | } finally { |
| 3081 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3082 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3085 | /** |
| 3086 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3087 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3088 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3089 | * powering it off, and these radio off votes will be cleared. |
| 3090 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3091 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3092 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3093 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3094 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3095 | * check its vote. |
| 3096 | * |
| 3097 | * @param subId The subscription ID. |
| 3098 | * @param reason The reason for powering off radio. |
| 3099 | * @return true on success and false on failure. |
| 3100 | */ |
| 3101 | public boolean requestRadioPowerOffForReason(int subId, |
| 3102 | @TelephonyManager.RadioPowerReason int reason) { |
| 3103 | enforceModifyPermission(); |
| 3104 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3106 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3107 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3108 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3109 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3112 | boolean result = false; |
| 3113 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3114 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3115 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3116 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3117 | if (!result) { |
| 3118 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3119 | } |
| 3120 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3128 | * {@link requestRadioPowerOffForReason}. |
| 3129 | * |
| 3130 | * @param subId The subscription ID. |
| 3131 | * @param reason The reason for powering off radio. |
| 3132 | * @return true on success and false on failure. |
| 3133 | */ |
| 3134 | public boolean clearRadioPowerOffForReason(int subId, |
| 3135 | @TelephonyManager.RadioPowerReason int reason) { |
| 3136 | enforceModifyPermission(); |
| 3137 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3138 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3139 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3140 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3141 | final long identity = Binder.clearCallingIdentity(); |
| 3142 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3143 | boolean result = false; |
| 3144 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3145 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3146 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3147 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3148 | if (!result) { |
| 3149 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3150 | } |
| 3151 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3152 | } finally { |
| 3153 | Binder.restoreCallingIdentity(identity); |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | /** |
| 3158 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3159 | * |
| 3160 | * @param subId The subscription ID. |
| 3161 | * @param callingPackage The package making the call. |
| 3162 | * @param callingFeatureId The feature in the package. |
| 3163 | * @return List of reasons for powering off radio. |
| 3164 | */ |
| 3165 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3166 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3167 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3168 | enforceTelephonyFeatureWithException(callingPackage, |
| 3169 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3170 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | List result = new ArrayList(); |
| 3173 | try { |
| 3174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3175 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3176 | return result; |
| 3177 | } |
| 3178 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3179 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3180 | if (phone != null) { |
| 3181 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3182 | } else { |
| 3183 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3184 | } |
| 3185 | } finally { |
| 3186 | Binder.restoreCallingIdentity(identity); |
| 3187 | } |
| 3188 | return result; |
| 3189 | } |
| 3190 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3191 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3192 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3193 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3194 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3196 | enforceTelephonyFeatureWithException(callingPackage, |
| 3197 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3198 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3201 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3203 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3204 | phone.getDataSettingsManager().setDataEnabled( |
| 3205 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | return true; |
| 3207 | } else { |
| 3208 | return false; |
| 3209 | } |
| 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3215 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3216 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3217 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3219 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3220 | enforceTelephonyFeatureWithException(callingPackage, |
| 3221 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3225 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3227 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3228 | phone.getDataSettingsManager().setDataEnabled( |
| 3229 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | return true; |
| 3231 | } else { |
| 3232 | return false; |
| 3233 | } |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3239 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3240 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3241 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3242 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3244 | final long identity = Binder.clearCallingIdentity(); |
| 3245 | try { |
| 3246 | final Phone phone = getPhone(subId); |
| 3247 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3248 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | } else { |
| 3250 | return false; |
| 3251 | } |
| 3252 | } finally { |
| 3253 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3254 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3258 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3261 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3262 | enforceCallPermission(); |
| 3263 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3264 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3265 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3266 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | final long identity = Binder.clearCallingIdentity(); |
| 3268 | try { |
| 3269 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3270 | return; |
| 3271 | } |
| 3272 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3273 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3274 | } finally { |
| 3275 | Binder.restoreCallingIdentity(identity); |
| 3276 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3277 | }; |
| 3278 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3279 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3282 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3283 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3285 | final long identity = Binder.clearCallingIdentity(); |
| 3286 | try { |
| 3287 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3288 | return false; |
| 3289 | } |
| 3290 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3291 | } finally { |
| 3292 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3296 | /** |
| 3297 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3298 | * tag on getCallState Binder call. |
| 3299 | */ |
| 3300 | @Deprecated |
| 3301 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3303 | if (CompatChanges.isChangeEnabled( |
| 3304 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3305 | Binder.getCallingUid())) { |
| 3306 | // Do not allow this API to be called on API version 31+, it should only be |
| 3307 | // called on old apps using this Binder call directly. |
| 3308 | throw new SecurityException("This method can only be used for applications " |
| 3309 | + "targeting API version 30 or less."); |
| 3310 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3313 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3314 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(identity); |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | @Override |
| 3321 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3322 | if (CompatChanges.isChangeEnabled( |
| 3323 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3324 | Binder.getCallingUid())) { |
| 3325 | // Check READ_PHONE_STATE for API version 31+ |
| 3326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3327 | featureId, "getCallStateForSubscription")) { |
| 3328 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3329 | + "targeting API level 31+."); |
| 3330 | } |
| 3331 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3332 | |
| 3333 | enforceTelephonyFeatureWithException(callingPackage, |
| 3334 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3335 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3336 | final long identity = Binder.clearCallingIdentity(); |
| 3337 | try { |
| 3338 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3339 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3340 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
| 3343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3346 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3347 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3348 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | @Override |
| 3352 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3353 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3354 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3355 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 | final long identity = Binder.clearCallingIdentity(); |
| 3357 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3358 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3359 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3360 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | } else { |
| 3362 | return PhoneConstantConversions.convertDataState( |
| 3363 | PhoneConstants.DataState.DISCONNECTED); |
| 3364 | } |
| 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3370 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3371 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3372 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3376 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3377 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3378 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | final long identity = Binder.clearCallingIdentity(); |
| 3381 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3382 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3384 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3385 | } else { |
| 3386 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3387 | } |
| 3388 | } finally { |
| 3389 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3394 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3395 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3396 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3397 | |
| 3398 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3399 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3400 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3401 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3402 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3403 | .setCallingPid(Binder.getCallingPid()) |
| 3404 | .setCallingUid(Binder.getCallingUid()) |
| 3405 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3406 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3407 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3408 | .build()); |
| 3409 | switch (locationResult) { |
| 3410 | case DENIED_HARD: |
| 3411 | throw new SecurityException("Not allowed to access cell location"); |
| 3412 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3413 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3414 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3417 | enforceTelephonyFeatureWithException(callingPackage, |
| 3418 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3419 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3420 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3424 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3425 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
| 3428 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3432 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3433 | if (!mApp.getResources().getBoolean( |
| 3434 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3435 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3436 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3437 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3438 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3439 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3440 | // registered cell info, so return a NULL country instead. |
| 3441 | final long identity = Binder.clearCallingIdentity(); |
| 3442 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3443 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3444 | // Get default phone in this case. |
| 3445 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3446 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3447 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3449 | if (phone == null) return ""; |
| 3450 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3451 | if (sst == null) return ""; |
| 3452 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3453 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3454 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3455 | } finally { |
| 3456 | Binder.restoreCallingIdentity(identity); |
| 3457 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3460 | /** |
| 3461 | * This method was removed due to potential issues caused by performing partial |
| 3462 | * updates of service state, and lack of a credible use case. |
| 3463 | * |
| 3464 | * This has the ability to break the telephony implementation by disabling notification of |
| 3465 | * changes in device connectivity. DO NOT USE THIS! |
| 3466 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3467 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3468 | public void enableLocationUpdates() { |
| 3469 | mApp.enforceCallingOrSelfPermission( |
| 3470 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3473 | /** |
| 3474 | * This method was removed due to potential issues caused by performing partial |
| 3475 | * updates of service state, and lack of a credible use case. |
| 3476 | * |
| 3477 | * This has the ability to break the telephony implementation by disabling notification of |
| 3478 | * changes in device connectivity. DO NOT USE THIS! |
| 3479 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3480 | @Override |
| 3481 | public void disableLocationUpdates() { |
| 3482 | mApp.enforceCallingOrSelfPermission( |
| 3483 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | @Override |
| 3487 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3488 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3489 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3490 | try { |
| 3491 | mApp.getSystemService(AppOpsManager.class) |
| 3492 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3493 | } catch (SecurityException e) { |
| 3494 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3495 | throw e; |
| 3496 | } |
| 3497 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3498 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3499 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3500 | throw new SecurityException( |
| 3501 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3502 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3503 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3504 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3505 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3506 | return null; |
| 3507 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3508 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3509 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3510 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3511 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3512 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3513 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3514 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3515 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3517 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3518 | for (CellInfo ci : info) { |
| 3519 | if (ci instanceof CellInfoGsm) { |
| 3520 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3521 | } else if (ci instanceof CellInfoWcdma) { |
| 3522 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3525 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3528 | private List<CellInfo> getCachedCellInfo() { |
| 3529 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3530 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3531 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3532 | if (info != null) cellInfos.addAll(info); |
| 3533 | } |
| 3534 | return cellInfos; |
| 3535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3536 | |
| 3537 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3538 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3539 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3540 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3541 | |
| 3542 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3543 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3544 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3545 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3546 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3547 | .setCallingPid(Binder.getCallingPid()) |
| 3548 | .setCallingUid(Binder.getCallingUid()) |
| 3549 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3550 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3551 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3552 | .build()); |
| 3553 | switch (locationResult) { |
| 3554 | case DENIED_HARD: |
| 3555 | throw new SecurityException("Not allowed to access cell info"); |
| 3556 | case DENIED_SOFT: |
| 3557 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3560 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3561 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3562 | return getCachedCellInfo(); |
| 3563 | } |
| 3564 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3565 | enforceTelephonyFeatureWithException(callingPackage, |
| 3566 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3567 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3568 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3569 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3570 | final long identity = Binder.clearCallingIdentity(); |
| 3571 | try { |
| 3572 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3573 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3574 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3575 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3576 | if (info != null) cellInfos.addAll(info); |
| 3577 | } |
| 3578 | return cellInfos; |
| 3579 | } finally { |
| 3580 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3584 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3585 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3586 | String callingFeatureId) { |
| 3587 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3588 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3592 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3593 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3594 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3595 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3598 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3599 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3600 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3601 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3602 | |
| 3603 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3604 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3605 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3606 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3607 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3608 | .setCallingPid(Binder.getCallingPid()) |
| 3609 | .setCallingUid(Binder.getCallingUid()) |
| 3610 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3611 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3612 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3613 | .build()); |
| 3614 | switch (locationResult) { |
| 3615 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3616 | if (TelephonyPermissions |
| 3617 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3618 | // Safetynet logging for b/154934934 |
| 3619 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3620 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3621 | throw new SecurityException("Not allowed to access cell info"); |
| 3622 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3623 | if (TelephonyPermissions |
| 3624 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3625 | // Safetynet logging for b/154934934 |
| 3626 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3627 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3628 | try { |
| 3629 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3630 | } catch (RemoteException re) { |
| 3631 | // Drop without consequences |
| 3632 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3633 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3636 | enforceTelephonyFeatureWithException(callingPackage, |
| 3637 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3638 | |
| 3639 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3640 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3641 | |
| 3642 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3643 | } |
| 3644 | |
| 3645 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3646 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3647 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3648 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | |
| 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3652 | Phone phone = getPhone(subId); |
| 3653 | if (phone == null) { |
| 3654 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3655 | } else { |
| 3656 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3663 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3664 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3665 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3666 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3667 | return null; |
| 3668 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3669 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3670 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3671 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3672 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3673 | return null; |
| 3674 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3676 | enforceTelephonyFeatureWithException(callingPackage, |
| 3677 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3679 | final long identity = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | return phone.getImei(); |
| 3682 | } finally { |
| 3683 | Binder.restoreCallingIdentity(identity); |
| 3684 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3688 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3689 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3690 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3691 | callingFeatureId, "getPrimaryImei")) { |
| 3692 | throw new SecurityException("Caller does not have permission"); |
| 3693 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3694 | |
| 3695 | enforceTelephonyFeatureWithException(callingPackage, |
| 3696 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3697 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3701 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3702 | return phone.getImei(); |
| 3703 | } |
| 3704 | } |
| 3705 | throw new UnsupportedOperationException("Operation not supported"); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3712 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3713 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3714 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3715 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3716 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3717 | String tac = null; |
| 3718 | if (phone != null) { |
| 3719 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3720 | try { |
| 3721 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3722 | } catch (IndexOutOfBoundsException e) { |
| 3723 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3724 | return null; |
| 3725 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3726 | } |
| 3727 | return tac; |
| 3728 | } |
| 3729 | |
| 3730 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3731 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3732 | try { |
| 3733 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3734 | } catch (SecurityException se) { |
| 3735 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3736 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3737 | + Binder.getCallingUid()); |
| 3738 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3739 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3740 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3741 | return null; |
| 3742 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3744 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3745 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3746 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3747 | return null; |
| 3748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3749 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3750 | enforceTelephonyFeatureWithException(callingPackage, |
| 3751 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | final long identity = Binder.clearCallingIdentity(); |
| 3754 | try { |
| 3755 | return phone.getMeid(); |
| 3756 | } finally { |
| 3757 | Binder.restoreCallingIdentity(identity); |
| 3758 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3762 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3763 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3764 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3765 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3766 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3767 | String manufacturerCode = null; |
| 3768 | if (phone != null) { |
| 3769 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3770 | try { |
| 3771 | manufacturerCode = |
| 3772 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3773 | } catch (IndexOutOfBoundsException e) { |
| 3774 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3775 | return null; |
| 3776 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3777 | } |
| 3778 | return manufacturerCode; |
| 3779 | } |
| 3780 | |
| 3781 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3782 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3783 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3784 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3785 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3786 | return null; |
| 3787 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3788 | int subId = phone.getSubId(); |
| 3789 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3790 | mApp, subId, callingPackage, callingFeatureId, |
| 3791 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3792 | return null; |
| 3793 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3795 | enforceTelephonyFeatureWithException(callingPackage, |
| 3796 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3797 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | return phone.getDeviceSvn(); |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
| 3803 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3806 | @Override |
| 3807 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3808 | if (!mApp.getResources().getBoolean( |
| 3809 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3810 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3811 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3812 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | final Phone phone = getPhone(subId); |
| 3817 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
| 3820 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | @Override |
| 3824 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3825 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3826 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3827 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3828 | final long identity = Binder.clearCallingIdentity(); |
| 3829 | try { |
| 3830 | final Phone phone = getPhone(subId); |
| 3831 | return phone == null ? null : phone.getCarrierName(); |
| 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
| 3834 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3835 | } |
| 3836 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3837 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3838 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3839 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3840 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3841 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3842 | final long identity = Binder.clearCallingIdentity(); |
| 3843 | try { |
| 3844 | final Phone phone = getPhone(subId); |
| 3845 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3846 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3847 | } finally { |
| 3848 | Binder.restoreCallingIdentity(identity); |
| 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3853 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3854 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3855 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3856 | "getSubscriptionSpecificCarrierName"); |
| 3857 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3858 | final long identity = Binder.clearCallingIdentity(); |
| 3859 | try { |
| 3860 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3861 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
| 3864 | } |
| 3865 | } |
| 3866 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3867 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3868 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3869 | if (!isSubscriptionMccMnc) { |
| 3870 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3871 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3872 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3873 | if (phone == null) { |
| 3874 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3875 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3876 | |
| 3877 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3878 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3879 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3880 | final long identity = Binder.clearCallingIdentity(); |
| 3881 | try { |
| 3882 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3883 | } finally { |
| 3884 | Binder.restoreCallingIdentity(identity); |
| 3885 | } |
| 3886 | } |
| 3887 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3888 | // |
| 3889 | // Internal helper methods. |
| 3890 | // |
| 3891 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3892 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3893 | * Make sure the caller is the calling package itself |
| 3894 | * |
| 3895 | * @throws SecurityException if the caller is not the calling package |
| 3896 | */ |
| 3897 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3898 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3899 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3900 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3901 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3902 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3903 | } catch (PackageManager.NameNotFoundException e) { |
| 3904 | // packageUid is -1 |
| 3905 | } |
| 3906 | if (packageUid != callingUid) { |
| 3907 | throw new SecurityException(message + ": Package " + callingPackage |
| 3908 | + " does not belong to " + callingUid); |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3913 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3914 | * |
| 3915 | * @throws SecurityException if the caller does not have the required permission |
| 3916 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3917 | @VisibleForTesting |
| 3918 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3919 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3920 | } |
| 3921 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3922 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3923 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3924 | * |
| 3925 | * @throws SecurityException if the caller does not have the required permission |
| 3926 | */ |
| 3927 | @VisibleForTesting |
| 3928 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3929 | enforceReadPermission(null); |
| 3930 | } |
| 3931 | |
| 3932 | /** |
| 3933 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3934 | * |
| 3935 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3936 | */ |
| 3937 | @VisibleForTesting |
| 3938 | public void enforceReadPermission(String msg) { |
| 3939 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3942 | private void enforceActiveEmergencySessionPermission() { |
| 3943 | mApp.enforceCallingOrSelfPermission( |
| 3944 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3945 | } |
| 3946 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3947 | /** |
| 3948 | * Make sure the caller has the CALL_PHONE permission. |
| 3949 | * |
| 3950 | * @throws SecurityException if the caller does not have the required permission |
| 3951 | */ |
| 3952 | private void enforceCallPermission() { |
| 3953 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3954 | } |
| 3955 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3956 | private void enforceSettingsPermission() { |
| 3957 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3960 | private void enforceRebootPermission() { |
| 3961 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3962 | } |
| 3963 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3964 | /** |
| 3965 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3966 | * @param message - log message to print. |
| 3967 | * @throws SecurityException if the caller does not have the required permission |
| 3968 | */ |
| 3969 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3970 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3971 | } |
| 3972 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3973 | /** |
| 3974 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3975 | * @param message - log message to print. |
| 3976 | * @throws SecurityException if the caller does not have the required permission |
| 3977 | */ |
| 3978 | private void enforcePackageUsageStatsPermission(String message) { |
| 3979 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3980 | } |
| 3981 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3982 | private String createTelUrl(String number) { |
| 3983 | if (TextUtils.isEmpty(number)) { |
| 3984 | return null; |
| 3985 | } |
| 3986 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3987 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3990 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3991 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3994 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3995 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3998 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3999 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4002 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4003 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4004 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4007 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4008 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4009 | if (!mApp.getResources().getBoolean( |
| 4010 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4011 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4012 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4013 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | final long identity = Binder.clearCallingIdentity(); |
| 4016 | try { |
| 4017 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4018 | if (phone == null) { |
| 4019 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4020 | } else { |
| 4021 | return phone.getPhoneType(); |
| 4022 | } |
| 4023 | } finally { |
| 4024 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4025 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | /** |
| 4029 | * Returns the CDMA ERI icon index to display |
| 4030 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4031 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4032 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4033 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4034 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4037 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4038 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4039 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4040 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4041 | mApp, subId, callingPackage, callingFeatureId, |
| 4042 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4043 | return -1; |
| 4044 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4045 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4046 | enforceTelephonyFeatureWithException(callingPackage, |
| 4047 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4048 | "getCdmaEriIconIndexForSubscriber"); |
| 4049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | final long identity = Binder.clearCallingIdentity(); |
| 4051 | try { |
| 4052 | final Phone phone = getPhone(subId); |
| 4053 | if (phone != null) { |
| 4054 | return phone.getCdmaEriIconIndex(); |
| 4055 | } else { |
| 4056 | return -1; |
| 4057 | } |
| 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4060 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | /** |
| 4064 | * Returns the CDMA ERI icon mode, |
| 4065 | * 0 - ON |
| 4066 | * 1 - FLASHING |
| 4067 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4068 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4069 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4070 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4071 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4074 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4075 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4076 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4077 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4078 | mApp, subId, callingPackage, callingFeatureId, |
| 4079 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4080 | return -1; |
| 4081 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | |
| 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | final Phone phone = getPhone(subId); |
| 4086 | if (phone != null) { |
| 4087 | return phone.getCdmaEriIconMode(); |
| 4088 | } else { |
| 4089 | return -1; |
| 4090 | } |
| 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /** |
| 4097 | * Returns the CDMA ERI text, |
| 4098 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4099 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4100 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4101 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4102 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4105 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4106 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4107 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4108 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4109 | mApp, subId, callingPackage, callingFeatureId, |
| 4110 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4111 | return null; |
| 4112 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4113 | |
| 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | final Phone phone = getPhone(subId); |
| 4117 | if (phone != null) { |
| 4118 | return phone.getCdmaEriText(); |
| 4119 | } else { |
| 4120 | return null; |
| 4121 | } |
| 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4128 | * Returns the CDMA MDN. |
| 4129 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4130 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4131 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4133 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4135 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4136 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4138 | final long identity = Binder.clearCallingIdentity(); |
| 4139 | try { |
| 4140 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | return phone.getLine1Number(); |
| 4143 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4145 | return null; |
| 4146 | } |
| 4147 | } finally { |
| 4148 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | /** |
| 4153 | * Returns the CDMA MIN. |
| 4154 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4155 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4156 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4158 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4160 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4161 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
| 4165 | final Phone phone = getPhone(subId); |
| 4166 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4167 | return phone.getCdmaMin(); |
| 4168 | } else { |
| 4169 | return null; |
| 4170 | } |
| 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4173 | } |
| 4174 | } |
| 4175 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4176 | @Override |
| 4177 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4178 | INumberVerificationCallback callback, String callingPackage) { |
| 4179 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4180 | != PERMISSION_GRANTED) { |
| 4181 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4182 | } |
| 4183 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4184 | |
| 4185 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4186 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4187 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4188 | + "calling package: " + callingPackage |
| 4189 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4192 | enforceTelephonyFeatureWithException(callingPackage, |
| 4193 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4194 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4195 | if (range == null) { |
| 4196 | throw new NullPointerException("Range must be non-null"); |
| 4197 | } |
| 4198 | |
| 4199 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4200 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4201 | |
| 4202 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4203 | } |
| 4204 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4205 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4206 | * Returns true if CDMA provisioning needs to run. |
| 4207 | */ |
| 4208 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4209 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4210 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4211 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | final long identity = Binder.clearCallingIdentity(); |
| 4213 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4214 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
| 4217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4221 | * Sets the voice mail number of a given subId. |
| 4222 | */ |
| 4223 | @Override |
| 4224 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4225 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4226 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4227 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4228 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4229 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4234 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4235 | return success; |
| 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(identity); |
| 4238 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4239 | } |
| 4240 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4241 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4242 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4243 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4244 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4245 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4246 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4247 | throw new SecurityException("caller must be system dialer"); |
| 4248 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4250 | enforceTelephonyFeatureWithException(callingPackage, |
| 4251 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4252 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | final long identity = Binder.clearCallingIdentity(); |
| 4254 | try { |
| 4255 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4256 | if (phoneAccountHandle == null) { |
| 4257 | return null; |
| 4258 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4259 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4262 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4266 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4267 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4268 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4269 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4270 | mApp, subId, callingPackage, callingFeatureId, |
| 4271 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4272 | return null; |
| 4273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4274 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4275 | enforceTelephonyFeatureWithException(callingPackage, |
| 4276 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4277 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4278 | final long identity = Binder.clearCallingIdentity(); |
| 4279 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4280 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4281 | } finally { |
| 4282 | Binder.restoreCallingIdentity(identity); |
| 4283 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4287 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4288 | VisualVoicemailSmsFilterSettings settings) { |
| 4289 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4290 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4291 | enforceTelephonyFeatureWithException(callingPackage, |
| 4292 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4293 | final long identity = Binder.clearCallingIdentity(); |
| 4294 | try { |
| 4295 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4296 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(identity); |
| 4299 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4303 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4304 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4305 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4306 | enforceTelephonyFeatureWithException(callingPackage, |
| 4307 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4312 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(identity); |
| 4315 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4319 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4320 | String callingPackage, int subId) { |
| 4321 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | |
| 4323 | final long identity = Binder.clearCallingIdentity(); |
| 4324 | try { |
| 4325 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4326 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | } finally { |
| 4328 | Binder.restoreCallingIdentity(identity); |
| 4329 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4333 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4334 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | |
| 4336 | final long identity = Binder.clearCallingIdentity(); |
| 4337 | try { |
| 4338 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4339 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4340 | } finally { |
| 4341 | Binder.restoreCallingIdentity(identity); |
| 4342 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4346 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4347 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4348 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4349 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4350 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4351 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4352 | |
| 4353 | enforceTelephonyFeatureWithException(callingPackage, |
| 4354 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4355 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4356 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4357 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4358 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4359 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4360 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4361 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4362 | * Sets the voice activation state of a given subId. |
| 4363 | */ |
| 4364 | @Override |
| 4365 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4367 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4368 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4369 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4370 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | final long identity = Binder.clearCallingIdentity(); |
| 4373 | try { |
| 4374 | final Phone phone = getPhone(subId); |
| 4375 | if (phone != null) { |
| 4376 | phone.setVoiceActivationState(activationState); |
| 4377 | } else { |
| 4378 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4379 | } |
| 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | /** |
| 4386 | * Sets the data activation state of a given subId. |
| 4387 | */ |
| 4388 | @Override |
| 4389 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4391 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4393 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4394 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4395 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 | final long identity = Binder.clearCallingIdentity(); |
| 4397 | try { |
| 4398 | final Phone phone = getPhone(subId); |
| 4399 | if (phone != null) { |
| 4400 | phone.setDataActivationState(activationState); |
| 4401 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4402 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | } |
| 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | /** |
| 4410 | * Returns the voice activation state of a given subId. |
| 4411 | */ |
| 4412 | @Override |
| 4413 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4414 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4415 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4416 | enforceTelephonyFeatureWithException(callingPackage, |
| 4417 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4418 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4419 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | final long identity = Binder.clearCallingIdentity(); |
| 4421 | try { |
| 4422 | if (phone != null) { |
| 4423 | return phone.getVoiceActivationState(); |
| 4424 | } else { |
| 4425 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4426 | } |
| 4427 | } finally { |
| 4428 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | /** |
| 4433 | * Returns the data activation state of a given subId. |
| 4434 | */ |
| 4435 | @Override |
| 4436 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4437 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4439 | enforceTelephonyFeatureWithException(callingPackage, |
| 4440 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4441 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4442 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | if (phone != null) { |
| 4446 | return phone.getDataActivationState(); |
| 4447 | } else { |
| 4448 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4449 | } |
| 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4456 | * Returns the unread count of voicemails for a subId |
| 4457 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4458 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4459 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4460 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4461 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4462 | mApp, subId, callingPackage, callingFeatureId, |
| 4463 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4464 | return 0; |
| 4465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4466 | final long identity = Binder.clearCallingIdentity(); |
| 4467 | try { |
| 4468 | final Phone phone = getPhone(subId); |
| 4469 | if (phone != null) { |
| 4470 | return phone.getVoiceMessageCount(); |
| 4471 | } else { |
| 4472 | return 0; |
| 4473 | } |
| 4474 | } finally { |
| 4475 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4480 | * returns true, if the device is in a state where both voice and data |
| 4481 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4482 | */ |
| 4483 | @Override |
| 4484 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4485 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4486 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4487 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4488 | final long identity = Binder.clearCallingIdentity(); |
| 4489 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4490 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4497 | * Send the dialer code if called from the current default dialer or the caller has |
| 4498 | * carrier privilege. |
| 4499 | * @param inputCode The dialer code to send |
| 4500 | */ |
| 4501 | @Override |
| 4502 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4503 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4504 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4505 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4506 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4507 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4508 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4509 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4510 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4511 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4512 | enforceTelephonyFeatureWithException(callingPackage, |
| 4513 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4514 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4517 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4521 | } |
| 4522 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4523 | @Override |
| 4524 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4525 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4526 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4527 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4528 | |
| 4529 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4530 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4531 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
| 4534 | if (!isActiveSubscription(subId)) { |
| 4535 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4536 | } |
| 4537 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4538 | } finally { |
| 4539 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4540 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4541 | } |
| 4542 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4543 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4544 | public boolean isInEmergencySmsMode() { |
| 4545 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4546 | |
| 4547 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4548 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4549 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4550 | final long identity = Binder.clearCallingIdentity(); |
| 4551 | try { |
| 4552 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4553 | if (phone.isInEmergencySmsMode()) { |
| 4554 | return true; |
| 4555 | } |
| 4556 | } |
| 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(identity); |
| 4559 | } |
| 4560 | return false; |
| 4561 | } |
| 4562 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4563 | /** |
| 4564 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4565 | * @param subId The subscription to use to check the configuration. |
| 4566 | * @param c The callback that will be used to send the result. |
| 4567 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4568 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4569 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4570 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4571 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4572 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4573 | |
| 4574 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4575 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4576 | "IMS not available on device."); |
| 4577 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4578 | final long token = Binder.clearCallingIdentity(); |
| 4579 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4580 | int slotId = getSlotIndexOrException(subId); |
| 4581 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4582 | |
| 4583 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4584 | if (controller != null) { |
| 4585 | ImsManager imsManager = controller.getImsManager(subId); |
| 4586 | if (imsManager != null) { |
| 4587 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4588 | } else { |
| 4589 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4590 | } |
| 4591 | } else { |
| 4592 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4593 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4594 | } catch (ImsException e) { |
| 4595 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(token); |
| 4598 | } |
| 4599 | } |
| 4600 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4601 | /** |
| 4602 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4603 | * @param subId The subscription to use to check the configuration. |
| 4604 | * @param c The callback that will be used to send the result. |
| 4605 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4606 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4607 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4608 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4609 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4610 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4611 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4612 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4613 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4614 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4615 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4616 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4617 | if (controller != null) { |
| 4618 | ImsManager imsManager = controller.getImsManager(subId); |
| 4619 | if (imsManager != null) { |
| 4620 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4621 | } else { |
| 4622 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4623 | + "is inactive, ignoring unregister."); |
| 4624 | // If the ImsManager is not valid, just return, since the callback |
| 4625 | // will already have been removed internally. |
| 4626 | } |
| 4627 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(token); |
| 4630 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | } |
| 4632 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4633 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4634 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4635 | * @param subId The subscription to use to check the configuration. |
| 4636 | * @param c The callback that will be used to send the result. |
| 4637 | */ |
| 4638 | @Override |
| 4639 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4640 | throws RemoteException { |
| 4641 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4642 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4643 | |
| 4644 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4645 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4646 | "IMS not available on device."); |
| 4647 | } |
| 4648 | final long token = Binder.clearCallingIdentity(); |
| 4649 | try { |
| 4650 | int slotId = getSlotIndexOrException(subId); |
| 4651 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4652 | |
| 4653 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4654 | if (controller != null) { |
| 4655 | ImsManager imsManager = controller.getImsManager(subId); |
| 4656 | if (imsManager != null) { |
| 4657 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4658 | } else { |
| 4659 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4660 | } |
| 4661 | } else { |
| 4662 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4663 | } |
| 4664 | } catch (ImsException e) { |
| 4665 | throw new ServiceSpecificException(e.getCode()); |
| 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(token); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | /** |
| 4672 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4673 | * @param subId The subscription to use to check the configuration. |
| 4674 | * @param c The callback that will be used to send the result. |
| 4675 | */ |
| 4676 | @Override |
| 4677 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4678 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4679 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4680 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4681 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4682 | } |
| 4683 | final long token = Binder.clearCallingIdentity(); |
| 4684 | |
| 4685 | try { |
| 4686 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4687 | if (controller != null) { |
| 4688 | ImsManager imsManager = controller.getImsManager(subId); |
| 4689 | if (imsManager != null) { |
| 4690 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4691 | } else { |
| 4692 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4693 | + "is inactive, ignoring unregister."); |
| 4694 | // If the ImsManager is not valid, just return, since the callback |
| 4695 | // will already have been removed internally. |
| 4696 | } |
| 4697 | } |
| 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(token); |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4704 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4705 | */ |
| 4706 | @Override |
| 4707 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4708 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4709 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4710 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4711 | "IMS not available on device."); |
| 4712 | } |
| 4713 | final long token = Binder.clearCallingIdentity(); |
| 4714 | try { |
| 4715 | Phone phone = getPhone(subId); |
| 4716 | if (phone == null) { |
| 4717 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4718 | + subId + "'"); |
| 4719 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4720 | } |
| 4721 | phone.getImsRegistrationState(regState -> { |
| 4722 | try { |
| 4723 | consumer.accept((regState == null) |
| 4724 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4725 | } catch (RemoteException e) { |
| 4726 | // Ignore if the remote process is no longer available to call back. |
| 4727 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4728 | } |
| 4729 | }); |
| 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(token); |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * Get the transport type for the IMS service registration state. |
| 4737 | */ |
| 4738 | @Override |
| 4739 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4740 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4741 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4742 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4743 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4744 | "IMS not available on device."); |
| 4745 | } |
| 4746 | final long token = Binder.clearCallingIdentity(); |
| 4747 | try { |
| 4748 | Phone phone = getPhone(subId); |
| 4749 | if (phone == null) { |
| 4750 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4751 | + subId + "'"); |
| 4752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4753 | } |
| 4754 | phone.getImsRegistrationTech(regTech -> { |
| 4755 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4756 | int regTechConverted = (regTech == null) |
| 4757 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4758 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4759 | regTechConverted); |
| 4760 | try { |
| 4761 | consumer.accept(regTechConverted); |
| 4762 | } catch (RemoteException e) { |
| 4763 | // Ignore if the remote process is no longer available to call back. |
| 4764 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4765 | } |
| 4766 | }); |
| 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(token); |
| 4769 | } |
| 4770 | } |
| 4771 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4772 | /** |
| 4773 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4774 | * @param subId The subscription to use to check the configuration. |
| 4775 | * @param c The callback that will be used to send the result. |
| 4776 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4777 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4778 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4779 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4780 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4781 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4782 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4783 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4784 | "IMS not available on device."); |
| 4785 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | final long token = Binder.clearCallingIdentity(); |
| 4787 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4788 | int slotId = getSlotIndexOrException(subId); |
| 4789 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4790 | |
| 4791 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4792 | if (controller != null) { |
| 4793 | ImsManager imsManager = controller.getImsManager(subId); |
| 4794 | if (imsManager != null) { |
| 4795 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4796 | } else { |
| 4797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4798 | } |
| 4799 | } else { |
| 4800 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4801 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4802 | } catch (ImsException e) { |
| 4803 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4804 | } finally { |
| 4805 | Binder.restoreCallingIdentity(token); |
| 4806 | } |
| 4807 | } |
| 4808 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4809 | /** |
| 4810 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4811 | * @param subId The subscription to use to check the configuration. |
| 4812 | * @param c The callback that will be used to send the result. |
| 4813 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4814 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4815 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4816 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4817 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4818 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4819 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4820 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4821 | |
| 4822 | final long token = Binder.clearCallingIdentity(); |
| 4823 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4824 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4825 | if (controller != null) { |
| 4826 | ImsManager imsManager = controller.getImsManager(subId); |
| 4827 | if (imsManager != null) { |
| 4828 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4829 | } else { |
| 4830 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4831 | + " is inactive, ignoring unregister."); |
| 4832 | // If the ImsManager is not valid, just return, since the callback |
| 4833 | // will already have been removed internally. |
| 4834 | } |
| 4835 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4836 | } finally { |
| 4837 | Binder.restoreCallingIdentity(token); |
| 4838 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4842 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4843 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4844 | |
| 4845 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4846 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4847 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4848 | final long token = Binder.clearCallingIdentity(); |
| 4849 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4850 | int slotId = getSlotIndexOrException(subId); |
| 4851 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4852 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4853 | } catch (com.android.ims.ImsException e) { |
| 4854 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4855 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4856 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4857 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4858 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4859 | } finally { |
| 4860 | Binder.restoreCallingIdentity(token); |
| 4861 | } |
| 4862 | } |
| 4863 | |
| 4864 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4865 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4866 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4867 | |
| 4868 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4869 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4870 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4871 | final long token = Binder.clearCallingIdentity(); |
| 4872 | try { |
| 4873 | Phone phone = getPhone(subId); |
| 4874 | if (phone == null) return false; |
| 4875 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4876 | } catch (com.android.ims.ImsException e) { |
| 4877 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4878 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4879 | } finally { |
| 4880 | Binder.restoreCallingIdentity(token); |
| 4881 | } |
| 4882 | } |
| 4883 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4884 | /** |
| 4885 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4886 | * subscription. |
| 4887 | * @param subId The subscription to use to check the configuration. |
| 4888 | * @param callback The callback that will be used to send the result. |
| 4889 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4890 | * @param transportType The transport type of the MmTelFeature capability. |
| 4891 | */ |
| 4892 | @Override |
| 4893 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4894 | int transportType) { |
| 4895 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4896 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4897 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4898 | "IMS not available on device."); |
| 4899 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4900 | final long token = Binder.clearCallingIdentity(); |
| 4901 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4902 | int slotId = getSlotIndex(subId); |
| 4903 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4904 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4905 | + subId + "'"); |
| 4906 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4907 | } |
| 4908 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4909 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4910 | transportType, aBoolean -> { |
| 4911 | try { |
| 4912 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4913 | } catch (RemoteException e) { |
| 4914 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4915 | + "running. Ignore"); |
| 4916 | } |
| 4917 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4918 | } catch (ImsException e) { |
| 4919 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(token); |
| 4922 | } |
| 4923 | } |
| 4924 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4925 | /** |
| 4926 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4927 | * @param subId The subscription to use to check the configuration. |
| 4928 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4929 | @Override |
| 4930 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4931 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4932 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4933 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4934 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4935 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4936 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4937 | final long token = Binder.clearCallingIdentity(); |
| 4938 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4939 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4940 | // 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] | 4941 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4942 | } catch (ImsException e) { |
| 4943 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4944 | } finally { |
| 4945 | Binder.restoreCallingIdentity(token); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4950 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4952 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4953 | |
| 4954 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4955 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4956 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | final long identity = Binder.clearCallingIdentity(); |
| 4958 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4959 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4960 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4961 | // 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] | 4962 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4963 | } catch (ImsException e) { |
| 4964 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4965 | } finally { |
| 4966 | Binder.restoreCallingIdentity(identity); |
| 4967 | } |
| 4968 | } |
| 4969 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4970 | /** |
| 4971 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4972 | * @param subId The subscription to use to check the configuration. |
| 4973 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4974 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4975 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4976 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4977 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4978 | |
| 4979 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4980 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4981 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4984 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4985 | // 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] | 4986 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4987 | } catch (ImsException e) { |
| 4988 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4989 | } finally { |
| 4990 | Binder.restoreCallingIdentity(identity); |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4995 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4996 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4997 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4998 | |
| 4999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5000 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5001 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5004 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5005 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5006 | // 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] | 5007 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5008 | } catch (ImsException e) { |
| 5009 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5010 | } finally { |
| 5011 | Binder.restoreCallingIdentity(identity); |
| 5012 | } |
| 5013 | } |
| 5014 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5015 | /** |
| 5016 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5017 | * @param subId The subscription to use to check the configuration. |
| 5018 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5019 | @Override |
| 5020 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5021 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5022 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5023 | |
| 5024 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5025 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5026 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5027 | final long identity = Binder.clearCallingIdentity(); |
| 5028 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5029 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5030 | // 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] | 5031 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5032 | } catch (ImsException e) { |
| 5033 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5034 | } finally { |
| 5035 | Binder.restoreCallingIdentity(identity); |
| 5036 | } |
| 5037 | } |
| 5038 | |
| 5039 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5040 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5042 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5043 | |
| 5044 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5045 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5046 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5047 | final long identity = Binder.clearCallingIdentity(); |
| 5048 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5049 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5050 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5051 | // 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] | 5052 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5053 | } catch (ImsException e) { |
| 5054 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5055 | } finally { |
| 5056 | Binder.restoreCallingIdentity(identity); |
| 5057 | } |
| 5058 | } |
| 5059 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5060 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5061 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5062 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5063 | * @param subId The subscription to use to check the configuration. |
| 5064 | */ |
| 5065 | @Override |
| 5066 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5068 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5069 | |
| 5070 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5071 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5072 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5073 | final long identity = Binder.clearCallingIdentity(); |
| 5074 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5075 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5076 | // 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] | 5077 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5078 | } catch (ImsException e) { |
| 5079 | throw new ServiceSpecificException(e.getCode()); |
| 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | /** |
| 5086 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5087 | * Requires MODIFY_PHONE_STATE permission. |
| 5088 | * @param subId The subscription to use to check the configuration. |
| 5089 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5090 | * false otherwise |
| 5091 | */ |
| 5092 | @Override |
| 5093 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5095 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5096 | |
| 5097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5098 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5099 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5100 | final long identity = Binder.clearCallingIdentity(); |
| 5101 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5102 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5103 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5104 | // 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] | 5105 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5106 | } catch (ImsException e) { |
| 5107 | throw new ServiceSpecificException(e.getCode()); |
| 5108 | } finally { |
| 5109 | Binder.restoreCallingIdentity(identity); |
| 5110 | } |
| 5111 | } |
| 5112 | |
| 5113 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5114 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5115 | * @param subId The subscription to use to check the configuration. |
| 5116 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5117 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5118 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5119 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5120 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5121 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5122 | |
| 5123 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5124 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5125 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5126 | final long identity = Binder.clearCallingIdentity(); |
| 5127 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5128 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5129 | // 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] | 5130 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5131 | } catch (ImsException e) { |
| 5132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5133 | } finally { |
| 5134 | Binder.restoreCallingIdentity(identity); |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5139 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5141 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5142 | |
| 5143 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5144 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5145 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5148 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5149 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5150 | // 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] | 5151 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5152 | } catch (ImsException e) { |
| 5153 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | @Override |
| 5160 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5162 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5163 | |
| 5164 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5165 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5166 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5167 | final long identity = Binder.clearCallingIdentity(); |
| 5168 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5169 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5170 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5171 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5172 | } catch (ImsException e) { |
| 5173 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
| 5177 | } |
| 5178 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5179 | /** |
| 5180 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5181 | * @param subId The subscription to use to check the configuration. |
| 5182 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5183 | @Override |
| 5184 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5185 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5186 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5187 | |
| 5188 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5189 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5190 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5191 | final long identity = Binder.clearCallingIdentity(); |
| 5192 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5193 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5194 | // 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] | 5195 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5196 | } catch (ImsException e) { |
| 5197 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
| 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | @Override |
| 5204 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5206 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5207 | |
| 5208 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5209 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5210 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5211 | final long identity = Binder.clearCallingIdentity(); |
| 5212 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5213 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5214 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5215 | // 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] | 5216 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5217 | } catch (ImsException e) { |
| 5218 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5219 | } finally { |
| 5220 | Binder.restoreCallingIdentity(identity); |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | @Override |
| 5225 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5226 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5227 | |
| 5228 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5229 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5230 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5233 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5234 | // 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] | 5235 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5236 | } catch (ImsException e) { |
| 5237 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5238 | } finally { |
| 5239 | Binder.restoreCallingIdentity(identity); |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | @Override |
| 5244 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5246 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5247 | |
| 5248 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5249 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5250 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5253 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5254 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5255 | // 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] | 5256 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5257 | } catch (ImsException e) { |
| 5258 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5259 | } finally { |
| 5260 | Binder.restoreCallingIdentity(identity); |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | @Override |
| 5265 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5267 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5268 | |
| 5269 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5270 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5271 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5272 | final long identity = Binder.clearCallingIdentity(); |
| 5273 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5274 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5275 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5276 | // 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] | 5277 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5278 | } catch (ImsException e) { |
| 5279 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
| 5282 | } |
| 5283 | } |
| 5284 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5285 | /** |
| 5286 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5287 | * @param subId The subscription to use to check the configuration. |
| 5288 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5289 | @Override |
| 5290 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5291 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5292 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5293 | |
| 5294 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5295 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5296 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5297 | final long identity = Binder.clearCallingIdentity(); |
| 5298 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5299 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5300 | // 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] | 5301 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5302 | } catch (ImsException e) { |
| 5303 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5304 | } finally { |
| 5305 | Binder.restoreCallingIdentity(identity); |
| 5306 | } |
| 5307 | } |
| 5308 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5309 | @Override |
| 5310 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5311 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5312 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5315 | if (!isImsAvailableOnDevice()) { |
| 5316 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5317 | "IMS not available on device."); |
| 5318 | } |
| 5319 | int slotId = getSlotIndexOrException(subId); |
| 5320 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5321 | |
| 5322 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5323 | if (controller != null) { |
| 5324 | ImsManager imsManager = controller.getImsManager(subId); |
| 5325 | if (imsManager != null) { |
| 5326 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5327 | } else { |
| 5328 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5329 | } |
| 5330 | } else { |
| 5331 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5332 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5333 | } catch (ImsException e) { |
| 5334 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
| 5337 | } |
| 5338 | } |
| 5339 | |
| 5340 | @Override |
| 5341 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5342 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5343 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5344 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5345 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5346 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5347 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5348 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5349 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5350 | if (controller != null) { |
| 5351 | ImsManager imsManager = controller.getImsManager(subId); |
| 5352 | if (imsManager != null) { |
| 5353 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5354 | } else { |
| 5355 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5356 | + " is inactive, ignoring unregister."); |
| 5357 | // If the ImsManager is not valid, just return, since the callback will already |
| 5358 | // have been removed internally. |
| 5359 | } |
| 5360 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5361 | } finally { |
| 5362 | Binder.restoreCallingIdentity(identity); |
| 5363 | } |
| 5364 | } |
| 5365 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5366 | @Override |
| 5367 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5368 | IFeatureProvisioningCallback callback) { |
| 5369 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5370 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5371 | |
| 5372 | final long identity = Binder.clearCallingIdentity(); |
| 5373 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5374 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5375 | } |
| 5376 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5377 | try { |
| 5378 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5379 | if (controller == null) { |
| 5380 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5381 | "Device does not support IMS"); |
| 5382 | } |
| 5383 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
| 5386 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | @Override |
| 5390 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5391 | IFeatureProvisioningCallback callback) { |
| 5392 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5393 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5394 | |
| 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5397 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5398 | } |
| 5399 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5400 | try { |
| 5401 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5402 | if (controller == null) { |
| 5403 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5404 | return; |
| 5405 | } |
| 5406 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5410 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5411 | |
| 5412 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5414 | message); |
| 5415 | } |
| 5416 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5417 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5418 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5419 | boolean isProvisioned) { |
| 5420 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5421 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5422 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5423 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5424 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5427 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5428 | if (controller == null) { |
| 5429 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5430 | return; |
| 5431 | } |
| 5432 | controller.setRcsProvisioningStatusForCapability( |
| 5433 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5434 | } finally { |
| 5435 | Binder.restoreCallingIdentity(identity); |
| 5436 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | |
| 5440 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5441 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5442 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5443 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5444 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5445 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5446 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5447 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5450 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5451 | if (controller == null) { |
| 5452 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5453 | |
| 5454 | // device does not support IMS, this method will return true always. |
| 5455 | return true; |
| 5456 | } |
| 5457 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
| 5461 | } |
| 5462 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5463 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5464 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5465 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5466 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5469 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5470 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5471 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5474 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5475 | if (controller == null) { |
| 5476 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5477 | return; |
| 5478 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5479 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5480 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
| 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | @Override |
| 5487 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5488 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5489 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5490 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5492 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5493 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5494 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5495 | final long identity = Binder.clearCallingIdentity(); |
| 5496 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5497 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5498 | if (controller == null) { |
| 5499 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5500 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5501 | // device does not support IMS, this method will return true always. |
| 5502 | return true; |
| 5503 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5504 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5505 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5512 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5513 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5514 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5515 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5516 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5517 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5518 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5521 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5522 | if (controller == null) { |
| 5523 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5524 | |
| 5525 | // device does not support IMS, this method will return false |
| 5526 | return false; |
| 5527 | } |
| 5528 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5531 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5535 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5536 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5537 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5538 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5539 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5540 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5541 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5544 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5545 | if (controller == null) { |
| 5546 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5547 | |
| 5548 | // device does not support IMS, this method will return false |
| 5549 | return false; |
| 5550 | } |
| 5551 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5552 | } finally { |
| 5553 | Binder.restoreCallingIdentity(identity); |
| 5554 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5555 | } |
| 5556 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5557 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5558 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5559 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5560 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5561 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5562 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5563 | mApp, subId, "getImsProvisioningInt"); |
| 5564 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5565 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5566 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5567 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5568 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5569 | final long identity = Binder.clearCallingIdentity(); |
| 5570 | try { |
| 5571 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5572 | int slotId = getSlotIndex(subId); |
| 5573 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5574 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5575 | + subId + "' for key:" + key); |
| 5576 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5577 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5578 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5579 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5580 | if (controller == null) { |
| 5581 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5582 | |
| 5583 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5584 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5585 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5586 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5587 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5588 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5589 | return retVal; |
| 5590 | } |
| 5591 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5592 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5593 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5594 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5595 | + subId + "' for key:" + key); |
| 5596 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
| 5600 | } |
| 5601 | |
| 5602 | @Override |
| 5603 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5604 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5605 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5606 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5607 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5608 | mApp, subId, "getImsProvisioningString"); |
| 5609 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5610 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5611 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5612 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5613 | final long identity = Binder.clearCallingIdentity(); |
| 5614 | try { |
| 5615 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5616 | int slotId = getSlotIndex(subId); |
| 5617 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5618 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5619 | + subId + "' for key:" + key); |
| 5620 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5621 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5622 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5623 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5624 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5625 | + subId + "' for key:" + key); |
| 5626 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5627 | } finally { |
| 5628 | Binder.restoreCallingIdentity(identity); |
| 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | @Override |
| 5633 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5634 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5635 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5636 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5638 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5639 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5640 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5641 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5642 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5643 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
| 5646 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5647 | int slotId = getSlotIndex(subId); |
| 5648 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5649 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5650 | + subId + "' for key:" + key); |
| 5651 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5652 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5653 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5654 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5655 | if (controller == null) { |
| 5656 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5657 | |
| 5658 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5659 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5660 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5661 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5662 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5663 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5664 | return retVal; |
| 5665 | } |
| 5666 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5667 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5668 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5669 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5670 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5671 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
| 5675 | } |
| 5676 | |
| 5677 | @Override |
| 5678 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5679 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5680 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5681 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5683 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5684 | |
| 5685 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5686 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5687 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5688 | final long identity = Binder.clearCallingIdentity(); |
| 5689 | try { |
| 5690 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5691 | int slotId = getSlotIndex(subId); |
| 5692 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5693 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5694 | + subId + "' for key:" + key); |
| 5695 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5696 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5697 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5698 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5699 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5700 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5701 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5702 | } finally { |
| 5703 | Binder.restoreCallingIdentity(identity); |
| 5704 | } |
| 5705 | } |
| 5706 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5707 | /** |
| 5708 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5709 | * for the given slot ID or no ImsResolver instance has been created. |
| 5710 | * @param slotId The slot ID that the IMS service is created for. |
| 5711 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5712 | */ |
| 5713 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5714 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5715 | ImsFeature.FEATURE_MMTEL)) { |
| 5716 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5717 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5718 | } |
| 5719 | } |
| 5720 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5721 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5722 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5723 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5724 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5725 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5726 | } |
| 5727 | return slotId; |
| 5728 | } |
| 5729 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5730 | private int getSlotIndex(int subId) { |
| 5731 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5732 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5733 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5734 | } |
| 5735 | return slotId; |
| 5736 | } |
| 5737 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5738 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5739 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5740 | */ |
| 5741 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5742 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5743 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5744 | try { |
| 5745 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5746 | } catch (SecurityException se) { |
| 5747 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5748 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5749 | + Binder.getCallingUid()); |
| 5750 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5751 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5752 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5753 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5754 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5755 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5756 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5757 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5758 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5759 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5760 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5761 | enforceTelephonyFeatureWithException(callingPackage, |
| 5762 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | final long identity = Binder.clearCallingIdentity(); |
| 5765 | try { |
| 5766 | final Phone phone = getPhone(subId); |
| 5767 | if (phone != null) { |
| 5768 | return phone.getServiceState().getDataNetworkType(); |
| 5769 | } else { |
| 5770 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5771 | } |
| 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5774 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /** |
| 5778 | * Returns the data network type |
| 5779 | */ |
| 5780 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5781 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5782 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5783 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | /** |
| 5787 | * Returns the data network type for a subId |
| 5788 | */ |
| 5789 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5790 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5791 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5792 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5793 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5794 | mApp, functionName)) { |
| 5795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5796 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5797 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5798 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5799 | } |
| 5800 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5801 | enforceTelephonyFeatureWithException(callingPackage, |
| 5802 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5803 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | final long identity = Binder.clearCallingIdentity(); |
| 5805 | try { |
| 5806 | final Phone phone = getPhone(subId); |
| 5807 | if (phone != null) { |
| 5808 | return phone.getServiceState().getDataNetworkType(); |
| 5809 | } else { |
| 5810 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5811 | } |
| 5812 | } finally { |
| 5813 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5814 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5818 | * Returns the Voice network type for a subId |
| 5819 | */ |
| 5820 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5821 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5822 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5823 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5824 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5825 | mApp, functionName)) { |
| 5826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5827 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5828 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5829 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5830 | } |
| 5831 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5832 | enforceTelephonyFeatureWithException(callingPackage, |
| 5833 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | final Phone phone = getPhone(subId); |
| 5838 | if (phone != null) { |
| 5839 | return phone.getServiceState().getVoiceNetworkType(); |
| 5840 | } else { |
| 5841 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5842 | } |
| 5843 | } finally { |
| 5844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | /** |
| 5849 | * @return true if a ICC card is present |
| 5850 | */ |
| 5851 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5852 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5853 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5854 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5858 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5859 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5860 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5861 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5862 | if (!mApp.getResources().getBoolean( |
| 5863 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5864 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5865 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5866 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5867 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5868 | final long identity = Binder.clearCallingIdentity(); |
| 5869 | try { |
| 5870 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5871 | if (phone != null) { |
| 5872 | return phone.getIccCard().hasIccCard(); |
| 5873 | } else { |
| 5874 | return false; |
| 5875 | } |
| 5876 | } finally { |
| 5877 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5878 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * Return if the current radio is LTE on CDMA. This |
| 5883 | * is a tri-state return value as for a period of time |
| 5884 | * the mode may be unknown. |
| 5885 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5886 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5887 | * @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] | 5888 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5889 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5890 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5891 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5892 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5893 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5896 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5897 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5898 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5899 | try { |
| 5900 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5901 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5902 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5903 | } |
| 5904 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5905 | enforceTelephonyFeatureWithException(callingPackage, |
| 5906 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | final long identity = Binder.clearCallingIdentity(); |
| 5909 | try { |
| 5910 | final Phone phone = getPhone(subId); |
| 5911 | if (phone == null) { |
| 5912 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5913 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5914 | return TelephonyProperties.lte_on_cdma_device() |
| 5915 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | } |
| 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5919 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5920 | } |
| 5921 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5922 | /** |
| 5923 | * {@hide} |
| 5924 | * Returns Default subId, 0 in the case of single standby. |
| 5925 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5926 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5927 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5928 | } |
| 5929 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5930 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5931 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5934 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5935 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5936 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5937 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5938 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5939 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5940 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5943 | /** |
| 5944 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5945 | */ |
| 5946 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5949 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5951 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
| 5954 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | /** |
| 5958 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5959 | */ |
| 5960 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
| 5963 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5964 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
| 5968 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5969 | } |
| 5970 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5971 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5972 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5973 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5974 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5975 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5976 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5977 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5978 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5979 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5980 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5981 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5982 | } |
| 5983 | return PhoneFactory.getPhone(phoneId); |
| 5984 | } |
| 5985 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5986 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5987 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5988 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5989 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5990 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5991 | /*message=*/ "iccOpenLogicalChannel"); |
| 5992 | |
| 5993 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5994 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5995 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5996 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5997 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5998 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5999 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6000 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6001 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6002 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6003 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6004 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6005 | Phone phone; |
| 6006 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6008 | mApp, request.subId, message); |
| 6009 | phone = getPhoneFromSubId(request.subId); |
| 6010 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6011 | enforceModifyPermission(); |
| 6012 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6013 | } else { |
| 6014 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6015 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6016 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6020 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6023 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6024 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6025 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6026 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6027 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6028 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | loge("The calling package is not allowed to access ISD-R."); |
| 6030 | throw new SecurityException( |
| 6031 | "The calling package is not allowed to access ISD-R."); |
| 6032 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6033 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6035 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6036 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6037 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | return response; |
| 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
| 6041 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6045 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6046 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6047 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6048 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6049 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6050 | /*message=*/"iccCloseLogicalChannel"); |
| 6051 | |
| 6052 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6053 | |
| 6054 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6055 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6056 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6057 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6058 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6059 | // before this feature is enabled, this API should only return false if |
| 6060 | // the operation fails instead of throwing runtime exception for |
| 6061 | // backward-compatibility. |
| 6062 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6063 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6064 | final long identity = Binder.clearCallingIdentity(); |
| 6065 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6066 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6067 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6069 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6070 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6071 | Boolean success = false; |
| 6072 | if (result instanceof RuntimeException) { |
| 6073 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6074 | if (shouldThrowExceptionOnFailure) { |
| 6075 | throw (RuntimeException) result; |
| 6076 | } else { |
| 6077 | return false; |
| 6078 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6079 | } else if (result instanceof Boolean) { |
| 6080 | success = (Boolean) result; |
| 6081 | } else { |
| 6082 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6083 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6084 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | return success; |
| 6086 | } finally { |
| 6087 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6088 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6092 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6093 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6095 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6096 | |
| 6097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6098 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6099 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6100 | if (DBG) { |
| 6101 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6102 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6103 | + p3 + " data=" + data); |
| 6104 | } |
| 6105 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6106 | command, p1, p2, p3, data); |
| 6107 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6108 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6109 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6110 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6111 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6112 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6113 | |
| 6114 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6115 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6116 | "iccTransmitApduLogicalChannelBySlot"); |
| 6117 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6118 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6119 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6120 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6121 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6122 | } |
| 6123 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6124 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6125 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6126 | } |
| 6127 | |
| 6128 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6129 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6130 | final long identity = Binder.clearCallingIdentity(); |
| 6131 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6132 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | return ""; |
| 6134 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6137 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6138 | null /* workSource */); |
| 6139 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6140 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 | // Append the returned status code to the end of the response payload. |
| 6142 | String s = Integer.toHexString( |
| 6143 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6144 | if (response.payload != null) { |
| 6145 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6146 | } |
| 6147 | return s; |
| 6148 | } finally { |
| 6149 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6150 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6151 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6152 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6153 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6154 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6155 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6157 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6159 | |
| 6160 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6161 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6162 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6163 | if (DBG) { |
| 6164 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6165 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6166 | } |
| 6167 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6168 | cla, command, p1, p2, p3, data); |
| 6169 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6170 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6171 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6172 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6173 | 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] | 6174 | enforceModifyPermission(); |
| 6175 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6176 | |
| 6177 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6178 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6179 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6180 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6181 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6182 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6183 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6187 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6188 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6189 | } |
| 6190 | |
| 6191 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6192 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6193 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | final long identity = Binder.clearCallingIdentity(); |
| 6195 | try { |
| 6196 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6197 | && TextUtils.equals(ISDR_AID, data)) { |
| 6198 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6199 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6200 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6201 | if (bestComponent == null |
| 6202 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6203 | loge("The calling package is not allowed to select ISD-R."); |
| 6204 | throw new SecurityException( |
| 6205 | "The calling package is not allowed to select ISD-R."); |
| 6206 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6207 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6208 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6209 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6210 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6211 | null /* workSource */); |
| 6212 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | // Append the returned status code to the end of the response payload. |
| 6215 | String s = Integer.toHexString( |
| 6216 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6217 | if (response.payload != null) { |
| 6218 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6219 | } |
| 6220 | return s; |
| 6221 | } finally { |
| 6222 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6223 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6227 | 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] | 6228 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6230 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6231 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6232 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6233 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | final long identity = Binder.clearCallingIdentity(); |
| 6236 | try { |
| 6237 | if (DBG) { |
| 6238 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6239 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6240 | } |
| 6241 | |
| 6242 | IccIoResult response = |
| 6243 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6244 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6245 | subId); |
| 6246 | |
| 6247 | if (DBG) { |
| 6248 | log("Exchange SIM_IO [R]" + response); |
| 6249 | } |
| 6250 | |
| 6251 | byte[] result = null; |
| 6252 | int length = 2; |
| 6253 | if (response.payload != null) { |
| 6254 | length = 2 + response.payload.length; |
| 6255 | result = new byte[length]; |
| 6256 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6257 | } else { |
| 6258 | result = new byte[length]; |
| 6259 | } |
| 6260 | |
| 6261 | result[length - 1] = (byte) response.sw2; |
| 6262 | result[length - 2] = (byte) response.sw1; |
| 6263 | return result; |
| 6264 | } finally { |
| 6265 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6266 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6267 | } |
| 6268 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6269 | /** |
| 6270 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6271 | * on a particular subscription |
| 6272 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6273 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6274 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6276 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6277 | return null; |
| 6278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6279 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6280 | enforceTelephonyFeatureWithException(callingPackage, |
| 6281 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6282 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | final long identity = Binder.clearCallingIdentity(); |
| 6284 | try { |
| 6285 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6286 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6287 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6288 | return null; |
| 6289 | } |
| 6290 | Object response = sendRequest( |
| 6291 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6292 | if (response instanceof String[]) { |
| 6293 | return (String[]) response; |
| 6294 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6295 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6297 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6300 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6301 | } |
| 6302 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6303 | /** |
| 6304 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6305 | * subscription. |
| 6306 | * |
| 6307 | * @param subId the id of the subscription. |
| 6308 | * @param appType the uicc app type, must be USIM or SIM. |
| 6309 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6310 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6311 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6312 | * @return number of fplmns that is successfully written to the SIM. |
| 6313 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6314 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6315 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6317 | mApp, subId, "setForbiddenPlmns"); |
| 6318 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6319 | enforceTelephonyFeatureWithException(callingPackage, |
| 6320 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6321 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6322 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6323 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6324 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6325 | } |
| 6326 | if (fplmns == null) { |
| 6327 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6328 | } |
| 6329 | for (String fplmn : fplmns) { |
| 6330 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6331 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6332 | } |
| 6333 | } |
| 6334 | final long identity = Binder.clearCallingIdentity(); |
| 6335 | try { |
| 6336 | Object response = sendRequest( |
| 6337 | CMD_SET_FORBIDDEN_PLMNS, |
| 6338 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6339 | subId); |
| 6340 | return (int) response; |
| 6341 | } finally { |
| 6342 | Binder.restoreCallingIdentity(identity); |
| 6343 | } |
| 6344 | } |
| 6345 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6346 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6347 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6349 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6350 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6351 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6352 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6357 | if (response.payload == null) { |
| 6358 | return ""; |
| 6359 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6361 | // Append the returned status code to the end of the response payload. |
| 6362 | String s = Integer.toHexString( |
| 6363 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6364 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6365 | return s; |
| 6366 | } finally { |
| 6367 | Binder.restoreCallingIdentity(identity); |
| 6368 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6371 | /** |
| 6372 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6373 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6374 | * |
| 6375 | * @param itemID the ID of the item to read |
| 6376 | * @return the NV item as a String, or null on error. |
| 6377 | */ |
| 6378 | @Override |
| 6379 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6380 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6382 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6383 | |
| 6384 | final long identity = Binder.clearCallingIdentity(); |
| 6385 | try { |
| 6386 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6387 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6388 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6389 | return value; |
| 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /** |
| 6396 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6397 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6398 | * |
| 6399 | * @param itemID the ID of the item to read |
| 6400 | * @param itemValue the value to write, as a String |
| 6401 | * @return true on success; false on any failure |
| 6402 | */ |
| 6403 | @Override |
| 6404 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6405 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6407 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | |
| 6409 | final long identity = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6412 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6413 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6415 | return success; |
| 6416 | } finally { |
| 6417 | Binder.restoreCallingIdentity(identity); |
| 6418 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | /** |
| 6422 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6423 | * Used for device configuration by some CDMA operators. |
| 6424 | * |
| 6425 | * @param preferredRoamingList byte array containing the new PRL |
| 6426 | * @return true on success; false on any failure |
| 6427 | */ |
| 6428 | @Override |
| 6429 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6431 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6432 | |
| 6433 | final long identity = Binder.clearCallingIdentity(); |
| 6434 | try { |
| 6435 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6436 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6437 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6438 | return success; |
| 6439 | } finally { |
| 6440 | Binder.restoreCallingIdentity(identity); |
| 6441 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6445 | * 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] | 6446 | * Used for device configuration by some CDMA operators. |
| 6447 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6448 | * @param slotIndex - device slot. |
| 6449 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6450 | * @return true on success; false on any failure |
| 6451 | */ |
| 6452 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6453 | public boolean resetModemConfig(int slotIndex) { |
| 6454 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6455 | if (phone != null) { |
| 6456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6457 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6458 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6459 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6460 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6461 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6462 | final long identity = Binder.clearCallingIdentity(); |
| 6463 | try { |
| 6464 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6465 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6466 | return success; |
| 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
| 6469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6470 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6471 | return false; |
| 6472 | } |
| 6473 | |
| 6474 | /** |
| 6475 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6476 | * |
| 6477 | * @param slotIndex - device slot. |
| 6478 | * |
| 6479 | * @return true on success; false on any failure |
| 6480 | */ |
| 6481 | @Override |
| 6482 | public boolean rebootModem(int slotIndex) { |
| 6483 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6484 | if (phone != null) { |
| 6485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6486 | mApp, phone.getSubId(), "rebootModem"); |
| 6487 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6488 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6489 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6490 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6494 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6495 | return success; |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
| 6499 | } |
| 6500 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6501 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6502 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6503 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6504 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6505 | * {@link #disableIms(int)}. |
| 6506 | * @param slotIndex device slot. |
| 6507 | */ |
| 6508 | public void resetIms(int slotIndex) { |
| 6509 | enforceModifyPermission(); |
| 6510 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6511 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6512 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6513 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6514 | final long identity = Binder.clearCallingIdentity(); |
| 6515 | try { |
| 6516 | if (mImsResolver == null) { |
| 6517 | // may happen if the does not support IMS. |
| 6518 | return; |
| 6519 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6520 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6521 | } finally { |
| 6522 | Binder.restoreCallingIdentity(identity); |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6527 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6528 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6529 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6530 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6531 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6532 | |
| 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6535 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6536 | // may happen if the device does not support IMS. |
| 6537 | return; |
| 6538 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6539 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | } finally { |
| 6541 | Binder.restoreCallingIdentity(identity); |
| 6542 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6546 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6547 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6548 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6549 | public void disableIms(int slotId) { |
| 6550 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | |
| 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6554 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6555 | // may happen if the device does not support IMS. |
| 6556 | return; |
| 6557 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6558 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6559 | } finally { |
| 6560 | Binder.restoreCallingIdentity(identity); |
| 6561 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6562 | } |
| 6563 | |
| 6564 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6565 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6566 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6567 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6568 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6569 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6570 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6571 | |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6574 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6575 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6576 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6577 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6578 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6579 | } finally { |
| 6580 | Binder.restoreCallingIdentity(identity); |
| 6581 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6582 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6583 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6584 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6585 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6586 | @Override |
| 6587 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6588 | enforceModifyPermission(); |
| 6589 | |
| 6590 | final long identity = Binder.clearCallingIdentity(); |
| 6591 | try { |
| 6592 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6593 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6594 | } finally { |
| 6595 | Binder.restoreCallingIdentity(identity); |
| 6596 | } |
| 6597 | } |
| 6598 | |
| 6599 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6600 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6601 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6602 | */ |
| 6603 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6604 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | |
| 6606 | final long identity = Binder.clearCallingIdentity(); |
| 6607 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6608 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6609 | // may happen if the device does not support IMS. |
| 6610 | return null; |
| 6611 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6612 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6613 | } finally { |
| 6614 | Binder.restoreCallingIdentity(identity); |
| 6615 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6616 | } |
| 6617 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6618 | /** |
| 6619 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6620 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6621 | */ |
| 6622 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6623 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6624 | |
| 6625 | final long identity = Binder.clearCallingIdentity(); |
| 6626 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6627 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6628 | // may happen if the device does not support IMS. |
| 6629 | return null; |
| 6630 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6631 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6632 | } finally { |
| 6633 | Binder.restoreCallingIdentity(identity); |
| 6634 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6635 | } |
| 6636 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6637 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6638 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6639 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6640 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6641 | * @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] | 6642 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6643 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6644 | * @param packageName The name of the package that the current configuration will be replaced |
| 6645 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6646 | * @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] | 6647 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6648 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6649 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6651 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6652 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6654 | final long identity = Binder.clearCallingIdentity(); |
| 6655 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6656 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6657 | // may happen if the device does not support IMS. |
| 6658 | return false; |
| 6659 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6660 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6661 | for (int featureType : featureTypes) { |
| 6662 | featureConfig.put(featureType, packageName); |
| 6663 | } |
| 6664 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6665 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6666 | } finally { |
| 6667 | Binder.restoreCallingIdentity(identity); |
| 6668 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6672 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6673 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6674 | * |
| 6675 | * This should only be used for testing. |
| 6676 | * |
| 6677 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6678 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6679 | */ |
| 6680 | @Override |
| 6681 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6682 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6683 | "clearCarrierImsServiceOverride"); |
| 6684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6685 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6686 | |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
| 6689 | if (mImsResolver == null) { |
| 6690 | // may happen if the device does not support IMS. |
| 6691 | return false; |
| 6692 | } |
| 6693 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6694 | } finally { |
| 6695 | Binder.restoreCallingIdentity(identity); |
| 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6700 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6701 | * |
| 6702 | * @param slotId The slot that the ImsService is associated with. |
| 6703 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6704 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6705 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6706 | * @return the package name of the ImsService configuration. |
| 6707 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6708 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6709 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6710 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6711 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6712 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | final long identity = Binder.clearCallingIdentity(); |
| 6715 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6716 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6717 | // may happen if the device does not support IMS. |
| 6718 | return ""; |
| 6719 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6720 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6721 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6722 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
| 6725 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6728 | /** |
| 6729 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6730 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6731 | * @param callback A callback with an integer containing the |
| 6732 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6733 | */ |
| 6734 | @Override |
| 6735 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6736 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6737 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6739 | "IMS not available on device."); |
| 6740 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6741 | final long token = Binder.clearCallingIdentity(); |
| 6742 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6743 | int slotId = getSlotIndex(subId); |
| 6744 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6745 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6746 | + subId + "'"); |
| 6747 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6748 | } |
| 6749 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6750 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6751 | try { |
| 6752 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6753 | } catch (RemoteException e) { |
| 6754 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6755 | + "Ignore"); |
| 6756 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6757 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6758 | } catch (ImsException e) { |
| 6759 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(token); |
| 6762 | } |
| 6763 | } |
| 6764 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6765 | /** |
| 6766 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6767 | */ |
| 6768 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6769 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | |
| 6771 | final long identity = Binder.clearCallingIdentity(); |
| 6772 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6773 | // NOTE: Before S, this method only set the default phone. |
| 6774 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6775 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6776 | phone.setImsRegistrationState(registered); |
| 6777 | } |
| 6778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | } finally { |
| 6780 | Binder.restoreCallingIdentity(identity); |
| 6781 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6785 | * Set the network selection mode to automatic. |
| 6786 | * |
| 6787 | */ |
| 6788 | @Override |
| 6789 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6791 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6793 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6794 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6796 | final long identity = Binder.clearCallingIdentity(); |
| 6797 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6798 | if (!isActiveSubscription(subId)) { |
| 6799 | return; |
| 6800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6801 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6802 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6803 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6804 | } finally { |
| 6805 | Binder.restoreCallingIdentity(identity); |
| 6806 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6807 | } |
| 6808 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6809 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6810 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6811 | * |
| 6812 | * @param subId the id of the subscription. |
| 6813 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6814 | * the operator to attach to. |
| 6815 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6816 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6817 | * normal network selection next time. |
| 6818 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6819 | */ |
| 6820 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6821 | public boolean setNetworkSelectionModeManual( |
| 6822 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6824 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6825 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6827 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6828 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6829 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6830 | if (!isActiveSubscription(subId)) { |
| 6831 | return false; |
| 6832 | } |
| 6833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6835 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6837 | if (DBG) { |
| 6838 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6839 | + " operator: " + operatorInfo); |
| 6840 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6842 | } finally { |
| 6843 | Binder.restoreCallingIdentity(identity); |
| 6844 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6845 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6846 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6847 | * Get the manual network selection |
| 6848 | * |
| 6849 | * @param subId the id of the subscription. |
| 6850 | * |
| 6851 | * @return the previously saved user selected PLMN |
| 6852 | */ |
| 6853 | @Override |
| 6854 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6855 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6856 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6857 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6858 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6859 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6860 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6861 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6865 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6866 | } |
| 6867 | |
| 6868 | final Phone phone = getPhone(subId); |
| 6869 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6870 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6871 | } |
| 6872 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6873 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6874 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(identity); |
| 6877 | } |
| 6878 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6879 | |
| 6880 | /** |
| 6881 | * Scans for available networks. |
| 6882 | */ |
| 6883 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6884 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6885 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6887 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6888 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6889 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6890 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6891 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6892 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6893 | .setCallingPid(Binder.getCallingPid()) |
| 6894 | .setCallingUid(Binder.getCallingUid()) |
| 6895 | .setMethod("getCellNetworkScanResults") |
| 6896 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6897 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6898 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6899 | .build()); |
| 6900 | switch (locationResult) { |
| 6901 | case DENIED_HARD: |
| 6902 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6903 | case DENIED_SOFT: |
| 6904 | return null; |
| 6905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6907 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6908 | try { |
| 6909 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6910 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6911 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(identity); |
| 6914 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6918 | * Get the call forwarding info, given the call forwarding reason. |
| 6919 | */ |
| 6920 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6921 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6922 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6923 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6924 | |
| 6925 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6926 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6927 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6928 | long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | if (DBG) { |
| 6931 | log("getCallForwarding: subId " + subId |
| 6932 | + " callForwardingReason" + callForwardingReason); |
| 6933 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6934 | |
| 6935 | Phone phone = getPhone(subId); |
| 6936 | if (phone == null) { |
| 6937 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6938 | callback.onError( |
| 6939 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6940 | } catch (RemoteException e) { |
| 6941 | // ignore |
| 6942 | } |
| 6943 | return; |
| 6944 | } |
| 6945 | |
| 6946 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6947 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6948 | @Override |
| 6949 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6950 | try { |
| 6951 | callback.onCallForwardingInfoAvailable(info); |
| 6952 | } catch (RemoteException e) { |
| 6953 | // ignore |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | @Override |
| 6958 | public void onError(int error) { |
| 6959 | try { |
| 6960 | callback.onError(error); |
| 6961 | } catch (RemoteException e) { |
| 6962 | // ignore |
| 6963 | } |
| 6964 | } |
| 6965 | }); |
| 6966 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6967 | } finally { |
| 6968 | Binder.restoreCallingIdentity(identity); |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /** |
| 6973 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6974 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6975 | */ |
| 6976 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6977 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6978 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6979 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6980 | |
| 6981 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6982 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6983 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6984 | long identity = Binder.clearCallingIdentity(); |
| 6985 | try { |
| 6986 | if (DBG) { |
| 6987 | log("setCallForwarding: subId " + subId |
| 6988 | + " callForwardingInfo" + callForwardingInfo); |
| 6989 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6990 | |
| 6991 | Phone phone = getPhone(subId); |
| 6992 | if (phone == null) { |
| 6993 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6994 | callback.accept( |
| 6995 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6996 | } catch (RemoteException e) { |
| 6997 | // ignore |
| 6998 | } |
| 6999 | return; |
| 7000 | } |
| 7001 | |
| 7002 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7003 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7004 | |
| 7005 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7006 | } finally { |
| 7007 | Binder.restoreCallingIdentity(identity); |
| 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7012 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7013 | */ |
| 7014 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7015 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7016 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7017 | |
| 7018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7019 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7020 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7021 | long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7023 | Phone phone = getPhone(subId); |
| 7024 | if (phone == null) { |
| 7025 | try { |
| 7026 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7027 | } catch (RemoteException e) { |
| 7028 | // ignore |
| 7029 | } |
| 7030 | return; |
| 7031 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7032 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7033 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7034 | boolean requireUssd = c.getBoolean( |
| 7035 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7036 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7037 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7038 | if (requireUssd) { |
| 7039 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7040 | getSubscriptionCarrierId(subId)); |
| 7041 | String newUssdCommand = ""; |
| 7042 | try { |
| 7043 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7044 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7045 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7046 | } catch (NullPointerException e) { |
| 7047 | loge("Failed to generate USSD number" + e); |
| 7048 | } |
| 7049 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7050 | mMainThreadHandler, callback, carrierXmlParser, |
| 7051 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7052 | final String ussdCommand = newUssdCommand; |
| 7053 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7054 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7055 | }); |
| 7056 | } else { |
| 7057 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7058 | callback::accept); |
| 7059 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7060 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
| 7064 | } |
| 7065 | |
| 7066 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7067 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7068 | */ |
| 7069 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7070 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7071 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7072 | |
| 7073 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7074 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7075 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7076 | long identity = Binder.clearCallingIdentity(); |
| 7077 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7078 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7079 | |
| 7080 | Phone phone = getPhone(subId); |
| 7081 | if (phone == null) { |
| 7082 | try { |
| 7083 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7084 | } catch (RemoteException e) { |
| 7085 | // ignore |
| 7086 | } |
| 7087 | return; |
| 7088 | } |
| 7089 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7090 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7091 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7092 | boolean requireUssd = c.getBoolean( |
| 7093 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7094 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7095 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7096 | if (requireUssd) { |
| 7097 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7098 | getSubscriptionCarrierId(subId)); |
| 7099 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7100 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7101 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7102 | String newUssdCommand = ""; |
| 7103 | try { |
| 7104 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7105 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7106 | .makeCommand(ssAction, null); |
| 7107 | } catch (NullPointerException e) { |
| 7108 | loge("Failed to generate USSD number" + e); |
| 7109 | } |
| 7110 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7111 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7112 | final String ussdCommand = newUssdCommand; |
| 7113 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7114 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7115 | }); |
| 7116 | } else { |
| 7117 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7118 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7119 | |
| 7120 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7121 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7128 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7129 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7130 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7131 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7132 | * location related information which will be sent if the caller already possess |
| 7133 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7134 | * @param request contains the radio access networks with bands/channels to scan |
| 7135 | * @param messenger callback messenger for scan results or errors |
| 7136 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7137 | * @return the id of the requested scan which can be used to stop the scan. |
| 7138 | */ |
| 7139 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7140 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7141 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7142 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7144 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7145 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7146 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7147 | if (!renounceFineLocationAccess) { |
| 7148 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7149 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7150 | .setCallingPackage(callingPackage) |
| 7151 | .setCallingFeatureId(callingFeatureId) |
| 7152 | .setCallingPid(Binder.getCallingPid()) |
| 7153 | .setCallingUid(Binder.getCallingUid()) |
| 7154 | .setMethod("requestNetworkScan") |
| 7155 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7156 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7157 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7158 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7159 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7160 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7161 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7162 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7163 | if (e != null) { |
| 7164 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7165 | throw e; |
| 7166 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7167 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7168 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7169 | } |
| 7170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7172 | |
| 7173 | enforceTelephonyFeatureWithException(callingPackage, |
| 7174 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7175 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7176 | int callingUid = Binder.getCallingUid(); |
| 7177 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
| 7180 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7181 | renounceFineLocationAccess, request, messenger, binder, |
| 7182 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7183 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7189 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7190 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7191 | boolean hasCarrierPriv; |
| 7192 | final long identity = Binder.clearCallingIdentity(); |
| 7193 | try { |
| 7194 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7195 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7196 | } finally { |
| 7197 | Binder.restoreCallingIdentity(identity); |
| 7198 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7199 | boolean hasNetworkScanPermission = |
| 7200 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7201 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7202 | |
| 7203 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7204 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7205 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7206 | } |
| 7207 | |
| 7208 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7209 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7210 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7211 | return new SecurityException("Specific channels must not be" |
| 7212 | + " scanned without location access."); |
| 7213 | } |
| 7214 | } |
| 7215 | } |
| 7216 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7217 | return null; |
| 7218 | } |
| 7219 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7220 | /** |
| 7221 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7222 | * |
| 7223 | * @param subId id of the subscription |
| 7224 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7225 | */ |
| 7226 | @Override |
| 7227 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7229 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7231 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | final long identity = Binder.clearCallingIdentity(); |
| 7233 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7234 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | } finally { |
| 7236 | Binder.restoreCallingIdentity(identity); |
| 7237 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7238 | } |
| 7239 | |
| 7240 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7241 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7242 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7243 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7244 | */ |
| 7245 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7246 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7247 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7248 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7249 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7251 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7252 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | final long identity = Binder.clearCallingIdentity(); |
| 7255 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7256 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7257 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7258 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7259 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7260 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | } finally { |
| 7262 | Binder.restoreCallingIdentity(identity); |
| 7263 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7267 | * Get the allowed network types for certain reason. |
| 7268 | * |
| 7269 | * @param subId the id of the subscription. |
| 7270 | * @param reason the reason the allowed network type change is taking place |
| 7271 | * @return the allowed network types. |
| 7272 | */ |
| 7273 | @Override |
| 7274 | public long getAllowedNetworkTypesForReason(int subId, |
| 7275 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7276 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7277 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7278 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7279 | if (!mApp.getResources().getBoolean( |
| 7280 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7281 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7282 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7283 | "getAllowedNetworkTypesForReason"); |
| 7284 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7285 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7286 | final long identity = Binder.clearCallingIdentity(); |
| 7287 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7288 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7289 | } finally { |
| 7290 | Binder.restoreCallingIdentity(identity); |
| 7291 | } |
| 7292 | } |
| 7293 | |
| 7294 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7295 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7296 | * @param subId subscription id of the sim card |
| 7297 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7298 | * This can be passed following states |
| 7299 | * <ol> |
| 7300 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7301 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7302 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7303 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7304 | * </ol> |
| 7305 | * @return operation result. |
| 7306 | */ |
| 7307 | @Override |
| 7308 | public int setNrDualConnectivityState(int subId, |
| 7309 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7311 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7312 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7313 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7314 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7315 | } |
| 7316 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7317 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7318 | final long identity = Binder.clearCallingIdentity(); |
| 7319 | try { |
| 7320 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7321 | nrDualConnectivityState, subId, |
| 7322 | workSource); |
| 7323 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7324 | return result; |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | /** |
| 7331 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7332 | * @return true if dual connectivity is enabled else false |
| 7333 | */ |
| 7334 | @Override |
| 7335 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7336 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7337 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7338 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7339 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7340 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7341 | return false; |
| 7342 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7347 | null, subId, workSource); |
| 7348 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7349 | return isEnabled; |
| 7350 | } finally { |
| 7351 | Binder.restoreCallingIdentity(identity); |
| 7352 | } |
| 7353 | } |
| 7354 | |
| 7355 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7356 | * Set the allowed network types of the device and |
| 7357 | * provide the reason triggering the allowed network change. |
| 7358 | * |
| 7359 | * @param subId the id of the subscription. |
| 7360 | * @param reason the reason the allowed network type change is taking place |
| 7361 | * @param allowedNetworkTypes the allowed network types. |
| 7362 | * @return true on success; false on any failure. |
| 7363 | */ |
| 7364 | @Override |
| 7365 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7366 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7367 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7369 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7370 | // If the caller only has carrier privileges, then they should not be able to override |
| 7371 | // any network types which were set for security reasons. |
| 7372 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7373 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7374 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7375 | throw new SecurityException( |
| 7376 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7377 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7378 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7379 | |
| 7380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7381 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7382 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7383 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7384 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7385 | return false; |
| 7386 | } |
| 7387 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7388 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7389 | return false; |
| 7390 | } |
| 7391 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7392 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7393 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7394 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7395 | Phone phone = getPhone(subId); |
| 7396 | if (phone == null) { |
| 7397 | return false; |
| 7398 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7399 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7400 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7401 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7402 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7403 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7404 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7407 | Boolean success = (Boolean) sendRequest( |
| 7408 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7409 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7410 | |
| 7411 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7412 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
| 7416 | } |
| 7417 | |
| 7418 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7419 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7420 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7421 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7422 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7423 | * @hide |
| 7424 | */ |
| 7425 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7426 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7427 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7428 | |
| 7429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7430 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7433 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7434 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7435 | if (phone != null) { |
| 7436 | return phone.hasMatchedTetherApnSetting(); |
| 7437 | } else { |
| 7438 | return false; |
| 7439 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7442 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7446 | * Get the user enabled state of Mobile Data. |
| 7447 | * |
| 7448 | * TODO: remove and use isUserDataEnabled. |
| 7449 | * This can't be removed now because some vendor codes |
| 7450 | * calls through ITelephony directly while they should |
| 7451 | * use TelephonyManager. |
| 7452 | * |
| 7453 | * @return true on enabled |
| 7454 | */ |
| 7455 | @Override |
| 7456 | public boolean getDataEnabled(int subId) { |
| 7457 | return isUserDataEnabled(subId); |
| 7458 | } |
| 7459 | |
| 7460 | /** |
| 7461 | * Get whether mobile data is enabled per user setting. |
| 7462 | * |
| 7463 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7464 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7465 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7466 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7467 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7468 | * |
| 7469 | * @return {@code true} if data is enabled else {@code false} |
| 7470 | */ |
| 7471 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7472 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7473 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7474 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7475 | try { |
| 7476 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7477 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7478 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7479 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7480 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7481 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7482 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7483 | mApp, subId, functionName); |
| 7484 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7485 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | |
| 7487 | final long identity = Binder.clearCallingIdentity(); |
| 7488 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7489 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7491 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7492 | if (phone != null) { |
| 7493 | boolean retVal = phone.isUserDataEnabled(); |
| 7494 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7495 | return retVal; |
| 7496 | } else { |
| 7497 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7498 | return false; |
| 7499 | } |
| 7500 | } finally { |
| 7501 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7502 | } |
| 7503 | } |
| 7504 | |
| 7505 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7506 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7507 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7508 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7509 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7510 | * @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] | 7511 | */ |
| 7512 | @Override |
| 7513 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7514 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7515 | try { |
| 7516 | try { |
| 7517 | mApp.enforceCallingOrSelfPermission( |
| 7518 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7519 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7520 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7521 | try { |
| 7522 | mApp.enforceCallingOrSelfPermission( |
| 7523 | android.Manifest.permission.READ_PHONE_STATE, |
| 7524 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7525 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7526 | mApp.enforceCallingOrSelfPermission( |
| 7527 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7528 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7529 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7530 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7531 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7533 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7534 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7535 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | final long identity = Binder.clearCallingIdentity(); |
| 7538 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7539 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7541 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7542 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7543 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | return retVal; |
| 7545 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7546 | if (DBG) { |
| 7547 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7548 | + subId + " retVal=false"); |
| 7549 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | return false; |
| 7551 | } |
| 7552 | } finally { |
| 7553 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7554 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7555 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7556 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7557 | /** |
| 7558 | * Check if data is enabled for a specific reason |
| 7559 | * @param subId Subscription index |
| 7560 | * @param reason the reason the data enable change is taking place |
| 7561 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7562 | */ |
| 7563 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7564 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7565 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7566 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7567 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7568 | try { |
| 7569 | mApp.enforceCallingOrSelfPermission( |
| 7570 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7571 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7572 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7573 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7574 | functionName); |
| 7575 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7576 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7577 | try { |
| 7578 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7579 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7580 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7581 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7582 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7583 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7584 | } |
| 7585 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7586 | if (!mApp.getResources().getBoolean( |
| 7587 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7588 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7589 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7590 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7591 | |
| 7592 | final long identity = Binder.clearCallingIdentity(); |
| 7593 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7594 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7595 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7596 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7597 | + " reason=" + reason); |
| 7598 | } |
| 7599 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7600 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7601 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7602 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7603 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7604 | return retVal; |
| 7605 | } else { |
| 7606 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7607 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7608 | + subId + " retVal=false"); |
| 7609 | } |
| 7610 | return false; |
| 7611 | } |
| 7612 | } finally { |
| 7613 | Binder.restoreCallingIdentity(identity); |
| 7614 | } |
| 7615 | } |
| 7616 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7617 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7618 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7619 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7620 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7621 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7622 | // No permission needed; this only lets the caller inspect their own status. |
| 7623 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7624 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7625 | |
| 7626 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7627 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7628 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7629 | |
| 7630 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7631 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7632 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7633 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7634 | } |
| 7635 | |
| 7636 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7637 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7638 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7639 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7640 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7641 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7642 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7643 | if (cpt == null) { |
| 7644 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7645 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7646 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7647 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7651 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7652 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7653 | |
| 7654 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7655 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7656 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7657 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7658 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7659 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7660 | Phone phone = getPhone(subId); |
| 7661 | if (phone == null) { |
| 7662 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7663 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7664 | } |
| 7665 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7666 | if (cpt == null) { |
| 7667 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7668 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7669 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7670 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | @Override |
| 7674 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7675 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7676 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7677 | if (!mApp.getResources().getBoolean( |
| 7678 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7679 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7680 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7681 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7682 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7683 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7684 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7685 | } |
| 7686 | |
| 7687 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7688 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7689 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7690 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7691 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7692 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7693 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7694 | if (phone == null) { |
| 7695 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7696 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7697 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7698 | if (cpt == null) { |
| 7699 | continue; |
| 7700 | } |
| 7701 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7702 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7703 | break; |
| 7704 | } |
| 7705 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7706 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7707 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7708 | |
| 7709 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7710 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7711 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7712 | |
| 7713 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7714 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7715 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7716 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7717 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7718 | if (phone == null) { |
| 7719 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7720 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7721 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7722 | if (cpt == null) { |
| 7723 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7724 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7725 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7726 | } |
| 7727 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7728 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7729 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7730 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7731 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7732 | if (phone == null) { |
| 7733 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7734 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7735 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7736 | if (cpt == null) { |
| 7737 | return Collections.emptyList(); |
| 7738 | } |
| 7739 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7740 | } |
| 7741 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7742 | @Override |
| 7743 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7744 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7745 | |
| 7746 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7747 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7748 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7749 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7750 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7751 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7752 | try { |
| 7753 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7754 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7755 | } |
| 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7758 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7759 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7762 | @Override |
| 7763 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7764 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7765 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7766 | if (!mApp.getResources().getBoolean( |
| 7767 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7768 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7769 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7770 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7771 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7772 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7773 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7774 | if (phone == null) { |
| 7775 | return null; |
| 7776 | } |
| 7777 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7778 | if (cpt == null) { |
| 7779 | return null; |
| 7780 | } |
| 7781 | return cpt.getCarrierServicePackageName(); |
| 7782 | } |
| 7783 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7784 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7785 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7786 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7787 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7788 | return null; |
| 7789 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7790 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7791 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7792 | return null; |
| 7793 | } |
| 7794 | return iccId; |
| 7795 | } |
| 7796 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7797 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7798 | public void setCallComposerStatus(int subId, int status) { |
| 7799 | enforceModifyPermission(); |
| 7800 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7801 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7802 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7803 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7804 | final long identity = Binder.clearCallingIdentity(); |
| 7805 | try { |
| 7806 | Phone phone = getPhone(subId); |
| 7807 | if (phone != null) { |
| 7808 | Phone defaultPhone = phone.getImsPhone(); |
| 7809 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7810 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7811 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7812 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7813 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7814 | } |
| 7815 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7816 | } catch (ImsException e) { |
| 7817 | throw new ServiceSpecificException(e.getCode()); |
| 7818 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7819 | Binder.restoreCallingIdentity(identity); |
| 7820 | } |
| 7821 | } |
| 7822 | |
| 7823 | @Override |
| 7824 | public int getCallComposerStatus(int subId) { |
| 7825 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7826 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7827 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7828 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7829 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7830 | final long identity = Binder.clearCallingIdentity(); |
| 7831 | try { |
| 7832 | Phone phone = getPhone(subId); |
| 7833 | if (phone != null) { |
| 7834 | Phone defaultPhone = phone.getImsPhone(); |
| 7835 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7836 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7837 | return imsPhone.getCallComposerStatus(); |
| 7838 | } |
| 7839 | } |
| 7840 | } finally { |
| 7841 | Binder.restoreCallingIdentity(identity); |
| 7842 | } |
| 7843 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7844 | } |
| 7845 | |
| 7846 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7847 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7848 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7849 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7850 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7851 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7852 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7853 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7854 | "setLine1NumberForDisplayForSubscriber"); |
| 7855 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | final String iccId = getIccId(subId); |
| 7859 | final Phone phone = getPhone(subId); |
| 7860 | if (phone == null) { |
| 7861 | return false; |
| 7862 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7863 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7864 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7865 | return false; |
| 7866 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7867 | final String subscriberId = phone.getSubscriberId(); |
| 7868 | |
| 7869 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7870 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7871 | + subscriberId + " to " + number); |
| 7872 | } |
| 7873 | |
| 7874 | if (TextUtils.isEmpty(iccId)) { |
| 7875 | return false; |
| 7876 | } |
| 7877 | |
| 7878 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7879 | |
| 7880 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7881 | if (alphaTag == null) { |
| 7882 | editor.remove(alphaTagPrefKey); |
| 7883 | } else { |
| 7884 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7885 | } |
| 7886 | |
| 7887 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7888 | // track all merged IMSIs based on line number |
| 7889 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7890 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7891 | if (number == null) { |
| 7892 | editor.remove(numberPrefKey); |
| 7893 | editor.remove(subscriberPrefKey); |
| 7894 | } else { |
| 7895 | editor.putString(numberPrefKey, number); |
| 7896 | editor.putString(subscriberPrefKey, subscriberId); |
| 7897 | } |
| 7898 | |
| 7899 | editor.commit(); |
| 7900 | return true; |
| 7901 | } finally { |
| 7902 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7903 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7907 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7908 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7909 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7910 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7911 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7912 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7913 | return null; |
| 7914 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7915 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7916 | enforceTelephonyFeatureWithException(callingPackage, |
| 7917 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7918 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7919 | final long identity = Binder.clearCallingIdentity(); |
| 7920 | try { |
| 7921 | String iccId = getIccId(subId); |
| 7922 | if (iccId != null) { |
| 7923 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7924 | if (DBG_MERGE) { |
| 7925 | log("getLine1NumberForDisplay returning " |
| 7926 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7927 | } |
| 7928 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7929 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7930 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7931 | return null; |
| 7932 | } finally { |
| 7933 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7934 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7938 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7939 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7940 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7941 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7942 | return null; |
| 7943 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7945 | final long identity = Binder.clearCallingIdentity(); |
| 7946 | try { |
| 7947 | String iccId = getIccId(subId); |
| 7948 | if (iccId != null) { |
| 7949 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7950 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7951 | } |
| 7952 | return null; |
| 7953 | } finally { |
| 7954 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7955 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7956 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7957 | |
| 7958 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7959 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7960 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7961 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7962 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7964 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7965 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7966 | return null; |
| 7967 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7968 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7969 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7970 | // the process, where TelephonyManager was instantiated. |
| 7971 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7972 | final long identity = Binder.clearCallingIdentity(); |
| 7973 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7974 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7976 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7977 | |
| 7978 | // Figure out what subscribers are currently active |
| 7979 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7980 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7981 | // Only consider subs which match the current subId |
| 7982 | // This logic can be simplified. See b/131189269 for progress. |
| 7983 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7984 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | |
| 7987 | // First pass, find a number override for an active subscriber |
| 7988 | String mergeNumber = null; |
| 7989 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7990 | for (String key : prefs.keySet()) { |
| 7991 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7992 | final String subscriberId = (String) prefs.get(key); |
| 7993 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7994 | final String iccId = key.substring( |
| 7995 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7996 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7997 | mergeNumber = (String) prefs.get(numberKey); |
| 7998 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7999 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8000 | + " for active subscriber " + subscriberId); |
| 8001 | } |
| 8002 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8003 | break; |
| 8004 | } |
| 8005 | } |
| 8006 | } |
| 8007 | } |
| 8008 | |
| 8009 | // Shortcut when no active merged subscribers |
| 8010 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8011 | return null; |
| 8012 | } |
| 8013 | |
| 8014 | // Second pass, find all subscribers under that line override |
| 8015 | final ArraySet<String> result = new ArraySet<>(); |
| 8016 | for (String key : prefs.keySet()) { |
| 8017 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8018 | final String number = (String) prefs.get(key); |
| 8019 | if (mergeNumber.equals(number)) { |
| 8020 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8021 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8022 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8023 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8024 | result.add(subscriberId); |
| 8025 | } |
| 8026 | } |
| 8027 | } |
| 8028 | } |
| 8029 | |
| 8030 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8031 | Arrays.sort(resultArray); |
| 8032 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8033 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8034 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8035 | } |
| 8036 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8037 | } finally { |
| 8038 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8039 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
| 8042 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8043 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8044 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8045 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8046 | enforceTelephonyFeatureWithException(callingPackage, |
| 8047 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8048 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8049 | final long identity = Binder.clearCallingIdentity(); |
| 8050 | try { |
| 8051 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8052 | TelephonyManager.class); |
| 8053 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8054 | if (subscriberId == null) { |
| 8055 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8056 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8057 | + subId); |
| 8058 | } |
| 8059 | return null; |
| 8060 | } |
| 8061 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8062 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8063 | .getSubscriptionInfo(subId); |
| 8064 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8065 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8066 | if (groupUuid == null) { |
| 8067 | return new String[]{subscriberId}; |
| 8068 | } |
| 8069 | |
| 8070 | // Get all subscriberIds from the group. |
| 8071 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8072 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8073 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8074 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8075 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8076 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8077 | if (subscriberId != null) { |
| 8078 | mergedSubscriberIds.add(subscriberId); |
| 8079 | } |
| 8080 | } |
| 8081 | |
| 8082 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8083 | } finally { |
| 8084 | Binder.restoreCallingIdentity(identity); |
| 8085 | |
| 8086 | } |
| 8087 | } |
| 8088 | |
| 8089 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8090 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8091 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8092 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8093 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8094 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8095 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8096 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8097 | final long identity = Binder.clearCallingIdentity(); |
| 8098 | try { |
| 8099 | final Phone phone = getPhone(subId); |
| 8100 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8101 | } finally { |
| 8102 | Binder.restoreCallingIdentity(identity); |
| 8103 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8104 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8105 | |
| 8106 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8107 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8108 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8109 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8110 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8111 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8112 | |
| 8113 | final long identity = Binder.clearCallingIdentity(); |
| 8114 | try { |
| 8115 | final Phone phone = getPhone(subId); |
| 8116 | if (phone == null) { |
| 8117 | return false; |
| 8118 | } |
| 8119 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8120 | cdmaNonRoamingList); |
| 8121 | } finally { |
| 8122 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8123 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8124 | } |
| 8125 | |
| 8126 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8127 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8128 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8129 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8130 | if (phone == null) { |
| 8131 | return raf; |
| 8132 | } |
| 8133 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8134 | try { |
| 8135 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8136 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8137 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8138 | } catch (SecurityException e) { |
| 8139 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8140 | throw e; |
| 8141 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8142 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8143 | if (!mApp.getResources().getBoolean( |
| 8144 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8145 | enforceTelephonyFeatureWithException(callingPackage, |
| 8146 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8147 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | final long identity = Binder.clearCallingIdentity(); |
| 8150 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8151 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | } finally { |
| 8153 | Binder.restoreCallingIdentity(identity); |
| 8154 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8155 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8156 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8157 | |
| 8158 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8159 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8160 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8161 | if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) { |
| 8162 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8163 | "Invalid package:" + callingPackage); |
| 8164 | } else { |
| 8165 | try { |
| 8166 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8167 | Binder.getCallingUid())) { |
| 8168 | throw new SecurityException("Invalid package:" + callingPackage); |
| 8169 | } |
| 8170 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8171 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8172 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8173 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8174 | |
| 8175 | enforceTelephonyFeatureWithException(callingPackage, |
| 8176 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8177 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8178 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8179 | List<String> dialerRoleHolders; |
| 8180 | if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) { |
| 8181 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8182 | UserHandle.of(ActivityManager.getCurrentUser())); |
| 8183 | } else { |
| 8184 | dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8185 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8186 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8187 | throw new SecurityException("App must be the dialer role holder to" |
| 8188 | + " upload a call composer pic"); |
| 8189 | } |
| 8190 | |
| 8191 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8192 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8193 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8194 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8195 | boolean readUntilEnd = false; |
| 8196 | int totalBytesRead = 0; |
| 8197 | byte[] buffer = new byte[16 * 1024]; |
| 8198 | while (true) { |
| 8199 | int numRead; |
| 8200 | try { |
| 8201 | numRead = input.read(buffer); |
| 8202 | } catch (IOException e) { |
| 8203 | try { |
| 8204 | fd.checkError(); |
| 8205 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8206 | null); |
| 8207 | } catch (IOException e1) { |
| 8208 | // This means that the other side closed explicitly with an error. If this |
| 8209 | // happens, log and ignore. |
| 8210 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8211 | } |
| 8212 | break; |
| 8213 | } |
| 8214 | if (numRead == -1) { |
| 8215 | readUntilEnd = true; |
| 8216 | break; |
| 8217 | } |
| 8218 | totalBytesRead += numRead; |
| 8219 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8220 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8221 | try { |
| 8222 | input.close(); |
| 8223 | } catch (IOException e) { |
| 8224 | // ignore |
| 8225 | } |
| 8226 | break; |
| 8227 | } |
| 8228 | output.write(buffer, 0, numRead); |
| 8229 | } |
| 8230 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8231 | // close is above, where the picture size is too big. |
| 8232 | |
| 8233 | try { |
| 8234 | fd.checkError(); |
| 8235 | } catch (IOException e) { |
| 8236 | loge("Remote end for call composer closed with an error: " + e); |
| 8237 | return; |
| 8238 | } |
| 8239 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8240 | if (!readUntilEnd) { |
| 8241 | loge("Did not finish reading entire image; aborting"); |
| 8242 | return; |
| 8243 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8244 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8245 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8246 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8247 | new CallComposerPictureTransfer.Factory() {}, |
| 8248 | imageData, |
| 8249 | (result) -> { |
| 8250 | if (result.first != null) { |
| 8251 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8252 | Bundle outputResult = new Bundle(); |
| 8253 | outputResult.putParcelable( |
| 8254 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8255 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8256 | outputResult); |
| 8257 | } else { |
| 8258 | callback.send(result.second, null); |
| 8259 | } |
| 8260 | } |
| 8261 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8262 | }); |
| 8263 | } |
| 8264 | |
| 8265 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8266 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8267 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8268 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8270 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8271 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8275 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8276 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
| 8282 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8283 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8284 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8286 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8287 | return false; |
| 8288 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8289 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8290 | enforceTelephonyFeatureWithException(callingPackage, |
| 8291 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | final long identity = Binder.clearCallingIdentity(); |
| 8294 | try { |
| 8295 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8296 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8297 | // In the long run, we may instead need to check if there exists a connection service |
| 8298 | // which can support video calling. |
| 8299 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8300 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | return imsManager.isVtEnabledByPlatform() |
| 8302 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8303 | && imsManager.isVtEnabledByUser(); |
| 8304 | } finally { |
| 8305 | Binder.restoreCallingIdentity(identity); |
| 8306 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8307 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8308 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8309 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8310 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8311 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8313 | mApp, subId, callingPackage, callingFeatureId, |
| 8314 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | return false; |
| 8316 | } |
| 8317 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8318 | enforceTelephonyFeatureWithException(callingPackage, |
| 8319 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8320 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8321 | final long identity = Binder.clearCallingIdentity(); |
| 8322 | try { |
| 8323 | CarrierConfigManager configManager = |
| 8324 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8325 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8326 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8327 | } finally { |
| 8328 | Binder.restoreCallingIdentity(identity); |
| 8329 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8333 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8335 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | return false; |
| 8337 | } |
| 8338 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8339 | enforceTelephonyFeatureWithException(callingPackage, |
| 8340 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8342 | final long identity = Binder.clearCallingIdentity(); |
| 8343 | try { |
| 8344 | CarrierConfigManager configManager = |
| 8345 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8346 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8347 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8348 | } finally { |
| 8349 | Binder.restoreCallingIdentity(identity); |
| 8350 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8351 | } |
| 8352 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8353 | @Override |
| 8354 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8355 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8356 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8357 | } |
| 8358 | |
| 8359 | @Override |
| 8360 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8362 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8364 | final long identity = Binder.clearCallingIdentity(); |
| 8365 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8366 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
| 8369 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8370 | } |
| 8371 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8372 | /** |
| 8373 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8374 | * support for the feature and device firmware support. |
| 8375 | * |
| 8376 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8377 | */ |
| 8378 | @Override |
| 8379 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8381 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8384 | final Phone phone = getPhone(subscriptionId); |
| 8385 | if (phone == null) { |
| 8386 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8387 | return false; |
| 8388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8390 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8392 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8393 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8394 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8395 | return isCarrierSupported && isDeviceSupported; |
| 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
| 8398 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8399 | } |
| 8400 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8401 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8402 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8403 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8404 | * Otherwise. only returns true if the device and carrier both also support RTT. |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8405 | */ |
| 8406 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | final long identity = Binder.clearCallingIdentity(); |
| 8408 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8409 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8410 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8411 | return false; |
| 8412 | } |
| 8413 | } |
| 8414 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8415 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8416 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8417 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8418 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8419 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8420 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8421 | } finally { |
| 8422 | Binder.restoreCallingIdentity(identity); |
| 8423 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8426 | @Deprecated |
| 8427 | @Override |
| 8428 | public String getDeviceId(String callingPackage) { |
| 8429 | return getDeviceIdWithFeature(callingPackage, null); |
| 8430 | } |
| 8431 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8432 | /** |
| 8433 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8434 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8435 | * |
| 8436 | * <p>Requires Permission: |
| 8437 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8438 | */ |
| 8439 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8440 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8441 | try { |
| 8442 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8443 | } catch (SecurityException se) { |
| 8444 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8445 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8446 | + Binder.getCallingUid()); |
| 8447 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8448 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8449 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8450 | return null; |
| 8451 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8452 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8453 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8454 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8455 | return null; |
| 8456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8457 | |
| 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | return phone.getDeviceId(); |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8464 | } |
| 8465 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8466 | /** |
| 8467 | * {@hide} |
| 8468 | * Returns the IMS Registration Status on a particular subid |
| 8469 | * |
| 8470 | * @param subId |
| 8471 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8472 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8473 | Phone phone = getPhone(subId); |
| 8474 | if (phone != null) { |
| 8475 | return phone.isImsRegistered(); |
| 8476 | } else { |
| 8477 | return false; |
| 8478 | } |
| 8479 | } |
| 8480 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8481 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8482 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8483 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8484 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8485 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8486 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8487 | } |
| 8488 | final long identity = Binder.clearCallingIdentity(); |
| 8489 | try { |
| 8490 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8491 | } finally { |
| 8492 | Binder.restoreCallingIdentity(identity); |
| 8493 | } |
| 8494 | } |
| 8495 | |
| 8496 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8497 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8498 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8499 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8500 | mApp, |
| 8501 | subscriptionId, |
| 8502 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8503 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8504 | |
| 8505 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8506 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8507 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8508 | final long identity = Binder.clearCallingIdentity(); |
| 8509 | try { |
| 8510 | Phone phone = getPhone(subscriptionId); |
| 8511 | if (phone == null) { |
| 8512 | return null; |
| 8513 | } |
| 8514 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8515 | } finally { |
| 8516 | Binder.restoreCallingIdentity(identity); |
| 8517 | } |
| 8518 | } |
| 8519 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8520 | /** |
| 8521 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8522 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8523 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | final long identity = Binder.clearCallingIdentity(); |
| 8525 | try { |
| 8526 | Phone phone = getPhone(subId); |
| 8527 | if (phone != null) { |
| 8528 | return phone.isWifiCallingEnabled(); |
| 8529 | } else { |
| 8530 | return false; |
| 8531 | } |
| 8532 | } finally { |
| 8533 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8534 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8535 | } |
| 8536 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8537 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8538 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8539 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8540 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | Phone phone = getPhone(subId); |
| 8544 | if (phone != null) { |
| 8545 | return phone.isVideoEnabled(); |
| 8546 | } else { |
| 8547 | return false; |
| 8548 | } |
| 8549 | } finally { |
| 8550 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8551 | } |
| 8552 | } |
| 8553 | |
| 8554 | /** |
| 8555 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8556 | * defined in {@link ImsRegistrationImplBase}. |
| 8557 | */ |
| 8558 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8559 | final long identity = Binder.clearCallingIdentity(); |
| 8560 | try { |
| 8561 | Phone phone = getPhone(subId); |
| 8562 | if (phone != null) { |
| 8563 | return phone.getImsRegistrationTech(); |
| 8564 | } else { |
| 8565 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8566 | } |
| 8567 | } finally { |
| 8568 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8569 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8572 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8573 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8574 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8575 | |
| 8576 | enforceTelephonyFeatureWithException(callingPackage, |
| 8577 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8578 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8579 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8580 | return; |
| 8581 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8582 | Phone defaultPhone = getDefaultPhone(); |
| 8583 | if (defaultPhone != null) { |
| 8584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8585 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8586 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8587 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8588 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8589 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8590 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8591 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8592 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8593 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8594 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8595 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8596 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8597 | setDataRoamingEnabled(subId, phone == null ? false |
| 8598 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8599 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8600 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8601 | // There has been issues when Sms raw table somehow stores orphan |
| 8602 | // fragments. They lead to garbled message when new fragments come |
| 8603 | // in and combined with those stale ones. In case this happens again, |
| 8604 | // user can reset all network settings which will clean up this table. |
| 8605 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8606 | // Clean up IMS settings as well here. |
| 8607 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8608 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8609 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8610 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8611 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8612 | if (defaultPhone == null) { |
| 8613 | return; |
| 8614 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8615 | // Erase modem config if erase modem on network setting is enabled. |
| 8616 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8617 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8618 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8619 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8620 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8621 | |
| 8622 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8623 | } finally { |
| 8624 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8625 | } |
| 8626 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8627 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8628 | @VisibleForTesting |
| 8629 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8630 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8631 | return; |
| 8632 | } |
| 8633 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8634 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8635 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8636 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8637 | "user=" + defaultNetworkType); |
| 8638 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8639 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8640 | defaultNetworkType, null); |
| 8641 | } |
| 8642 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8643 | private void cleanUpSmsRawTable(Context context) { |
| 8644 | ContentResolver resolver = context.getContentResolver(); |
| 8645 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8646 | resolver.delete(uri, null, null); |
| 8647 | } |
| 8648 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8649 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8650 | public String getSimLocaleForSubscriber(int subId) { |
| 8651 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8652 | |
| 8653 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8654 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8655 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8656 | final Phone phone = getPhone(subId); |
| 8657 | if (phone == null) { |
| 8658 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8659 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8661 | final long identity = Binder.clearCallingIdentity(); |
| 8662 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8663 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8664 | phone.getContext().getOpPackageName(), |
| 8665 | phone.getContext().getAttributionTag()); |
| 8666 | if (info == null) { |
| 8667 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8668 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8669 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8670 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8671 | // preferences (EF-PL and EF-LI)... |
| 8672 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8673 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8674 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8675 | if (localeFromDefaultSim != null) { |
| 8676 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8677 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8678 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8679 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8680 | } else { |
| 8681 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8682 | } |
| 8683 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8684 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8685 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8686 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8687 | // the SIM and carrier preferences does not include a country we add the country |
| 8688 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8689 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8690 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8691 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8692 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | if (DBG) log("No locale found - returning null"); |
| 8696 | return null; |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8700 | } |
| 8701 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8702 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8703 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8704 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8705 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8706 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8707 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8708 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8709 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8710 | return localeTag; |
| 8711 | } |
| 8712 | } |
| 8713 | return inputLocale.toLanguageTag(); |
| 8714 | } |
| 8715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8716 | /** |
| 8717 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8718 | */ |
| 8719 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8720 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8721 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8722 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8723 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8724 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8725 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8726 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8727 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8728 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8729 | * representing the state of the modem. |
| 8730 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8731 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8732 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8733 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8734 | */ |
| 8735 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8736 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8737 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8738 | |
| 8739 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8740 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8741 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8742 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8743 | |
| 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8746 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8747 | } finally { |
| 8748 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8749 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8750 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8751 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8752 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8753 | // less than total activity duration. |
| 8754 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8755 | if (info == null) { |
| 8756 | return false; |
| 8757 | } |
| 8758 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8759 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8760 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8761 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8762 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8763 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8764 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8765 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8766 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8767 | } |
| 8768 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8769 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8770 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8771 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8772 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8773 | |
| 8774 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8775 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8776 | } |
| 8777 | |
| 8778 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8779 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8780 | rat, |
| 8781 | freq, |
| 8782 | info.getReceiveTimeMillis(rat, freq) |
| 8783 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8784 | } |
| 8785 | |
| 8786 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8787 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8788 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8789 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8790 | |
| 8791 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8792 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8793 | } |
| 8794 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8795 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8796 | rat, |
| 8797 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8798 | } |
| 8799 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8800 | /** |
| 8801 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8802 | * @param info recent ModemActivityInfo |
| 8803 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8804 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8805 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8806 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8807 | boolean matched; |
| 8808 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8809 | matched = false; |
| 8810 | int rat = info.getSpecificInfoRat(i); |
| 8811 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8812 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8813 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8814 | //if it already exists |
| 8815 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8816 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8817 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8818 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8819 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8820 | updateLastModemActivityInfo(info, rat, freq); |
| 8821 | matched = true; |
| 8822 | } |
| 8823 | } else { |
| 8824 | updateLastModemActivityInfo(info, rat); |
| 8825 | matched = true; |
| 8826 | } |
| 8827 | } |
| 8828 | } |
| 8829 | |
| 8830 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8831 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8832 | new ActivityStatsTechSpecificInfo( |
| 8833 | rat, |
| 8834 | freq, |
| 8835 | info.getTransmitTimeMillis(rat, freq), |
| 8836 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8837 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8838 | } |
| 8839 | } |
| 8840 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8841 | mLastModemActivitySpecificInfo = |
| 8842 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8843 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8844 | |
| 8845 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8846 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8847 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8848 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8849 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8850 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8851 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8852 | |
| 8853 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8854 | new ModemActivityInfo( |
| 8855 | mLastModemActivityInfo.getTimestampMillis(), |
| 8856 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8857 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8858 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8859 | } |
| 8860 | |
| 8861 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8862 | ActivityStatsTechSpecificInfo[] info) { |
| 8863 | int infoSize = info.length; |
| 8864 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8865 | for (int i = 0; i < infoSize; i++) { |
| 8866 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8867 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8868 | info[i].getTransmitTimeMillis(), |
| 8869 | (int) info[i].getReceiveTimeMillis()); |
| 8870 | } |
| 8871 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8872 | } |
| 8873 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8874 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8875 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8876 | */ |
| 8877 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8878 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8879 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8880 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8881 | if (phone == null) { |
| 8882 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8883 | return null; |
| 8884 | } |
| 8885 | |
| 8886 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8887 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8888 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8889 | return null; |
| 8890 | } |
| 8891 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8892 | enforceTelephonyFeatureWithException(callingPackage, |
| 8893 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8894 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8895 | boolean hasFinePermission = false; |
| 8896 | boolean hasCoarsePermission = false; |
| 8897 | if (!renounceFineLocationAccess) { |
| 8898 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8899 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8900 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8901 | .setCallingPackage(callingPackage) |
| 8902 | .setCallingFeatureId(callingFeatureId) |
| 8903 | .setCallingPid(Binder.getCallingPid()) |
| 8904 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8905 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8906 | .setLogAsInfo(true) |
| 8907 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8908 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8909 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8910 | .build()); |
| 8911 | hasFinePermission = |
| 8912 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8913 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8914 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8915 | if (!renounceCoarseLocationAccess) { |
| 8916 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8917 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8918 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8919 | .setCallingPackage(callingPackage) |
| 8920 | .setCallingFeatureId(callingFeatureId) |
| 8921 | .setCallingPid(Binder.getCallingPid()) |
| 8922 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8923 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8924 | .setLogAsInfo(true) |
| 8925 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8926 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8927 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8928 | .build()); |
| 8929 | hasCoarsePermission = |
| 8930 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8931 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8932 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8933 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8934 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8935 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8936 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8937 | if (subInfo != null && !subInfo.isActive()) { |
| 8938 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8939 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8940 | } |
| 8941 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8942 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8943 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8944 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8945 | |
| 8946 | // Scrub out the location info in ServiceState depending on what level of access |
| 8947 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8948 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8949 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8950 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8951 | } finally { |
| 8952 | Binder.restoreCallingIdentity(identity); |
| 8953 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8954 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8955 | |
| 8956 | /** |
| 8957 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8958 | * |
| 8959 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8960 | * voicemail ringtone. |
| 8961 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8962 | * PhoneAccount. |
| 8963 | */ |
| 8964 | @Override |
| 8965 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8966 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8967 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8969 | final long identity = Binder.clearCallingIdentity(); |
| 8970 | try { |
| 8971 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8972 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8973 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8974 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8975 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8976 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8977 | } finally { |
| 8978 | Binder.restoreCallingIdentity(identity); |
| 8979 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8980 | } |
| 8981 | |
| 8982 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8983 | * Sets the per-account voicemail ringtone. |
| 8984 | * |
| 8985 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8986 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8987 | * |
| 8988 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8989 | * voicemail ringtone. |
| 8990 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8991 | * PhoneAccount. |
| 8992 | */ |
| 8993 | @Override |
| 8994 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8995 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8996 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8997 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8998 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8999 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9001 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9002 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9003 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9004 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9005 | enforceTelephonyFeatureWithException(callingPackage, |
| 9006 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9008 | final long identity = Binder.clearCallingIdentity(); |
| 9009 | try { |
| 9010 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9011 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9012 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9013 | } |
| 9014 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9015 | } finally { |
| 9016 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9017 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9018 | } |
| 9019 | |
| 9020 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9021 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9022 | * |
| 9023 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9024 | * voicemail vibration setting. |
| 9025 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9026 | */ |
| 9027 | @Override |
| 9028 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9029 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9030 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9032 | final long identity = Binder.clearCallingIdentity(); |
| 9033 | try { |
| 9034 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9035 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9036 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9037 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9038 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9039 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9040 | } finally { |
| 9041 | Binder.restoreCallingIdentity(identity); |
| 9042 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9043 | } |
| 9044 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9045 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9046 | * Sets the per-account voicemail vibration. |
| 9047 | * |
| 9048 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9049 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9050 | * |
| 9051 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9052 | * voicemail vibration setting. |
| 9053 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9054 | * specific PhoneAccount. |
| 9055 | */ |
| 9056 | @Override |
| 9057 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9058 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9059 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9060 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9061 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9062 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9064 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9065 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9066 | } |
| 9067 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9068 | enforceTelephonyFeatureWithException(callingPackage, |
| 9069 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | final long identity = Binder.clearCallingIdentity(); |
| 9072 | try { |
| 9073 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9074 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9075 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9076 | } |
| 9077 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9078 | } finally { |
| 9079 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9080 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9081 | } |
| 9082 | |
| 9083 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9084 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9085 | * |
| 9086 | * @throws SecurityException if the caller does not have the required permission |
| 9087 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9088 | @VisibleForTesting |
| 9089 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9090 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9091 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9092 | } |
| 9093 | |
| 9094 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9095 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9096 | * permission. |
| 9097 | * |
| 9098 | * @throws SecurityException if the caller does not have the required permission |
| 9099 | */ |
| 9100 | private void enforceSendSmsPermission() { |
| 9101 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9102 | } |
| 9103 | |
| 9104 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9105 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9106 | * users permission. |
| 9107 | * |
| 9108 | * @throws SecurityException if the caller does not have the required permission |
| 9109 | */ |
| 9110 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9111 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9112 | } |
| 9113 | |
| 9114 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9115 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9116 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9117 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9118 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9119 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9120 | final long identity = Binder.clearCallingIdentity(); |
| 9121 | try { |
| 9122 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9123 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9124 | if (componentName == null) { |
| 9125 | throw new SecurityException( |
| 9126 | "Caller not current active visual voicemail package[null]"); |
| 9127 | } |
| 9128 | String vvmPackage = componentName.getPackageName(); |
| 9129 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9130 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9131 | } |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9138 | * Return the application ID for the app type. |
| 9139 | * |
| 9140 | * @param subId the subscription ID that this request applies to. |
| 9141 | * @param appType the uicc app type. |
| 9142 | * @return Application ID for specificied app type, or null if no uicc. |
| 9143 | */ |
| 9144 | @Override |
| 9145 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9146 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9147 | |
| 9148 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9149 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9150 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9151 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9152 | |
| 9153 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9154 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9155 | if (phone == null) { |
| 9156 | return null; |
| 9157 | } |
| 9158 | String aid = null; |
| 9159 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9160 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9161 | .getApplicationByType(appType).getAid(); |
| 9162 | } catch (Exception e) { |
| 9163 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9164 | } |
| 9165 | return aid; |
| 9166 | } finally { |
| 9167 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9168 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9169 | } |
| 9170 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9171 | /** |
| 9172 | * Return the Electronic Serial Number. |
| 9173 | * |
| 9174 | * @param subId the subscription ID that this request applies to. |
| 9175 | * @return ESN or null if error. |
| 9176 | */ |
| 9177 | @Override |
| 9178 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9179 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9180 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9181 | |
| 9182 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9183 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9184 | if (phone == null) { |
| 9185 | return null; |
| 9186 | } |
| 9187 | String esn = null; |
| 9188 | try { |
| 9189 | esn = phone.getEsn(); |
| 9190 | } catch (Exception e) { |
| 9191 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9192 | } |
| 9193 | return esn; |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9196 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9197 | } |
| 9198 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9199 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9200 | * Return the Preferred Roaming List Version. |
| 9201 | * |
| 9202 | * @param subId the subscription ID that this request applies to. |
| 9203 | * @return PRLVersion or null if error. |
| 9204 | */ |
| 9205 | @Override |
| 9206 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9207 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9208 | |
| 9209 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9210 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9211 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9212 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9213 | |
| 9214 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9215 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9216 | if (phone == null) { |
| 9217 | return null; |
| 9218 | } |
| 9219 | String cdmaPrlVersion = null; |
| 9220 | try { |
| 9221 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9222 | } catch (Exception e) { |
| 9223 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9224 | } |
| 9225 | return cdmaPrlVersion; |
| 9226 | } finally { |
| 9227 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9228 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9232 | * Get snapshot of Telephony histograms |
| 9233 | * @return List of Telephony histograms |
| 9234 | * @hide |
| 9235 | */ |
| 9236 | @Override |
| 9237 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9239 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9240 | |
| 9241 | final long identity = Binder.clearCallingIdentity(); |
| 9242 | try { |
| 9243 | return RIL.getTelephonyRILTimingHistograms(); |
| 9244 | } finally { |
| 9245 | Binder.restoreCallingIdentity(identity); |
| 9246 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9247 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9248 | |
| 9249 | /** |
| 9250 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9251 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9252 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9253 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9254 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9255 | * @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] | 9256 | */ |
| 9257 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9258 | @TelephonyManager.SetCarrierRestrictionResult |
| 9259 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9260 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9261 | |
| 9262 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9263 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9264 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9265 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9266 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9267 | if (carrierRestrictionRules == null) { |
| 9268 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9269 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9270 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9273 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9274 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9275 | } finally { |
| 9276 | Binder.restoreCallingIdentity(identity); |
| 9277 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9278 | } |
| 9279 | |
| 9280 | /** |
| 9281 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9282 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9283 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9284 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9285 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9286 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9287 | */ |
| 9288 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9289 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9290 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9291 | |
| 9292 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9293 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9294 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9295 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9296 | |
| 9297 | final long identity = Binder.clearCallingIdentity(); |
| 9298 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9299 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9300 | if (response instanceof CarrierRestrictionRules) { |
| 9301 | return (CarrierRestrictionRules) response; |
| 9302 | } |
| 9303 | // Response is an Exception of some kind, |
| 9304 | // which is signalled to the user as a NULL retval |
| 9305 | return null; |
| 9306 | } catch (Exception e) { |
| 9307 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9308 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9309 | } finally { |
| 9310 | Binder.restoreCallingIdentity(identity); |
| 9311 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9312 | } |
| 9313 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9314 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9315 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9316 | * through the callback. |
| 9317 | * |
| 9318 | * @param callback The callback that will be used to send the result. |
| 9319 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9320 | * the caller is not allowlisted. |
| 9321 | */ |
| 9322 | @Override |
| 9323 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9324 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9325 | |
| 9326 | enforceTelephonyFeatureWithException(packageName, |
| 9327 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9328 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9329 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9330 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9331 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9332 | throw new SecurityException("Not an authorized caller"); |
| 9333 | } |
| 9334 | final long identity = Binder.clearCallingIdentity(); |
| 9335 | try { |
| 9336 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9337 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9338 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9339 | } finally { |
| 9340 | Binder.restoreCallingIdentity(identity); |
| 9341 | } |
| 9342 | } |
| 9343 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9344 | @Override |
| 9345 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9346 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9347 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9348 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9349 | } |
| 9350 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9351 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9352 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9353 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9354 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9355 | } |
| 9356 | |
| 9357 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9358 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9359 | * @param subId the subscription ID that this action applies to. |
| 9360 | * @param enabled control enable or disable radio. |
| 9361 | * {@hide} |
| 9362 | */ |
| 9363 | @Override |
| 9364 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9365 | enforceModifyPermission(); |
| 9366 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9367 | |
| 9368 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9369 | if (phone == null) { |
| 9370 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9371 | return; |
| 9372 | } |
| 9373 | try { |
| 9374 | phone.carrierActionSetRadioEnabled(enabled); |
| 9375 | } catch (Exception e) { |
| 9376 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9377 | } finally { |
| 9378 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9379 | } |
| 9380 | } |
| 9381 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9382 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9383 | * Enable or disable Voice over NR (VoNR) |
| 9384 | * @param subId the subscription ID that this action applies to. |
| 9385 | * @param enabled enable or disable VoNR. |
| 9386 | * @return operation result. |
| 9387 | */ |
| 9388 | @Override |
| 9389 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9390 | enforceModifyPermission(); |
| 9391 | final Phone phone = getPhone(subId); |
| 9392 | |
| 9393 | final long identity = Binder.clearCallingIdentity(); |
| 9394 | if (phone == null) { |
| 9395 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9396 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9397 | } |
| 9398 | |
| 9399 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9400 | try { |
| 9401 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9402 | workSource); |
| 9403 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9404 | |
| 9405 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9406 | if (DBG) { |
| 9407 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9408 | } |
| 9409 | SubscriptionManager.setSubscriptionProperty( |
| 9410 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9411 | (enabled ? "1" : "0")); |
| 9412 | } |
| 9413 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9414 | return result; |
| 9415 | } finally { |
| 9416 | Binder.restoreCallingIdentity(identity); |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | /** |
| 9421 | * Is voice over NR enabled |
| 9422 | * @return true if VoNR is enabled else false |
| 9423 | */ |
| 9424 | @Override |
| 9425 | public boolean isVoNrEnabled(int subId) { |
| 9426 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9427 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9428 | final long identity = Binder.clearCallingIdentity(); |
| 9429 | try { |
| 9430 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9431 | null, subId, workSource); |
| 9432 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9433 | return isEnabled; |
| 9434 | } finally { |
| 9435 | Binder.restoreCallingIdentity(identity); |
| 9436 | } |
| 9437 | } |
| 9438 | |
| 9439 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9440 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9441 | * network status based on which carrier apps could apply actions accordingly, |
| 9442 | * enable/disable default url handler for example. |
| 9443 | * |
| 9444 | * @param subId the subscription ID that this action applies to. |
| 9445 | * @param report control start/stop reporting the default network status. |
| 9446 | * {@hide} |
| 9447 | */ |
| 9448 | @Override |
| 9449 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9450 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9451 | |
| 9452 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9453 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9454 | "carrierActionReportDefaultNetworkStatus"); |
| 9455 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9456 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9457 | |
| 9458 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9459 | if (phone == null) { |
| 9460 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9461 | return; |
| 9462 | } |
| 9463 | try { |
| 9464 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9465 | } catch (Exception e) { |
| 9466 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9469 | } |
| 9470 | } |
| 9471 | |
| 9472 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9473 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9474 | * @param subId the subscription ID that this action applies to. |
| 9475 | * {@hide} |
| 9476 | */ |
| 9477 | @Override |
| 9478 | public void carrierActionResetAll(int subId) { |
| 9479 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9480 | |
| 9481 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9482 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9483 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9484 | final Phone phone = getPhone(subId); |
| 9485 | if (phone == null) { |
| 9486 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9487 | return; |
| 9488 | } |
| 9489 | try { |
| 9490 | phone.carrierActionResetAll(); |
| 9491 | } catch (Exception e) { |
| 9492 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9493 | } |
| 9494 | } |
| 9495 | |
| 9496 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9497 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9498 | * bug report is being generated. |
| 9499 | */ |
| 9500 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9501 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9502 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9503 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9504 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9505 | + Binder.getCallingPid() |
| 9506 | + ", uid=" + Binder.getCallingUid() |
| 9507 | + "without permission " |
| 9508 | + android.Manifest.permission.DUMP); |
| 9509 | return; |
| 9510 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9511 | try { |
| 9512 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9513 | } catch (Exception e) { |
| 9514 | writer.println("Failed to dump phone information: " + e); |
| 9515 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9516 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9517 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9518 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9519 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9520 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9521 | @NonNull String[] args) { |
| 9522 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9523 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9524 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9525 | } |
| 9526 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9527 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9528 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9529 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9530 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9531 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9532 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9533 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9534 | */ |
| 9535 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9536 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9537 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9538 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9539 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9540 | try { |
| 9541 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9542 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9543 | } catch (SecurityException se) { |
| 9544 | enforceModifyPermission(); |
| 9545 | } |
| 9546 | } else { |
| 9547 | enforceModifyPermission(); |
| 9548 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9549 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9550 | enforceTelephonyFeatureWithException(callingPackage, |
| 9551 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9552 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9553 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9554 | final long identity = Binder.clearCallingIdentity(); |
| 9555 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9556 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9557 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9558 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9559 | callingUid, callingPackage, null, null); |
| 9560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9561 | Phone phone = getPhone(subId); |
| 9562 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9563 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9564 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9565 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9566 | phone.getDataSettingsManager().setDataEnabled( |
| 9567 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9569 | } |
| 9570 | } finally { |
| 9571 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9572 | } |
| 9573 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9574 | |
| 9575 | /** |
| 9576 | * Get Client request stats |
| 9577 | * @return List of Client Request Stats |
| 9578 | * @hide |
| 9579 | */ |
| 9580 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9581 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9582 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9584 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9585 | return null; |
| 9586 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9587 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9589 | final long identity = Binder.clearCallingIdentity(); |
| 9590 | try { |
| 9591 | if (phone != null) { |
| 9592 | return phone.getClientRequestStats(); |
| 9593 | } |
| 9594 | |
| 9595 | return null; |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(identity); |
| 9598 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9599 | } |
| 9600 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9601 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9602 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9603 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9604 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9605 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9606 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9607 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9608 | // commands that plumb through the RIL as root, like so: |
| 9609 | // $ adb root |
| 9610 | // $ adb shell cmd phone ... |
| 9611 | packageName = "root"; |
| 9612 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9613 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9614 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9615 | |
| 9616 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9617 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9618 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9619 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9620 | * @param state State of SIM (power down, power up, pass through) |
| 9621 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9622 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9623 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9624 | * |
| 9625 | **/ |
| 9626 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9627 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9628 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9629 | |
| 9630 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9631 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9632 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9633 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9634 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9635 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9636 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9637 | final long identity = Binder.clearCallingIdentity(); |
| 9638 | try { |
| 9639 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9640 | phone.setSimPowerState(state, null, workSource); |
| 9641 | } |
| 9642 | } finally { |
| 9643 | Binder.restoreCallingIdentity(identity); |
| 9644 | } |
| 9645 | } |
| 9646 | |
| 9647 | /** |
| 9648 | * Set SIM card power state. |
| 9649 | * |
| 9650 | * @param slotIndex SIM slot id. |
| 9651 | * @param state State of SIM (power down, power up, pass through) |
| 9652 | * @param callback callback to trigger after success or failure |
| 9653 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9654 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9655 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9656 | * |
| 9657 | **/ |
| 9658 | @Override |
| 9659 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9660 | IIntegerConsumer callback) { |
| 9661 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9662 | |
| 9663 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9664 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9665 | "setSimPowerStateForSlotWithCallback"); |
| 9666 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9667 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9668 | |
| 9669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9670 | |
| 9671 | final long identity = Binder.clearCallingIdentity(); |
| 9672 | try { |
| 9673 | if (phone != null) { |
| 9674 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9675 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9676 | } |
| 9677 | } finally { |
| 9678 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9679 | } |
| 9680 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9681 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9682 | private boolean isUssdApiAllowed(int subId) { |
| 9683 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9684 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9685 | if (configManager == null) { |
| 9686 | return false; |
| 9687 | } |
| 9688 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9689 | if (pb == null) { |
| 9690 | return false; |
| 9691 | } |
| 9692 | return pb.getBoolean( |
| 9693 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9694 | } |
| 9695 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9696 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9697 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9698 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9699 | * @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] | 9700 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9701 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9702 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9703 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9704 | |
| 9705 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9706 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9707 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9708 | final long identity = Binder.clearCallingIdentity(); |
| 9709 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9710 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9713 | } |
| 9714 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9715 | |
| 9716 | /** |
| 9717 | * Get the current signal strength information for the given subscription. |
| 9718 | * Because this information is not updated when the device is in a low power state |
| 9719 | * it should not be relied-upon to be current. |
| 9720 | * @param subId Subscription index |
| 9721 | * @return the most recent cached signal strength info from the modem |
| 9722 | */ |
| 9723 | @Override |
| 9724 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9725 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9726 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9728 | final long identity = Binder.clearCallingIdentity(); |
| 9729 | try { |
| 9730 | Phone p = getPhone(subId); |
| 9731 | if (p == null) { |
| 9732 | return null; |
| 9733 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9735 | return p.getSignalStrength(); |
| 9736 | } finally { |
| 9737 | Binder.restoreCallingIdentity(identity); |
| 9738 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9739 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9740 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9741 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9742 | * Get the current modem radio state for the given slot. |
| 9743 | * @param slotIndex slot index. |
| 9744 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9745 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9746 | * @return the current radio power state from the modem |
| 9747 | */ |
| 9748 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9749 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9750 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9751 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9752 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9753 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9754 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9755 | } |
| 9756 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9757 | enforceTelephonyFeatureWithException(callingPackage, |
| 9758 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9759 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9760 | final long identity = Binder.clearCallingIdentity(); |
| 9761 | try { |
| 9762 | return phone.getRadioPowerState(); |
| 9763 | } finally { |
| 9764 | Binder.restoreCallingIdentity(identity); |
| 9765 | } |
| 9766 | } |
| 9767 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9768 | } |
| 9769 | |
| 9770 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9771 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9772 | * |
| 9773 | * <p>Requires one of the following permissions: |
| 9774 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9775 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9776 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9777 | * privileges. |
| 9778 | * |
| 9779 | * @param subId subscription id |
| 9780 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9781 | * {@code false}. |
| 9782 | */ |
| 9783 | @Override |
| 9784 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9785 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9786 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9787 | try { |
| 9788 | mApp.enforceCallingOrSelfPermission( |
| 9789 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9790 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9791 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9792 | mApp.enforceCallingOrSelfPermission( |
| 9793 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9794 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9795 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9796 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9797 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9798 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9799 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9800 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9801 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9802 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9803 | boolean isEnabled = false; |
| 9804 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9805 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9806 | Phone phone = getPhone(subId); |
| 9807 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9808 | } finally { |
| 9809 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9810 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9811 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9812 | } |
| 9813 | |
| 9814 | |
| 9815 | /** |
| 9816 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9817 | * |
| 9818 | * <p> Requires permission: |
| 9819 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9820 | * privileges. |
| 9821 | * |
| 9822 | * @param subId subscription id |
| 9823 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9828 | mApp, subId, "setDataRoamingEnabled"); |
| 9829 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9830 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9831 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9832 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9833 | final long identity = Binder.clearCallingIdentity(); |
| 9834 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9835 | Phone phone = getPhone(subId); |
| 9836 | if (phone != null) { |
| 9837 | phone.setDataRoamingEnabled(isEnabled); |
| 9838 | } |
| 9839 | } finally { |
| 9840 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9841 | } |
| 9842 | } |
| 9843 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9844 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9845 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9846 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9847 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9848 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9849 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9850 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9851 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9852 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9853 | boolean isAllowed = true; |
| 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9856 | Phone phone = getPhone(subId); |
| 9857 | if (phone != null) { |
| 9858 | isAllowed = phone.isCspPlmnEnabled(); |
| 9859 | } |
| 9860 | } finally { |
| 9861 | Binder.restoreCallingIdentity(identity); |
| 9862 | } |
| 9863 | return isAllowed; |
| 9864 | } |
| 9865 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9866 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9867 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9868 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9869 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9870 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9871 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9872 | if (phone == null) { |
| 9873 | return false; |
| 9874 | } |
| 9875 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9876 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9877 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9878 | } |
| 9879 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9880 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9881 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9882 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9883 | mApp.getSystemService(AppOpsManager.class) |
| 9884 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9885 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9886 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9887 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9888 | try { |
| 9889 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9890 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9891 | } catch (SecurityException e) { |
| 9892 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9893 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9894 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9895 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9896 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9897 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9898 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9899 | |
| 9900 | enforceTelephonyFeatureWithException(callingPackage, |
| 9901 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9902 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9903 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9904 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9905 | Binder.getCallingUid())) { |
| 9906 | isIccIdAccessRestricted = true; |
| 9907 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9908 | final long identity = Binder.clearCallingIdentity(); |
| 9909 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9910 | UiccController uiccController = UiccController.getInstance(); |
| 9911 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9912 | if (hasReadPermission) { |
| 9913 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9914 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9915 | |
| 9916 | // Remove private info if the caller doesn't have access |
| 9917 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9918 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9919 | //setting the value after compatibility check |
| 9920 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9921 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9922 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9923 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9924 | if (card == null) { |
| 9925 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9926 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9927 | continue; |
| 9928 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9929 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9930 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9931 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9932 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9933 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9934 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9935 | for (UiccPortInfo portInfo : portInfos) { |
| 9936 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9937 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9938 | if (port == null) { |
| 9939 | // assume no access if port is null |
| 9940 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9941 | continue; |
| 9942 | } |
| 9943 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9944 | uiccPortInfos.add(portInfo); |
| 9945 | } else { |
| 9946 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9947 | } |
| 9948 | } |
| 9949 | filteredInfos.add(new UiccCardInfo( |
| 9950 | cardInfo.isEuicc(), |
| 9951 | cardInfo.getCardId(), |
| 9952 | null, |
| 9953 | cardInfo.getPhysicalSlotIndex(), |
| 9954 | cardInfo.isRemovable(), |
| 9955 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9956 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9957 | } |
| 9958 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9959 | } finally { |
| 9960 | Binder.restoreCallingIdentity(identity); |
| 9961 | } |
| 9962 | } |
| 9963 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9964 | /** |
| 9965 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9966 | * generally private and require carrier privileges to view. |
| 9967 | * |
| 9968 | * @hide |
| 9969 | */ |
| 9970 | @NonNull |
| 9971 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9972 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9973 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9974 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9975 | } |
| 9976 | return new UiccCardInfo( |
| 9977 | cardInfo.isEuicc(), |
| 9978 | cardInfo.getCardId(), |
| 9979 | null, |
| 9980 | cardInfo.getPhysicalSlotIndex(), |
| 9981 | cardInfo.isRemovable(), |
| 9982 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9983 | portinfo |
| 9984 | ); |
| 9985 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9986 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9987 | /** |
| 9988 | * @hide |
| 9989 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9990 | * These values are generally private and require carrier privileges to view. |
| 9991 | */ |
| 9992 | @NonNull |
| 9993 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9994 | return new UiccPortInfo( |
| 9995 | UiccPortInfo.ICCID_REDACTED, |
| 9996 | portInfo.getPortIndex(), |
| 9997 | portInfo.getLogicalSlotIndex(), |
| 9998 | portInfo.isActive() |
| 9999 | ); |
| 10000 | } |
| 10001 | @Override |
| 10002 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10003 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10004 | mApp.getSystemService(AppOpsManager.class) |
| 10005 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10006 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10007 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10008 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10009 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10010 | // we are reading iccId which is PII data. |
| 10011 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10012 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10013 | enforceTelephonyFeatureWithException(callingPackage, |
| 10014 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10015 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10016 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10017 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10018 | Binder.getCallingUid())) { |
| 10019 | isLogicalSlotAccessRestricted = true; |
| 10020 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10021 | final long identity = Binder.clearCallingIdentity(); |
| 10022 | try { |
| 10023 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10024 | if (slots == null || slots.length == 0) { |
| 10025 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10026 | return null; |
| 10027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10028 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10029 | for (int i = 0; i < slots.length; i++) { |
| 10030 | UiccSlot slot = slots[i]; |
| 10031 | if (slot == null) { |
| 10032 | continue; |
| 10033 | } |
| 10034 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10035 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10036 | UiccCard card = slot.getUiccCard(); |
| 10037 | if (card != null) { |
| 10038 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10039 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10040 | cardId = slot.getEid(); |
| 10041 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10042 | // If cardId is null, use iccId of default port as cardId. |
| 10043 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10044 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10045 | } |
| 10046 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10047 | if (cardId != null) { |
| 10048 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10049 | // if cardId is an EID, it's all digits so this is fine |
| 10050 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10051 | } |
| 10052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10053 | int cardState = 0; |
| 10054 | switch (slot.getCardState()) { |
| 10055 | case CARDSTATE_ABSENT: |
| 10056 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10057 | break; |
| 10058 | case CARDSTATE_PRESENT: |
| 10059 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10060 | break; |
| 10061 | case CARDSTATE_ERROR: |
| 10062 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10063 | break; |
| 10064 | case CARDSTATE_RESTRICTED: |
| 10065 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10066 | break; |
| 10067 | default: |
| 10068 | break; |
| 10069 | |
| 10070 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10071 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10072 | int[] portIndexes = slot.getPortList(); |
| 10073 | for (int portIdx : portIndexes) { |
| 10074 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10075 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10076 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10077 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10079 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10080 | slot.isEuicc(), |
| 10081 | cardId, |
| 10082 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10083 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10084 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10085 | //setting the value after compatibility check |
| 10086 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10087 | } |
| 10088 | return infos; |
| 10089 | } finally { |
| 10090 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10091 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10092 | } |
| 10093 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10094 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10095 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10096 | boolean hasReadPermission) { |
| 10097 | String iccId = slot.getIccId(portIndex); |
| 10098 | if (hasReadPermission) { // if has read permission |
| 10099 | return iccId; |
| 10100 | } else { |
| 10101 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10102 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10103 | // if no read permission, checking carrier privilege access |
| 10104 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10105 | return iccId; |
| 10106 | } |
| 10107 | } |
| 10108 | } |
| 10109 | // No read permission or carrier privilege access. |
| 10110 | return UiccPortInfo.ICCID_REDACTED; |
| 10111 | } |
| 10112 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10113 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10114 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10115 | public boolean switchSlots(int[] physicalSlots) { |
| 10116 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10117 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10118 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10119 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10120 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10121 | final long identity = Binder.clearCallingIdentity(); |
| 10122 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10123 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10124 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10125 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10126 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10127 | physicalSlots[i], i)); |
| 10128 | } |
| 10129 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10130 | } finally { |
| 10131 | Binder.restoreCallingIdentity(identity); |
| 10132 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10133 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10134 | |
| 10135 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10136 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10137 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10138 | enforceModifyPermission(); |
| 10139 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10140 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10141 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10142 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10143 | final long identity = Binder.clearCallingIdentity(); |
| 10144 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10145 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10146 | } finally { |
| 10147 | Binder.restoreCallingIdentity(identity); |
| 10148 | } |
| 10149 | } |
| 10150 | |
| 10151 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10152 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10153 | enforceTelephonyFeatureWithException(callingPackage, |
| 10154 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10155 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10156 | final long identity = Binder.clearCallingIdentity(); |
| 10157 | try { |
| 10158 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10159 | } finally { |
| 10160 | Binder.restoreCallingIdentity(identity); |
| 10161 | } |
| 10162 | } |
| 10163 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10164 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10165 | * A test API to reload the UICC profile. |
| 10166 | * |
| 10167 | * <p>Requires that the calling app has permission |
| 10168 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10169 | * @hide |
| 10170 | */ |
| 10171 | @Override |
| 10172 | public void refreshUiccProfile(int subId) { |
| 10173 | enforceModifyPermission(); |
| 10174 | |
| 10175 | final long identity = Binder.clearCallingIdentity(); |
| 10176 | try { |
| 10177 | Phone phone = getPhone(subId); |
| 10178 | if (phone == null) { |
| 10179 | return; |
| 10180 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10181 | UiccPort uiccPort = phone.getUiccPort(); |
| 10182 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10183 | return; |
| 10184 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10185 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10186 | if (uiccProfile == null) { |
| 10187 | return; |
| 10188 | } |
| 10189 | uiccProfile.refresh(); |
| 10190 | } finally { |
| 10191 | Binder.restoreCallingIdentity(identity); |
| 10192 | } |
| 10193 | } |
| 10194 | |
| 10195 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10196 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10197 | */ |
| 10198 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10199 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10200 | } |
| 10201 | |
| 10202 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10203 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10204 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10205 | */ |
| 10206 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10207 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10208 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10209 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10210 | return list.get(phoneId); |
| 10211 | } |
| 10212 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10213 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10214 | |
| 10215 | @Override |
| 10216 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10217 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10219 | |
| 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
| 10222 | final Phone phone = getPhone(subId); |
| 10223 | if (phone == null) { |
| 10224 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10225 | return; |
| 10226 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10227 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10228 | if (cpt != null) { |
| 10229 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10230 | } |
| 10231 | // 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] | 10232 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10233 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10234 | if (carrierPrivilegeRules == null) { |
| 10235 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10236 | } else { |
| 10237 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10238 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10239 | } finally { |
| 10240 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10241 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10242 | } |
| 10243 | |
| 10244 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10245 | public void setCarrierServicePackageOverride( |
| 10246 | int subId, String carrierServicePackage, String callingPackage) { |
| 10247 | TelephonyPermissions.enforceShellOnly( |
| 10248 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10249 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10250 | final long identity = Binder.clearCallingIdentity(); |
| 10251 | try { |
| 10252 | final Phone phone = getPhone(subId); |
| 10253 | if (phone == null || phone.getSubId() != subId) { |
| 10254 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10255 | throw new IllegalArgumentException("No phone for subid"); |
| 10256 | } |
| 10257 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10258 | if (cpt == null) { |
| 10259 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10260 | throw new IllegalStateException("No CPT for phone"); |
| 10261 | } |
| 10262 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10263 | } finally { |
| 10264 | Binder.restoreCallingIdentity(identity); |
| 10265 | } |
| 10266 | } |
| 10267 | |
| 10268 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10269 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10270 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10271 | |
| 10272 | final long identity = Binder.clearCallingIdentity(); |
| 10273 | try { |
| 10274 | final Phone phone = getPhone(subId); |
| 10275 | if (phone == null) { |
| 10276 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10277 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10278 | } |
| 10279 | return phone.getCarrierIdListVersion(); |
| 10280 | } finally { |
| 10281 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10282 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10283 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10284 | |
| 10285 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10286 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10287 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10288 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10289 | mApp, subId, callingPackage, callingFeatureId, |
| 10290 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10291 | return -1; |
| 10292 | } |
| 10293 | |
| 10294 | final long identity = Binder.clearCallingIdentity(); |
| 10295 | try { |
| 10296 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
| 10300 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10301 | |
| 10302 | @Override |
| 10303 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10304 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10305 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10306 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10307 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10308 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10309 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10310 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
| 10313 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10314 | } finally { |
| 10315 | Binder.restoreCallingIdentity(identity); |
| 10316 | } |
| 10317 | } |
| 10318 | |
| 10319 | @Override |
| 10320 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10322 | mApp, subId, "setCdmaRoamingMode"); |
| 10323 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10324 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10325 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10326 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10327 | final long identity = Binder.clearCallingIdentity(); |
| 10328 | try { |
| 10329 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10330 | } finally { |
| 10331 | Binder.restoreCallingIdentity(identity); |
| 10332 | } |
| 10333 | } |
| 10334 | |
| 10335 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10336 | public int getCdmaSubscriptionMode(int subId) { |
| 10337 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10338 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10339 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10340 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10341 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10342 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10343 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10344 | final long identity = Binder.clearCallingIdentity(); |
| 10345 | try { |
| 10346 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10347 | } finally { |
| 10348 | Binder.restoreCallingIdentity(identity); |
| 10349 | } |
| 10350 | } |
| 10351 | |
| 10352 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10353 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10354 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10355 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10356 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10357 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10358 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10359 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10360 | final long identity = Binder.clearCallingIdentity(); |
| 10361 | try { |
| 10362 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10363 | } finally { |
| 10364 | Binder.restoreCallingIdentity(identity); |
| 10365 | } |
| 10366 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10367 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10368 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10369 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10370 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10371 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10372 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10373 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10374 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10375 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10376 | |
| 10377 | enforceTelephonyFeatureWithException(callingPackage, |
| 10378 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10379 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10380 | final long identity = Binder.clearCallingIdentity(); |
| 10381 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10382 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10383 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10384 | if (phone.getEmergencyNumberTracker() != null |
| 10385 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10386 | emergencyNumberListInternal.put( |
| 10387 | phone.getSubId(), |
| 10388 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10389 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10390 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10391 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10392 | } finally { |
| 10393 | Binder.restoreCallingIdentity(identity); |
| 10394 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10395 | } |
| 10396 | |
| 10397 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10398 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10399 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10400 | if (!exactMatch) { |
| 10401 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10402 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10403 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10404 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10405 | |
| 10406 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10407 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10408 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10409 | final long identity = Binder.clearCallingIdentity(); |
| 10410 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10411 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10412 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10413 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10414 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10415 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10416 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10417 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10418 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10419 | } |
| 10420 | return false; |
| 10421 | } finally { |
| 10422 | Binder.restoreCallingIdentity(identity); |
| 10423 | } |
| 10424 | } |
| 10425 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10426 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10427 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10428 | */ |
| 10429 | @Override |
| 10430 | public void startEmergencyCallbackMode() { |
| 10431 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10432 | "startEmergencyCallbackMode"); |
| 10433 | enforceModifyPermission(); |
| 10434 | final long identity = Binder.clearCallingIdentity(); |
| 10435 | try { |
| 10436 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10437 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10438 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10439 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10440 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10441 | gsmCdmaPhone.obtainMessage( |
| 10442 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10443 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10444 | } |
| 10445 | } |
| 10446 | } finally { |
| 10447 | Binder.restoreCallingIdentity(identity); |
| 10448 | } |
| 10449 | } |
| 10450 | |
| 10451 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10452 | * Update emergency number list for test mode. |
| 10453 | */ |
| 10454 | @Override |
| 10455 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10456 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10457 | "updateEmergencyNumberListTestMode"); |
| 10458 | |
| 10459 | final long identity = Binder.clearCallingIdentity(); |
| 10460 | try { |
| 10461 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10462 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10463 | if (tracker != null) { |
| 10464 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10465 | } |
| 10466 | } |
| 10467 | } finally { |
| 10468 | Binder.restoreCallingIdentity(identity); |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | /** |
| 10473 | * Get the full emergency number list for test mode. |
| 10474 | */ |
| 10475 | @Override |
| 10476 | public List<String> getEmergencyNumberListTestMode() { |
| 10477 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10478 | "getEmergencyNumberListTestMode"); |
| 10479 | |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
| 10482 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10483 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10484 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10485 | if (tracker != null) { |
| 10486 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10487 | emergencyNumbers.add(num.getNumber()); |
| 10488 | } |
| 10489 | } |
| 10490 | } |
| 10491 | return new ArrayList<>(emergencyNumbers); |
| 10492 | } finally { |
| 10493 | Binder.restoreCallingIdentity(identity); |
| 10494 | } |
| 10495 | } |
| 10496 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10497 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10498 | public int getEmergencyNumberDbVersion(int subId) { |
| 10499 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10500 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10501 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10502 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10503 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10504 | final long identity = Binder.clearCallingIdentity(); |
| 10505 | try { |
| 10506 | final Phone phone = getPhone(subId); |
| 10507 | if (phone == null) { |
| 10508 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10509 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10510 | } |
| 10511 | return phone.getEmergencyNumberDbVersion(); |
| 10512 | } finally { |
| 10513 | Binder.restoreCallingIdentity(identity); |
| 10514 | } |
| 10515 | } |
| 10516 | |
| 10517 | @Override |
| 10518 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10519 | enforceModifyPermission(); |
| 10520 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10522 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10523 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10524 | final long identity = Binder.clearCallingIdentity(); |
| 10525 | try { |
| 10526 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10527 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10528 | if (tracker != null) { |
| 10529 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10530 | } |
| 10531 | } |
| 10532 | } finally { |
| 10533 | Binder.restoreCallingIdentity(identity); |
| 10534 | } |
| 10535 | } |
| 10536 | |
| 10537 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10538 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10539 | enforceActiveEmergencySessionPermission(); |
| 10540 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10541 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10542 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10543 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10544 | final long identity = Binder.clearCallingIdentity(); |
| 10545 | try { |
| 10546 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10547 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10548 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10549 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10550 | } |
| 10551 | } |
| 10552 | } finally { |
| 10553 | Binder.restoreCallingIdentity(identity); |
| 10554 | } |
| 10555 | } |
| 10556 | |
| 10557 | @Override |
| 10558 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10559 | enforceActiveEmergencySessionPermission(); |
| 10560 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10561 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10562 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10563 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10564 | final long identity = Binder.clearCallingIdentity(); |
| 10565 | try { |
| 10566 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10567 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10568 | if (tracker != null) { |
| 10569 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10570 | } |
| 10571 | } |
| 10572 | } finally { |
| 10573 | Binder.restoreCallingIdentity(identity); |
| 10574 | } |
| 10575 | } |
| 10576 | |
| 10577 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10578 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10579 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10580 | Phone phone = getPhone(subId); |
| 10581 | if (phone == null) { |
| 10582 | return null; |
| 10583 | } |
| 10584 | final long identity = Binder.clearCallingIdentity(); |
| 10585 | try { |
| 10586 | UiccProfile profile = UiccController.getInstance() |
| 10587 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10588 | if (profile != null) { |
| 10589 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10590 | } |
| 10591 | } finally { |
| 10592 | Binder.restoreCallingIdentity(identity); |
| 10593 | } |
| 10594 | return null; |
| 10595 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10596 | |
| 10597 | /** |
| 10598 | * Enable or disable a modem stack. |
| 10599 | */ |
| 10600 | @Override |
| 10601 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10602 | enforceModifyPermission(); |
| 10603 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10604 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10605 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10606 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10607 | final long identity = Binder.clearCallingIdentity(); |
| 10608 | try { |
| 10609 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10610 | if (phone == null) { |
| 10611 | return false; |
| 10612 | } else { |
| 10613 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10614 | } |
| 10615 | } finally { |
| 10616 | Binder.restoreCallingIdentity(identity); |
| 10617 | } |
| 10618 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10619 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10620 | /** |
| 10621 | * Whether a modem stack is enabled or not. |
| 10622 | */ |
| 10623 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10624 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10625 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10626 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10627 | if (phone == null) return false; |
| 10628 | |
| 10629 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10630 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10631 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10632 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10633 | } |
| 10634 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10635 | enforceTelephonyFeatureWithException(callingPackage, |
| 10636 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10637 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10638 | final long identity = Binder.clearCallingIdentity(); |
| 10639 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10640 | try { |
| 10641 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10642 | } catch (NoSuchElementException ex) { |
| 10643 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10644 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10645 | } finally { |
| 10646 | Binder.restoreCallingIdentity(identity); |
| 10647 | } |
| 10648 | } |
| 10649 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10650 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10651 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10652 | enforceModifyPermission(); |
| 10653 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10654 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10655 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10656 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10657 | final long identity = Binder.clearCallingIdentity(); |
| 10658 | try { |
| 10659 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10660 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10661 | .commit(); |
| 10662 | } finally { |
| 10663 | Binder.restoreCallingIdentity(identity); |
| 10664 | } |
| 10665 | } |
| 10666 | |
| 10667 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10668 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10669 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10670 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10671 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10672 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10673 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10674 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10675 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10676 | enforceTelephonyFeatureWithException(callingPackage, |
| 10677 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10678 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10679 | final long identity = Binder.clearCallingIdentity(); |
| 10680 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10681 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10682 | } finally { |
| 10683 | Binder.restoreCallingIdentity(identity); |
| 10684 | } |
| 10685 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10686 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10687 | @TelephonyManager.IsMultiSimSupportedResult |
| 10688 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10689 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10690 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10691 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10692 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10693 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10694 | } |
| 10695 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10696 | // supported by the modem, indicate that it is restricted. |
| 10697 | PhoneCapability staticCapability = |
| 10698 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10699 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10700 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10701 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10702 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10703 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10704 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10705 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10706 | } |
| 10707 | // Check if support of multiple SIMs is restricted by carrier |
| 10708 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10709 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10710 | } |
| 10711 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10712 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10713 | } |
| 10714 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10715 | /** |
| 10716 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10717 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10718 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10719 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10720 | * @param numOfSims number of active sims we want to switch to |
| 10721 | */ |
| 10722 | @Override |
| 10723 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10724 | if (numOfSims == 1) { |
| 10725 | enforceModifyPermission(); |
| 10726 | } else { |
| 10727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10728 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10729 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10730 | |
| 10731 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10732 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10733 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10734 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10735 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10736 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10737 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10738 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10739 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10740 | return; |
| 10741 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10742 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10743 | } finally { |
| 10744 | Binder.restoreCallingIdentity(identity); |
| 10745 | } |
| 10746 | } |
| 10747 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10748 | @Override |
| 10749 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10750 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10751 | |
| 10752 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10753 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10754 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10755 | Phone phone = getPhone(subId); |
| 10756 | if (phone == null) { |
| 10757 | return false; |
| 10758 | } |
| 10759 | final long identity = Binder.clearCallingIdentity(); |
| 10760 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10761 | UiccPort uiccPort = phone.getUiccPort(); |
| 10762 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10763 | return false; |
| 10764 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10765 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10766 | if (uiccProfile == null) { |
| 10767 | return false; |
| 10768 | } |
| 10769 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10770 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10771 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10772 | } |
| 10773 | return false; |
| 10774 | } finally { |
| 10775 | Binder.restoreCallingIdentity(identity); |
| 10776 | } |
| 10777 | } |
| 10778 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10779 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10780 | * Get whether making changes to modem configurations will trigger reboot. |
| 10781 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10782 | */ |
| 10783 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10784 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10785 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10787 | mApp, subId, callingPackage, callingFeatureId, |
| 10788 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10789 | return false; |
| 10790 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10791 | |
| 10792 | enforceTelephonyFeatureWithException(callingPackage, |
| 10793 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10794 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10795 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10796 | final long identity = Binder.clearCallingIdentity(); |
| 10797 | try { |
| 10798 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10799 | } finally { |
| 10800 | Binder.restoreCallingIdentity(identity); |
| 10801 | } |
| 10802 | } |
| 10803 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10804 | private void updateModemStateMetrics() { |
| 10805 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10806 | // TODO: check the state for each modem if the api is ready. |
| 10807 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10808 | } |
| 10809 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10810 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10811 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10812 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10813 | // Verify that the callingPackage belongs to the calling UID |
| 10814 | mApp.getSystemService(AppOpsManager.class) |
| 10815 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10816 | |
| 10817 | enforceTelephonyFeatureWithException(callingPackage, |
| 10818 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10819 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10820 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10821 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10822 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10823 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10824 | if (slotInfos != null) { |
| 10825 | for (int i = 0; i < slotInfos.length; i++) { |
| 10826 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10827 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10828 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10829 | portInfo.getLogicalSlotIndex())); |
| 10830 | } |
| 10831 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10832 | } |
| 10833 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10834 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10835 | } finally { |
| 10836 | Binder.restoreCallingIdentity(identity); |
| 10837 | } |
| 10838 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10839 | |
| 10840 | /** |
| 10841 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10842 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10843 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10844 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10845 | @Override |
| 10846 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10847 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10848 | } |
| 10849 | |
| 10850 | /** |
| 10851 | * Get the HAL Version of a specific service |
| 10852 | */ |
| 10853 | @Override |
| 10854 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10855 | Phone phone = getDefaultPhone(); |
| 10856 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10857 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10858 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10859 | return hv.major * 100 + hv.minor; |
| 10860 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10861 | |
| 10862 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10863 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10864 | * |
| 10865 | * @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] | 10866 | */ |
| 10867 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10868 | public @Nullable String getCurrentPackageName() { |
| 10869 | PackageManager pm = mApp.getPackageManager(); |
| 10870 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10871 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10872 | } |
| 10873 | |
| 10874 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10875 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10876 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10877 | * actually always the caller. |
| 10878 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10879 | */ |
| 10880 | private String getCurrentPackageNameOrPhone() { |
| 10881 | PackageManager pm = mApp.getPackageManager(); |
| 10882 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10883 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10884 | return getCurrentPackageName(); |
| 10885 | } |
| 10886 | |
| 10887 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10888 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10889 | * corresponding network requests on a subId. |
| 10890 | * |
| 10891 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10892 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10893 | * 2) APN is un-metered for this subscription, or |
| 10894 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10895 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10896 | * |
| 10897 | * @return whether data is allowed for a apn type. |
| 10898 | * |
| 10899 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10900 | */ |
| 10901 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10902 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10903 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10904 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10905 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10906 | enforceTelephonyFeatureWithException(callingPackage, |
| 10907 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10908 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10909 | // Now that all security checks passes, perform the operation as ourselves. |
| 10910 | final long identity = Binder.clearCallingIdentity(); |
| 10911 | try { |
| 10912 | Phone phone = getPhone(subId); |
| 10913 | if (phone == null) return false; |
| 10914 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10915 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10916 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10917 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10918 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10919 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10920 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10921 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10922 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10923 | } finally { |
| 10924 | Binder.restoreCallingIdentity(identity); |
| 10925 | } |
| 10926 | } |
| 10927 | |
| 10928 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10929 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10930 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10931 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10932 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10933 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10934 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10935 | // Now that all security checks passes, perform the operation as ourselves. |
| 10936 | final long identity = Binder.clearCallingIdentity(); |
| 10937 | try { |
| 10938 | Phone phone = getPhone(subId); |
| 10939 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10940 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10941 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10942 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10947 | |
| 10948 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10949 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10950 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10951 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10952 | |
| 10953 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10954 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10955 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10956 | long token = Binder.clearCallingIdentity(); |
| 10957 | try { |
| 10958 | Phone phone = getPhone(subscriptionId); |
| 10959 | if (phone == null) { |
| 10960 | try { |
| 10961 | if (resultCallback != null) { |
| 10962 | resultCallback.accept(false); |
| 10963 | } |
| 10964 | } catch (RemoteException e) { |
| 10965 | // ignore |
| 10966 | } |
| 10967 | return; |
| 10968 | } |
| 10969 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10970 | Pair.create(specifiers, (x) -> { |
| 10971 | try { |
| 10972 | if (resultCallback != null) { |
| 10973 | resultCallback.accept(x); |
| 10974 | } |
| 10975 | } catch (RemoteException e) { |
| 10976 | // ignore |
| 10977 | } |
| 10978 | }); |
| 10979 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10980 | } finally { |
| 10981 | Binder.restoreCallingIdentity(token); |
| 10982 | } |
| 10983 | } |
| 10984 | |
| 10985 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10986 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10987 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10988 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10989 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10990 | |
| 10991 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10992 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10993 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10994 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10995 | final long identity = Binder.clearCallingIdentity(); |
| 10996 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10997 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10998 | if (result instanceof IllegalStateException) { |
| 10999 | throw (IllegalStateException) result; |
| 11000 | } |
| 11001 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11002 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11003 | return specifiers; |
| 11004 | } finally { |
| 11005 | Binder.restoreCallingIdentity(identity); |
| 11006 | } |
| 11007 | } |
| 11008 | |
| 11009 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11010 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11011 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11012 | |
| 11013 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11014 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11015 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11016 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11017 | } |
| 11018 | |
| 11019 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11020 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11021 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11022 | if (callingPackage == null) { |
| 11023 | callingPackage = getCurrentPackageName(); |
| 11024 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11025 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11026 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11027 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11028 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11029 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11030 | } |
| 11031 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11032 | Intent intent = new Intent(); |
| 11033 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11034 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11035 | // Bring up choose default SMS subscription dialog right now |
| 11036 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11037 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 11038 | mApp.startActivity(intent); |
| 11039 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11040 | |
| 11041 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11042 | public void showSwitchToManagedProfileDialog() { |
| 11043 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11044 | try { |
| 11045 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11046 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11047 | // for work telephony. |
| 11048 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11049 | intent.setData(Uri.parse("smsto:")); |
| 11050 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11051 | mApp.startActivity(intent); |
| 11052 | } catch (ActivityNotFoundException e) { |
| 11053 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11054 | Intent intent = new Intent(); |
| 11055 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11056 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11057 | mApp.startActivity(intent); |
| 11058 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11059 | } |
| 11060 | |
| 11061 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11062 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11063 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11064 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11065 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11066 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11067 | final long identity = Binder.clearCallingIdentity(); |
| 11068 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11069 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11070 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11071 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11072 | return carrierUAProfUrl; |
| 11073 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11074 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11075 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11076 | } finally { |
| 11077 | Binder.restoreCallingIdentity(identity); |
| 11078 | } |
| 11079 | } |
| 11080 | |
| 11081 | @Override |
| 11082 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11083 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11084 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11085 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11086 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11087 | final long identity = Binder.clearCallingIdentity(); |
| 11088 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11089 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11090 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11091 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11092 | return carrierUserAgent; |
| 11093 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11094 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11095 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11096 | } finally { |
| 11097 | Binder.restoreCallingIdentity(identity); |
| 11098 | } |
| 11099 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11100 | |
| 11101 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11102 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11103 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11104 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11106 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11107 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11108 | final long identity = Binder.clearCallingIdentity(); |
| 11109 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11110 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11111 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11112 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11113 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11114 | } finally { |
| 11115 | Binder.restoreCallingIdentity(identity); |
| 11116 | } |
| 11117 | } |
| 11118 | |
| 11119 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11120 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11121 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11122 | enforceModifyPermission(); |
| 11123 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11124 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11125 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11126 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11127 | final long identity = Binder.clearCallingIdentity(); |
| 11128 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11129 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11130 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11131 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11132 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11133 | } finally { |
| 11134 | Binder.restoreCallingIdentity(identity); |
| 11135 | } |
| 11136 | } |
| 11137 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11138 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11139 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11140 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11141 | * otherwise. |
| 11142 | */ |
| 11143 | @Override |
| 11144 | public void setCepEnabled(boolean isCepEnabled) { |
| 11145 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11146 | |
| 11147 | final long identity = Binder.clearCallingIdentity(); |
| 11148 | try { |
| 11149 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11150 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11151 | Phone defaultPhone = phone.getImsPhone(); |
| 11152 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11153 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11154 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11155 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11156 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11157 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11158 | + imsPhone.getMsisdn()); |
| 11159 | } |
| 11160 | } |
| 11161 | } finally { |
| 11162 | Binder.restoreCallingIdentity(identity); |
| 11163 | } |
| 11164 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11165 | |
| 11166 | /** |
| 11167 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11168 | * |
| 11169 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11170 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11171 | * before being read. |
| 11172 | */ |
| 11173 | @Override |
| 11174 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11175 | isCompressed) { |
| 11176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11177 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11178 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11179 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11180 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11181 | |
| 11182 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11183 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11184 | Binder.getCallingUserHandle())) { |
| 11185 | if (!isImsAvailableOnDevice()) { |
| 11186 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11187 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11188 | throw new IllegalStateException("IMS not available on device."); |
| 11189 | } |
| 11190 | } else { |
| 11191 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11192 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11193 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11194 | } |
| 11195 | |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11197 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11198 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11199 | } finally { |
| 11200 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11201 | } |
| 11202 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11203 | |
| 11204 | @Override |
| 11205 | public boolean isIccLockEnabled(int subId) { |
| 11206 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11207 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11208 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11209 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11210 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11211 | // Now that all security checks passes, perform the operation as ourselves. |
| 11212 | final long identity = Binder.clearCallingIdentity(); |
| 11213 | try { |
| 11214 | Phone phone = getPhone(subId); |
| 11215 | if (phone != null && phone.getIccCard() != null) { |
| 11216 | return phone.getIccCard().getIccLockEnabled(); |
| 11217 | } else { |
| 11218 | return false; |
| 11219 | } |
| 11220 | } finally { |
| 11221 | Binder.restoreCallingIdentity(identity); |
| 11222 | } |
| 11223 | } |
| 11224 | |
| 11225 | /** |
| 11226 | * Set the ICC pin lock enabled or disabled. |
| 11227 | * |
| 11228 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11229 | * three cases: |
| 11230 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11231 | * successfully. |
| 11232 | * - Positive number and zero for remaining password attempts. |
| 11233 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11234 | * |
| 11235 | */ |
| 11236 | @Override |
| 11237 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11238 | enforceModifyPermission(); |
| 11239 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11240 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11241 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11242 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11243 | Phone phone = getPhone(subId); |
| 11244 | if (phone == null) { |
| 11245 | return 0; |
| 11246 | } |
| 11247 | // Now that all security checks passes, perform the operation as ourselves. |
| 11248 | final long identity = Binder.clearCallingIdentity(); |
| 11249 | try { |
| 11250 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11251 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11252 | return attemptsRemaining; |
| 11253 | |
| 11254 | } catch (Exception e) { |
| 11255 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11256 | } finally { |
| 11257 | Binder.restoreCallingIdentity(identity); |
| 11258 | } |
| 11259 | return 0; |
| 11260 | } |
| 11261 | |
| 11262 | /** |
| 11263 | * Change the ICC password used in ICC pin lock. |
| 11264 | * |
| 11265 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11266 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11267 | * - Positive number and zero for remaining password attempts. |
| 11268 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11269 | * |
| 11270 | */ |
| 11271 | @Override |
| 11272 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11273 | enforceModifyPermission(); |
| 11274 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11275 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11276 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11277 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11278 | Phone phone = getPhone(subId); |
| 11279 | if (phone == null) { |
| 11280 | return 0; |
| 11281 | } |
| 11282 | // Now that all security checks passes, perform the operation as ourselves. |
| 11283 | final long identity = Binder.clearCallingIdentity(); |
| 11284 | try { |
| 11285 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11286 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11287 | return attemptsRemaining; |
| 11288 | |
| 11289 | } catch (Exception e) { |
| 11290 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11291 | } finally { |
| 11292 | Binder.restoreCallingIdentity(identity); |
| 11293 | } |
| 11294 | return 0; |
| 11295 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11296 | |
| 11297 | /** |
| 11298 | * Request for receiving user activity notification |
| 11299 | */ |
| 11300 | @Override |
| 11301 | public void requestUserActivityNotification() { |
| 11302 | if (!mNotifyUserActivity.get() |
| 11303 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11304 | mNotifyUserActivity.set(true); |
| 11305 | } |
| 11306 | } |
| 11307 | |
| 11308 | /** |
| 11309 | * Called when userActivity is signalled in the power manager. |
| 11310 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11311 | */ |
| 11312 | @Override |
| 11313 | public void userActivity() { |
| 11314 | // *************************************** |
| 11315 | // * Inherited from PhoneWindowManager * |
| 11316 | // *************************************** |
| 11317 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11318 | // WITH ITS LOCKS HELD. |
| 11319 | // |
| 11320 | // This code must be VERY careful about the locks |
| 11321 | // it acquires. |
| 11322 | // In fact, the current code acquires way too many, |
| 11323 | // and probably has lurking deadlocks. |
| 11324 | |
| 11325 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11326 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11327 | } |
| 11328 | |
| 11329 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11330 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11331 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11332 | } |
| 11333 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11334 | |
| 11335 | @Override |
| 11336 | public boolean canConnectTo5GInDsdsMode() { |
| 11337 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11338 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11339 | |
| 11340 | @Override |
| 11341 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11342 | String callingFeatureId) { |
| 11343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11344 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11345 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11346 | } |
| 11347 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11348 | enforceTelephonyFeatureWithException(callingPackage, |
| 11349 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11350 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11351 | Phone phone = getPhone(subId); |
| 11352 | if (phone == null) { |
| 11353 | throw new RuntimeException("phone is not available"); |
| 11354 | } |
| 11355 | // Now that all security checks passes, perform the operation as ourselves. |
| 11356 | final long identity = Binder.clearCallingIdentity(); |
| 11357 | try { |
| 11358 | return phone.getEquivalentHomePlmns(); |
| 11359 | } finally { |
| 11360 | Binder.restoreCallingIdentity(identity); |
| 11361 | } |
| 11362 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11363 | |
| 11364 | @Override |
| 11365 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11366 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11367 | if (!mApp.getResources().getBoolean( |
| 11368 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11369 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11370 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11371 | "isRadioInterfaceCapabilitySupported"); |
| 11372 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11373 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11374 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11375 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11376 | if (radioInterfaceCapabilities == null) { |
| 11377 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11378 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11379 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11380 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11381 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11382 | @Override |
| 11383 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11384 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11385 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11386 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11387 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11388 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11389 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11390 | |
| 11391 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11392 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11393 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11394 | if (DBG) { |
| 11395 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11396 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11397 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11398 | } |
| 11399 | |
| 11400 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11401 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11402 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11403 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11404 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11405 | if (callback != null) { |
| 11406 | try { |
| 11407 | callback.onAuthenticationFailure( |
| 11408 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11409 | } catch (RemoteException exception) { |
| 11410 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11411 | } |
| 11412 | return; |
| 11413 | } |
| 11414 | } |
| 11415 | |
| 11416 | final long token = Binder.clearCallingIdentity(); |
| 11417 | try { |
| 11418 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11419 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11420 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11421 | } finally { |
| 11422 | Binder.restoreCallingIdentity(token); |
| 11423 | } |
| 11424 | } |
| 11425 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11426 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11427 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11428 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11429 | * requested radio power state will actually be set. See {@link |
| 11430 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11431 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11432 | * @param enable {@code true} if trying to turn radio on. |
| 11433 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11434 | * false}. |
| 11435 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11436 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11437 | boolean isPhoneAvailable = false; |
| 11438 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11439 | Phone phone = PhoneFactory.getPhone(i); |
| 11440 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11441 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11442 | isPhoneAvailable = true; |
| 11443 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11444 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11445 | |
| 11446 | // return true if successfully informed the phone object about the thermal radio power |
| 11447 | // request. |
| 11448 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11449 | } |
| 11450 | |
| 11451 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11452 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11453 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11454 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11455 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11456 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11457 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11458 | } |
| 11459 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11460 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11461 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11462 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11463 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11464 | } |
| 11465 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11466 | setDataEnabledForReason( |
| 11467 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11468 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11469 | if (isDataThrottlingSupported) { |
| 11470 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11471 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11472 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11473 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11474 | } else if (thermalMitigationResult |
| 11475 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11476 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11477 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11478 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11479 | } |
| 11480 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11481 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11482 | |
| 11483 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11484 | } |
| 11485 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11486 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11487 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11488 | for (String pckg : context.getResources() |
| 11489 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11490 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11491 | } |
| 11492 | } |
| 11493 | |
| 11494 | return sThermalMitigationAllowlistedPackages; |
| 11495 | } |
| 11496 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11497 | private boolean isAnyPhoneInEmergencyState() { |
| 11498 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11499 | if (tm.isInEmergencyCall()) { |
| 11500 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11501 | return true; |
| 11502 | } |
| 11503 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11504 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11505 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11506 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11507 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11508 | return true; |
| 11509 | } |
| 11510 | } |
| 11511 | |
| 11512 | return false; |
| 11513 | } |
| 11514 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11515 | /** |
| 11516 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11517 | * @param packageName name of package to be allowlisted |
| 11518 | * @param context |
| 11519 | */ |
| 11520 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11521 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11522 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11523 | } |
| 11524 | |
| 11525 | /** |
| 11526 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11527 | * @param packageName name of package to remove from allowlist |
| 11528 | * @param context |
| 11529 | */ |
| 11530 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11531 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11532 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11533 | } |
| 11534 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11535 | /** |
| 11536 | * Thermal mitigation request to control functionalities at modem. |
| 11537 | * |
| 11538 | * @param subId the id of the subscription. |
| 11539 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11540 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11541 | * |
| 11542 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11543 | */ |
| 11544 | @Override |
| 11545 | @ThermalMitigationResult |
| 11546 | public int sendThermalMitigationRequest( |
| 11547 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11548 | ThermalMitigationRequest thermalMitigationRequest, |
| 11549 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11550 | enforceModifyPermission(); |
| 11551 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11552 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11553 | |
| 11554 | enforceTelephonyFeatureWithException(callingPackage, |
| 11555 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11556 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11557 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11558 | .contains(callingPackage)) { |
| 11559 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11560 | + "calling package: " + callingPackage); |
| 11561 | } |
| 11562 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11563 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11564 | final long identity = Binder.clearCallingIdentity(); |
| 11565 | |
| 11566 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11567 | try { |
| 11568 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11569 | switch (thermalMitigationAction) { |
| 11570 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11571 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11572 | handleDataThrottlingRequest(subId, |
| 11573 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11574 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11575 | break; |
| 11576 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11577 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11578 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11579 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11580 | } |
| 11581 | |
| 11582 | // Ensure that radio is on. If not able to power on due to phone being |
| 11583 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11584 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11585 | thermalMitigationResult = |
| 11586 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11587 | break; |
| 11588 | } |
| 11589 | |
| 11590 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11591 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11592 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11593 | break; |
| 11594 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11595 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11596 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11597 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11598 | } |
| 11599 | |
| 11600 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11601 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11602 | Phone phone = getPhone(subId); |
| 11603 | if (phone == null) { |
| 11604 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11605 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11606 | break; |
| 11607 | } |
| 11608 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11609 | TelephonyConnectionService service = |
| 11610 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11611 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11612 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11613 | thermalMitigationResult = |
| 11614 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11615 | break; |
| 11616 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11617 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11618 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11619 | break; |
| 11620 | } |
| 11621 | } else { |
| 11622 | thermalMitigationResult = |
| 11623 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11624 | break; |
| 11625 | } |
| 11626 | |
| 11627 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11628 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11629 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11630 | thermalMitigationResult = |
| 11631 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11632 | break; |
| 11633 | } |
| 11634 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11635 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11636 | break; |
| 11637 | default: |
| 11638 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11639 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11640 | } |
| 11641 | } catch (IllegalArgumentException e) { |
| 11642 | throw e; |
| 11643 | } catch (Exception e) { |
| 11644 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11645 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11646 | } finally { |
| 11647 | Binder.restoreCallingIdentity(identity); |
| 11648 | } |
| 11649 | |
| 11650 | if (DBG) { |
| 11651 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11652 | + thermalMitigationResult); |
| 11653 | } |
| 11654 | |
| 11655 | return thermalMitigationResult; |
| 11656 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11657 | |
| 11658 | /** |
| 11659 | * Set the GbaService Package Name that Telephony will bind to. |
| 11660 | * |
| 11661 | * @param subId The sim that the GbaService is associated with. |
| 11662 | * @param packageName The name of the package to be replaced with. |
| 11663 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11664 | */ |
| 11665 | @Override |
| 11666 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11667 | enforceModifyPermission(); |
| 11668 | |
| 11669 | final long identity = Binder.clearCallingIdentity(); |
| 11670 | try { |
| 11671 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11672 | } finally { |
| 11673 | Binder.restoreCallingIdentity(identity); |
| 11674 | } |
| 11675 | } |
| 11676 | |
| 11677 | /** |
| 11678 | * Return the package name of the currently bound GbaService. |
| 11679 | * |
| 11680 | * @param subId The sim that the GbaService is associated with. |
| 11681 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11682 | */ |
| 11683 | @Override |
| 11684 | public String getBoundGbaService(int subId) { |
| 11685 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11686 | |
| 11687 | final long identity = Binder.clearCallingIdentity(); |
| 11688 | try { |
| 11689 | return getGbaManager(subId).getServicePackage(); |
| 11690 | } finally { |
| 11691 | Binder.restoreCallingIdentity(identity); |
| 11692 | } |
| 11693 | } |
| 11694 | |
| 11695 | /** |
| 11696 | * Set the release time for telephony to unbind GbaService. |
| 11697 | * |
| 11698 | * @param subId The sim that the GbaService is associated with. |
| 11699 | * @param interval The release time to unbind GbaService by millisecond. |
| 11700 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11701 | */ |
| 11702 | @Override |
| 11703 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11704 | enforceModifyPermission(); |
| 11705 | |
| 11706 | final long identity = Binder.clearCallingIdentity(); |
| 11707 | try { |
| 11708 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11709 | } finally { |
| 11710 | Binder.restoreCallingIdentity(identity); |
| 11711 | } |
| 11712 | } |
| 11713 | |
| 11714 | /** |
| 11715 | * Return the release time for telephony to unbind GbaService. |
| 11716 | * |
| 11717 | * @param subId The sim that the GbaService is associated with. |
| 11718 | * @return The release time to unbind GbaService by millisecond. |
| 11719 | */ |
| 11720 | @Override |
| 11721 | public int getGbaReleaseTime(int subId) { |
| 11722 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11723 | |
| 11724 | final long identity = Binder.clearCallingIdentity(); |
| 11725 | try { |
| 11726 | return getGbaManager(subId).getReleaseTime(); |
| 11727 | } finally { |
| 11728 | Binder.restoreCallingIdentity(identity); |
| 11729 | } |
| 11730 | } |
| 11731 | |
| 11732 | private GbaManager getGbaManager(int subId) { |
| 11733 | GbaManager instance = GbaManager.getInstance(subId); |
| 11734 | if (instance == null) { |
| 11735 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11736 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11737 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11738 | } |
| 11739 | return instance; |
| 11740 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11741 | |
| 11742 | /** |
| 11743 | * indicate whether the device and the carrier can support |
| 11744 | * RCS VoLTE single registration. |
| 11745 | */ |
| 11746 | @Override |
| 11747 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11748 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11749 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11750 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11751 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11752 | |
| 11753 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11754 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11755 | } |
| 11756 | |
| 11757 | final long identity = Binder.clearCallingIdentity(); |
| 11758 | try { |
| 11759 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11760 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11761 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11762 | if (isCapable != null) { |
| 11763 | return isCapable; |
| 11764 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11765 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11766 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11767 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11768 | } finally { |
| 11769 | Binder.restoreCallingIdentity(identity); |
| 11770 | } |
| 11771 | } |
| 11772 | |
| 11773 | /** |
| 11774 | * Register RCS provisioning callback. |
| 11775 | */ |
| 11776 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11777 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11778 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11779 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11780 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 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 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11787 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11788 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11789 | Binder.getCallingUserHandle())) { |
| 11790 | if (!isImsAvailableOnDevice()) { |
| 11791 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11792 | "IMS not available on device."); |
| 11793 | } |
| 11794 | } else { |
| 11795 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11796 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11797 | } |
| 11798 | |
| 11799 | final long identity = Binder.clearCallingIdentity(); |
| 11800 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11801 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11802 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11803 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11804 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11805 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11806 | } finally { |
| 11807 | Binder.restoreCallingIdentity(identity); |
| 11808 | } |
| 11809 | } |
| 11810 | |
| 11811 | /** |
| 11812 | * Unregister RCS provisioning callback. |
| 11813 | */ |
| 11814 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11815 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11816 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11817 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11818 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11819 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11820 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11821 | |
| 11822 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11823 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11824 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11825 | |
| 11826 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11827 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11828 | Binder.getCallingUserHandle())) { |
| 11829 | if (!isImsAvailableOnDevice()) { |
| 11830 | // operation failed silently |
| 11831 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11832 | return; |
| 11833 | } |
| 11834 | } else { |
| 11835 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11836 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11837 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11838 | } |
| 11839 | |
| 11840 | final long identity = Binder.clearCallingIdentity(); |
| 11841 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11842 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11843 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11844 | } finally { |
| 11845 | Binder.restoreCallingIdentity(identity); |
| 11846 | } |
| 11847 | } |
| 11848 | |
| 11849 | /** |
| 11850 | * trigger RCS reconfiguration. |
| 11851 | */ |
| 11852 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11853 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11854 | "triggerRcsReconfiguration", |
| 11855 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11856 | |
| 11857 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11858 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11859 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11860 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11861 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11862 | Binder.getCallingUserHandle())) { |
| 11863 | if (!isImsAvailableOnDevice()) { |
| 11864 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11865 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11866 | throw new IllegalStateException("IMS not available on device."); |
| 11867 | } |
| 11868 | } else { |
| 11869 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11870 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11871 | } |
| 11872 | |
| 11873 | final long identity = Binder.clearCallingIdentity(); |
| 11874 | try { |
| 11875 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11876 | } finally { |
| 11877 | Binder.restoreCallingIdentity(identity); |
| 11878 | } |
| 11879 | } |
| 11880 | |
| 11881 | /** |
| 11882 | * Provide the client configuration parameters of the RCS application. |
| 11883 | */ |
| 11884 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11885 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11886 | "setRcsClientConfiguration", |
| 11887 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11888 | |
| 11889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11890 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11891 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11892 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11893 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11894 | Binder.getCallingUserHandle())) { |
| 11895 | if (!isImsAvailableOnDevice()) { |
| 11896 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11897 | "IMS not available on device."); |
| 11898 | } |
| 11899 | } else { |
| 11900 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11901 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11902 | } |
| 11903 | |
| 11904 | final long identity = Binder.clearCallingIdentity(); |
| 11905 | |
| 11906 | try { |
| 11907 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11908 | if (configBinder == null) { |
| 11909 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11910 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11911 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11912 | } else { |
| 11913 | configBinder.setRcsClientConfiguration(rcc); |
| 11914 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11915 | |
| 11916 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11917 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11918 | } catch (RemoteException e) { |
| 11919 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11920 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11921 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11922 | } finally { |
| 11923 | Binder.restoreCallingIdentity(identity); |
| 11924 | } |
| 11925 | } |
| 11926 | |
| 11927 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11928 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11929 | */ |
| 11930 | @Override |
| 11931 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11932 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11933 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11934 | |
| 11935 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11936 | } |
| 11937 | |
| 11938 | /** |
| 11939 | * Gets the test mode for RCS VoLTE single registration. |
| 11940 | */ |
| 11941 | @Override |
| 11942 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11943 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11944 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11945 | |
| 11946 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11947 | } |
| 11948 | |
| 11949 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11950 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11951 | */ |
| 11952 | @Override |
| 11953 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11955 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11956 | enforceModifyPermission(); |
| 11957 | |
| 11958 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11959 | : Boolean.parseBoolean(enabledStr); |
| 11960 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11961 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11962 | } |
| 11963 | |
| 11964 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11965 | * Sends a device to device communication message. Only usable via shell. |
| 11966 | * @param message message to send. |
| 11967 | * @param value message value. |
| 11968 | */ |
| 11969 | @Override |
| 11970 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11971 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11972 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11973 | enforceModifyPermission(); |
| 11974 | |
| 11975 | final long identity = Binder.clearCallingIdentity(); |
| 11976 | try { |
| 11977 | TelephonyConnectionService service = |
| 11978 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11979 | if (service == null) { |
| 11980 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11981 | return; |
| 11982 | } |
| 11983 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11984 | } finally { |
| 11985 | Binder.restoreCallingIdentity(identity); |
| 11986 | } |
| 11987 | } |
| 11988 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11989 | /** |
| 11990 | * Sets the specified device to device transport active. |
| 11991 | * @param transport The transport to set active. |
| 11992 | */ |
| 11993 | @Override |
| 11994 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11995 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11996 | "setActiveDeviceToDeviceTransport"); |
| 11997 | enforceModifyPermission(); |
| 11998 | |
| 11999 | final long identity = Binder.clearCallingIdentity(); |
| 12000 | try { |
| 12001 | TelephonyConnectionService service = |
| 12002 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12003 | if (service == null) { |
| 12004 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12005 | return; |
| 12006 | } |
| 12007 | service.setActiveDeviceToDeviceTransport(transport); |
| 12008 | } finally { |
| 12009 | Binder.restoreCallingIdentity(identity); |
| 12010 | } |
| 12011 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12012 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12013 | @Override |
| 12014 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12015 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12016 | "setDeviceToDeviceForceEnabled"); |
| 12017 | |
| 12018 | final long identity = Binder.clearCallingIdentity(); |
| 12019 | try { |
| 12020 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12021 | p -> { |
| 12022 | Phone thePhone = p.getImsPhone(); |
| 12023 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12024 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12025 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12026 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12027 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12028 | (ImsPhoneCallTracker) tracker; |
| 12029 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12030 | } |
| 12031 | } |
| 12032 | } |
| 12033 | ); |
| 12034 | } finally { |
| 12035 | Binder.restoreCallingIdentity(identity); |
| 12036 | } |
| 12037 | } |
| 12038 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12039 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12040 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12041 | */ |
| 12042 | @Override |
| 12043 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12044 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12045 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12046 | } |
| 12047 | |
| 12048 | /** |
| 12049 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12050 | */ |
| 12051 | @Override |
| 12052 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12053 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12054 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12055 | enforceModifyPermission(); |
| 12056 | |
| 12057 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12058 | : Boolean.parseBoolean(enabledStr); |
| 12059 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12060 | subId, enabled); |
| 12061 | } |
| 12062 | |
| 12063 | /** |
| 12064 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12065 | */ |
| 12066 | @Override |
| 12067 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12068 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12069 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12070 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12071 | |
| 12072 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12073 | * Overrides the ims feature validation result |
| 12074 | */ |
| 12075 | @Override |
| 12076 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12077 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12078 | "setImsFeatureValidationOverride"); |
| 12079 | |
| 12080 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12081 | : Boolean.parseBoolean(enabledStr); |
| 12082 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12083 | subId, enabled); |
| 12084 | } |
| 12085 | |
| 12086 | /** |
| 12087 | * Gets the ims feature validation override value |
| 12088 | */ |
| 12089 | @Override |
| 12090 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12091 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12092 | "getImsFeatureValidationOverride"); |
| 12093 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12094 | } |
| 12095 | |
| 12096 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12097 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12098 | * their mobile plan. |
| 12099 | */ |
| 12100 | @Override |
| 12101 | public String getMobileProvisioningUrl() { |
| 12102 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12103 | final long identity = Binder.clearCallingIdentity(); |
| 12104 | try { |
| 12105 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12106 | } finally { |
| 12107 | Binder.restoreCallingIdentity(identity); |
| 12108 | } |
| 12109 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12110 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12111 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12112 | * Get the EAB contact from the EAB database. |
| 12113 | */ |
| 12114 | @Override |
| 12115 | public String getContactFromEab(String contact) { |
| 12116 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12117 | enforceModifyPermission(); |
| 12118 | final long identity = Binder.clearCallingIdentity(); |
| 12119 | try { |
| 12120 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12121 | } finally { |
| 12122 | Binder.restoreCallingIdentity(identity); |
| 12123 | } |
| 12124 | } |
| 12125 | |
| 12126 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12127 | * Get the EAB capability from the EAB database. |
| 12128 | */ |
| 12129 | @Override |
| 12130 | public String getCapabilityFromEab(String contact) { |
| 12131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12132 | enforceModifyPermission(); |
| 12133 | final long identity = Binder.clearCallingIdentity(); |
| 12134 | try { |
| 12135 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12136 | } finally { |
| 12137 | Binder.restoreCallingIdentity(identity); |
| 12138 | } |
| 12139 | } |
| 12140 | |
| 12141 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12142 | * Remove the EAB contacts from the EAB database. |
| 12143 | */ |
| 12144 | @Override |
| 12145 | public int removeContactFromEab(int subId, String contacts) { |
| 12146 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12147 | enforceModifyPermission(); |
| 12148 | final long identity = Binder.clearCallingIdentity(); |
| 12149 | try { |
| 12150 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12151 | } finally { |
| 12152 | Binder.restoreCallingIdentity(identity); |
| 12153 | } |
| 12154 | } |
| 12155 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12156 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12157 | public boolean getDeviceUceEnabled() { |
| 12158 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12159 | final long identity = Binder.clearCallingIdentity(); |
| 12160 | try { |
| 12161 | return mApp.getDeviceUceEnabled(); |
| 12162 | } finally { |
| 12163 | Binder.restoreCallingIdentity(identity); |
| 12164 | } |
| 12165 | } |
| 12166 | |
| 12167 | @Override |
| 12168 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12169 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12170 | final long identity = Binder.clearCallingIdentity(); |
| 12171 | try { |
| 12172 | mApp.setDeviceUceEnabled(isEnabled); |
| 12173 | } finally { |
| 12174 | Binder.restoreCallingIdentity(identity); |
| 12175 | } |
| 12176 | } |
| 12177 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12178 | /** |
| 12179 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12180 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12181 | */ |
| 12182 | // Used for SHELL command only right now. |
| 12183 | @Override |
| 12184 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12185 | List<String> featureTags) { |
| 12186 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12187 | "addUceRegistrationOverrideShell"); |
| 12188 | final long identity = Binder.clearCallingIdentity(); |
| 12189 | try { |
| 12190 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12191 | new ArraySet<>(featureTags)); |
| 12192 | } catch (ImsException e) { |
| 12193 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12194 | } finally { |
| 12195 | Binder.restoreCallingIdentity(identity); |
| 12196 | } |
| 12197 | } |
| 12198 | |
| 12199 | /** |
| 12200 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12201 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12202 | */ |
| 12203 | // Used for SHELL command only right now. |
| 12204 | @Override |
| 12205 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12206 | List<String> featureTags) { |
| 12207 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12208 | "removeUceRegistrationOverrideShell"); |
| 12209 | final long identity = Binder.clearCallingIdentity(); |
| 12210 | try { |
| 12211 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12212 | new ArraySet<>(featureTags)); |
| 12213 | } catch (ImsException e) { |
| 12214 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12215 | } finally { |
| 12216 | Binder.restoreCallingIdentity(identity); |
| 12217 | } |
| 12218 | } |
| 12219 | |
| 12220 | /** |
| 12221 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12222 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12223 | */ |
| 12224 | // Used for SHELL command only right now. |
| 12225 | @Override |
| 12226 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12227 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12228 | "clearUceRegistrationOverrideShell"); |
| 12229 | final long identity = Binder.clearCallingIdentity(); |
| 12230 | try { |
| 12231 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12232 | } catch (ImsException e) { |
| 12233 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12234 | } finally { |
| 12235 | Binder.restoreCallingIdentity(identity); |
| 12236 | } |
| 12237 | } |
| 12238 | |
| 12239 | /** |
| 12240 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12241 | */ |
| 12242 | // Used for SHELL command only right now. |
| 12243 | @Override |
| 12244 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12245 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12246 | "getLatestRcsContactUceCapabilityShell"); |
| 12247 | final long identity = Binder.clearCallingIdentity(); |
| 12248 | try { |
| 12249 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12250 | } catch (ImsException e) { |
| 12251 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12252 | } finally { |
| 12253 | Binder.restoreCallingIdentity(identity); |
| 12254 | } |
| 12255 | } |
| 12256 | |
| 12257 | /** |
| 12258 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12259 | * device does not have an active PUBLISH. |
| 12260 | */ |
| 12261 | // Used for SHELL command only right now. |
| 12262 | @Override |
| 12263 | public String getLastUcePidfXmlShell(int subId) { |
| 12264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12265 | final long identity = Binder.clearCallingIdentity(); |
| 12266 | try { |
| 12267 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12268 | } catch (ImsException e) { |
| 12269 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12270 | } finally { |
| 12271 | Binder.restoreCallingIdentity(identity); |
| 12272 | } |
| 12273 | } |
| 12274 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12275 | /** |
| 12276 | * Remove UCE requests cannot be sent to the network status. |
| 12277 | */ |
| 12278 | // Used for SHELL command only right now. |
| 12279 | @Override |
| 12280 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12281 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12282 | final long identity = Binder.clearCallingIdentity(); |
| 12283 | try { |
| 12284 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12285 | } catch (ImsException e) { |
| 12286 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12287 | } finally { |
| 12288 | Binder.restoreCallingIdentity(identity); |
| 12289 | } |
| 12290 | } |
| 12291 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12292 | /** |
| 12293 | * Remove UCE requests cannot be sent to the network status. |
| 12294 | */ |
| 12295 | // Used for SHELL command only. |
| 12296 | @Override |
| 12297 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12299 | final long identity = Binder.clearCallingIdentity(); |
| 12300 | try { |
| 12301 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12302 | } catch (ImsException e) { |
| 12303 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12304 | } finally { |
| 12305 | Binder.restoreCallingIdentity(identity); |
| 12306 | } |
| 12307 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12308 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12309 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12310 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12311 | String callingPackage) { |
| 12312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12313 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12314 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12315 | enforceTelephonyFeatureWithException(callingPackage, |
| 12316 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12317 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12318 | final int callingUid = Binder.getCallingUid(); |
| 12319 | // Verify that tha callingPackage belongs to the calling UID |
| 12320 | mApp.getSystemService(AppOpsManager.class) |
| 12321 | .checkPackage(callingUid, callingPackage); |
| 12322 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12323 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12324 | |
| 12325 | final long identity = Binder.clearCallingIdentity(); |
| 12326 | try { |
| 12327 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12328 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12329 | |
| 12330 | if (result instanceof IllegalStateException) { |
| 12331 | throw (IllegalStateException) result; |
| 12332 | } |
| 12333 | } finally { |
| 12334 | Binder.restoreCallingIdentity(identity); |
| 12335 | } |
| 12336 | } |
| 12337 | |
| 12338 | @Override |
| 12339 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12340 | String callingPackage) { |
| 12341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12342 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12343 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12344 | enforceTelephonyFeatureWithException(callingPackage, |
| 12345 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12346 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12347 | final int callingUid = Binder.getCallingUid(); |
| 12348 | // Verify that tha callingPackage belongs to the calling UID |
| 12349 | mApp.getSystemService(AppOpsManager.class) |
| 12350 | .checkPackage(callingUid, callingPackage); |
| 12351 | |
| 12352 | final long identity = Binder.clearCallingIdentity(); |
| 12353 | try { |
| 12354 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12355 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12356 | |
| 12357 | if (result instanceof IllegalStateException) { |
| 12358 | throw (IllegalStateException) result; |
| 12359 | } |
| 12360 | } finally { |
| 12361 | Binder.restoreCallingIdentity(identity); |
| 12362 | } |
| 12363 | } |
| 12364 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12365 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12366 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12367 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12368 | // phone/system process do not have further restriction on request |
| 12369 | return; |
| 12370 | } |
| 12371 | |
| 12372 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12373 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12374 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12375 | context.enforceCallingOrSelfPermission( |
| 12376 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12377 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12378 | } |
| 12379 | |
| 12380 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12381 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12382 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12383 | || info.isEnabled()) { |
| 12384 | throw new IllegalArgumentException( |
| 12385 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12386 | } |
| 12387 | |
| 12388 | // Thresholds length for each RAN need in range. This has been validated in |
| 12389 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12390 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12391 | final int[] thresholds = info.getThresholds(); |
| 12392 | Objects.requireNonNull(thresholds); |
| 12393 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12394 | || thresholds.length |
| 12395 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12396 | throw new IllegalArgumentException( |
| 12397 | "thresholds length is out of range: " + thresholds.length); |
| 12398 | } |
| 12399 | } |
| 12400 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12401 | |
| 12402 | /** |
| 12403 | * Gets the current phone capability. |
| 12404 | * |
| 12405 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12406 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12407 | * It's used to evaluate possible phone config change, for example from single |
| 12408 | * SIM device to multi-SIM device. |
| 12409 | */ |
| 12410 | @Override |
| 12411 | public PhoneCapability getPhoneCapability() { |
| 12412 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12413 | |
| 12414 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12415 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12416 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12417 | final long identity = Binder.clearCallingIdentity(); |
| 12418 | try { |
| 12419 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12420 | } finally { |
| 12421 | Binder.restoreCallingIdentity(identity); |
| 12422 | } |
| 12423 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12424 | |
| 12425 | /** |
| 12426 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12427 | * required to be done shortly after the API is invoked. |
| 12428 | */ |
| 12429 | @Override |
| 12430 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12431 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12432 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12433 | enforceRebootPermission(); |
| 12434 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12435 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12436 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12437 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12438 | final long identity = Binder.clearCallingIdentity(); |
| 12439 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12440 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12441 | } finally { |
| 12442 | Binder.restoreCallingIdentity(identity); |
| 12443 | } |
| 12444 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12445 | |
| 12446 | /** |
| 12447 | * Request to get the current slicing configuration including URSP rules and |
| 12448 | * NSSAIs (configured, allowed and rejected). |
| 12449 | * |
| 12450 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12451 | */ |
| 12452 | @Override |
| 12453 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12454 | TelephonyPermissions |
| 12455 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12456 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12457 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12458 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12459 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12460 | "getSlicingConfig"); |
| 12461 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12462 | final long identity = Binder.clearCallingIdentity(); |
| 12463 | try { |
| 12464 | Phone phone = getDefaultPhone(); |
| 12465 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12466 | } finally { |
| 12467 | Binder.restoreCallingIdentity(identity); |
| 12468 | } |
| 12469 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12470 | |
| 12471 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12472 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12473 | * |
| 12474 | * @param capability The premium capability to check. |
| 12475 | * @param subId The subId to check the premium capability for. |
| 12476 | * |
| 12477 | * @return Whether the given premium capability is available to purchase. |
| 12478 | */ |
| 12479 | @Override |
| 12480 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12481 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12482 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12483 | log("Premium capability " |
| 12484 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12485 | + " is not available for purchase due to missing permissions."); |
| 12486 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12487 | + "permission READ_BASIC_PHONE_STATE."); |
| 12488 | } |
| 12489 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12491 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12492 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12493 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12494 | if (phone == null) { |
| 12495 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12496 | return false; |
| 12497 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12498 | final long identity = Binder.clearCallingIdentity(); |
| 12499 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12500 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12501 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12502 | } finally { |
| 12503 | Binder.restoreCallingIdentity(identity); |
| 12504 | } |
| 12505 | } |
| 12506 | |
| 12507 | /** |
| 12508 | * Purchase the given premium capability from the carrier. |
| 12509 | * |
| 12510 | * @param capability The premium capability to purchase. |
| 12511 | * @param callback The result of the purchase request. |
| 12512 | * @param subId The subId to purchase the premium capability for. |
| 12513 | */ |
| 12514 | @Override |
| 12515 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12516 | log("purchasePremiumCapability: capability=" |
| 12517 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12518 | + getCurrentPackageName()); |
| 12519 | |
| 12520 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12521 | mApp, "purchasePremiumCapability")) { |
| 12522 | log("purchasePremiumCapability " |
| 12523 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12524 | + " failed due to missing permissions."); |
| 12525 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12526 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12527 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12528 | mApp, "purchasePremiumCapability")) { |
| 12529 | log("purchasePremiumCapability " |
| 12530 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12531 | + " failed due to missing permissions."); |
| 12532 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12533 | } |
| 12534 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12535 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12536 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12537 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12538 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12539 | if (phone == null) { |
| 12540 | try { |
| 12541 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12542 | callback.accept(result); |
| 12543 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12544 | } catch (RemoteException e) { |
| 12545 | String logStr = "Purchase premium capability " |
| 12546 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12547 | + " failed due to RemoteException handling null phone: " + e; |
| 12548 | if (DBG) log(logStr); |
| 12549 | AnomalyReporter.reportAnomaly( |
| 12550 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12551 | } |
| 12552 | return; |
| 12553 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12554 | |
| 12555 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12556 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12557 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12558 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12559 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12560 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12561 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12562 | |
| 12563 | boolean isVisible = false; |
| 12564 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12565 | if (am != null) { |
| 12566 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12567 | if (processes != null) { |
| 12568 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12569 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12570 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12571 | if (process.processName.equals(callingProcess) && process.importance |
| 12572 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12573 | isVisible = true; |
| 12574 | break; |
| 12575 | } |
| 12576 | } |
| 12577 | } |
| 12578 | } |
| 12579 | |
| 12580 | if (!isVisible) { |
| 12581 | try { |
| 12582 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12583 | callback.accept(result); |
| 12584 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12585 | } catch (RemoteException e) { |
| 12586 | String logStr = "Purchase premium capability " |
| 12587 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12588 | + " failed due to RemoteException handling background application: " + e; |
| 12589 | if (DBG) log(logStr); |
| 12590 | AnomalyReporter.reportAnomaly( |
| 12591 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12592 | } |
| 12593 | return; |
| 12594 | } |
| 12595 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12596 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12597 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12598 | } |
| 12599 | |
| 12600 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12601 | * Register an IMS connection state callback |
| 12602 | */ |
| 12603 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12604 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12605 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12606 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12607 | // ImsMmTelManager |
| 12608 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12609 | TelephonyPermissions |
| 12610 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12611 | mApp, subId, "registerImsStateCallback"); |
| 12612 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12613 | // ImsRcsManager or SipDelegateManager |
| 12614 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12615 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12616 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12617 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12618 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12619 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12620 | } |
| 12621 | |
| 12622 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12623 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12624 | "IMS not available on device."); |
| 12625 | } |
| 12626 | |
| 12627 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12628 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12629 | } |
| 12630 | |
| 12631 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12632 | if (controller == null) { |
| 12633 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12634 | "IMS not available on device."); |
| 12635 | } |
| 12636 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12637 | if (callingPackage == null) { |
| 12638 | callingPackage = getCurrentPackageName(); |
| 12639 | } |
| 12640 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12641 | final long token = Binder.clearCallingIdentity(); |
| 12642 | try { |
| 12643 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12644 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12645 | } catch (ImsException e) { |
| 12646 | throw new ServiceSpecificException(e.getCode()); |
| 12647 | } finally { |
| 12648 | Binder.restoreCallingIdentity(token); |
| 12649 | } |
| 12650 | } |
| 12651 | |
| 12652 | /** |
| 12653 | * Unregister an IMS connection state callback |
| 12654 | */ |
| 12655 | @Override |
| 12656 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12657 | final long token = Binder.clearCallingIdentity(); |
| 12658 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12659 | if (controller == null) { |
| 12660 | return; |
| 12661 | } |
| 12662 | try { |
| 12663 | controller.unregisterImsStateCallback(cb); |
| 12664 | } finally { |
| 12665 | Binder.restoreCallingIdentity(token); |
| 12666 | } |
| 12667 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12668 | |
| 12669 | /** |
| 12670 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12671 | * |
| 12672 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12673 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12674 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12675 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12676 | * If there is current registered network this value will be same as the registered cell |
| 12677 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12678 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12679 | * it will be cleared and null will be returned. |
| 12680 | * |
| 12681 | */ |
| 12682 | @Override |
| 12683 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12684 | String callingFeatureId) { |
| 12685 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12686 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12687 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12688 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12689 | .setCallingPackage(callingPackage) |
| 12690 | .setCallingFeatureId(callingFeatureId) |
| 12691 | .setCallingPid(Binder.getCallingPid()) |
| 12692 | .setCallingUid(Binder.getCallingUid()) |
| 12693 | .setMethod("getLastKnownCellIdentity") |
| 12694 | .setLogAsInfo(true) |
| 12695 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12696 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12697 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12698 | .build()); |
| 12699 | |
| 12700 | boolean hasFinePermission = |
| 12701 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12702 | if (!hasFinePermission |
| 12703 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12704 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12705 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12706 | } |
| 12707 | |
| 12708 | final long identity = Binder.clearCallingIdentity(); |
| 12709 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12710 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12711 | if (sst == null) return null; |
| 12712 | return sst.getLastKnownCellIdentity(); |
| 12713 | } finally { |
| 12714 | Binder.restoreCallingIdentity(identity); |
| 12715 | } |
| 12716 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12717 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12718 | /** |
| 12719 | * Sets the modem service class Name that Telephony will bind to. |
| 12720 | * |
| 12721 | * @param serviceName The class name of the modem service. |
| 12722 | * @return true if the operation is succeed, otherwise false. |
| 12723 | */ |
| 12724 | public boolean setModemService(String serviceName) { |
| 12725 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12726 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12728 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12729 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12730 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12731 | } |
| 12732 | |
| 12733 | /** |
| 12734 | * Return the class name of the currently bounded modem service. |
| 12735 | * |
| 12736 | * @return the class name of the modem service. |
| 12737 | */ |
| 12738 | public String getModemService() { |
| 12739 | String result; |
| 12740 | Log.d(LOG_TAG, "getModemService"); |
| 12741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12742 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12743 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12744 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12745 | "getModemService"); |
| 12746 | result = mPhoneConfigurationManager.getModemService(); |
| 12747 | Log.d(LOG_TAG, "result = " + result); |
| 12748 | return result; |
| 12749 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12750 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12751 | /** |
| 12752 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12753 | * including carrier config, entitlement server, and config update. |
| 12754 | * |
| 12755 | * @param subId subId The subscription ID of the carrier. |
| 12756 | * |
| 12757 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12758 | * be returned. |
| 12759 | * |
| 12760 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12761 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12762 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12763 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12764 | final long identity = Binder.clearCallingIdentity(); |
| 12765 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12766 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12767 | } finally { |
| 12768 | Binder.restoreCallingIdentity(identity); |
| 12769 | } |
| 12770 | } |
| 12771 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12772 | @Override |
| 12773 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12774 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12775 | mApp.enforceCallingOrSelfPermission( |
| 12776 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12777 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12778 | |
| 12779 | final long identity = Binder.clearCallingIdentity(); |
| 12780 | try { |
| 12781 | Phone phone = getPhone(subId); |
| 12782 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12783 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12784 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12785 | phone.setVoiceServiceStateOverride(hasService); |
| 12786 | } finally { |
| 12787 | Binder.restoreCallingIdentity(identity); |
| 12788 | } |
| 12789 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12790 | |
| 12791 | /** |
| 12792 | * set removable eSIM as default eUICC. |
| 12793 | * |
| 12794 | * @hide |
| 12795 | */ |
| 12796 | @Override |
| 12797 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12798 | enforceModifyPermission(); |
| 12799 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12800 | |
| 12801 | final long identity = Binder.clearCallingIdentity(); |
| 12802 | try { |
| 12803 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12804 | } finally { |
| 12805 | Binder.restoreCallingIdentity(identity); |
| 12806 | } |
| 12807 | } |
| 12808 | |
| 12809 | /** |
| 12810 | * Returns whether the removable eSIM is default eUICC or not. |
| 12811 | * |
| 12812 | * @hide |
| 12813 | */ |
| 12814 | @Override |
| 12815 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12816 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12817 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12818 | |
| 12819 | final long identity = Binder.clearCallingIdentity(); |
| 12820 | try { |
| 12821 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12822 | } finally { |
| 12823 | Binder.restoreCallingIdentity(identity); |
| 12824 | } |
| 12825 | } |
| 12826 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12827 | /** |
| 12828 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12829 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12830 | * application currently configured for this user. |
| 12831 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12832 | * {@code null} if the functionality is not supported. |
| 12833 | * @hide |
| 12834 | */ |
| 12835 | @Override |
| 12836 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12837 | boolean updateIfNeeded) { |
| 12838 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12839 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12840 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12841 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12842 | "getDefaultRespondViaMessageApplication"); |
| 12843 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12844 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12845 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12846 | UserHandle userHandle = null; |
| 12847 | final long identity = Binder.clearCallingIdentity(); |
| 12848 | try { |
| 12849 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12850 | } finally { |
| 12851 | Binder.restoreCallingIdentity(identity); |
| 12852 | } |
| 12853 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12854 | updateIfNeeded, userHandle); |
| 12855 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12856 | |
| 12857 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12858 | * Set whether the device is able to connect with null ciphering or integrity |
| 12859 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12860 | * and all new subscriptions after this. |
| 12861 | * |
| 12862 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12863 | * @hide |
| 12864 | */ |
| 12865 | @Override |
| 12866 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12867 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12868 | enforceModifyPermission(); |
| 12869 | checkForNullCipherAndIntegritySupport(); |
| 12870 | |
| 12871 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12872 | // for listening to these preference changes and applying them immediately. |
| 12873 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12874 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12875 | editor.apply(); |
| 12876 | |
| 12877 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12878 | phone.handleNullCipherEnabledChange(); |
| 12879 | } |
| 12880 | } |
| 12881 | |
| 12882 | |
| 12883 | /** |
| 12884 | * Get whether the device is able to connect with null ciphering or integrity |
| 12885 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12886 | * the state of the radio. |
| 12887 | * |
| 12888 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12889 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12890 | * version for this feature. |
| 12891 | * @hide |
| 12892 | */ |
| 12893 | @Override |
| 12894 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12895 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12896 | enforceReadPermission(); |
| 12897 | checkForNullCipherAndIntegritySupport(); |
| 12898 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12899 | } |
| 12900 | |
| 12901 | private void checkForNullCipherAndIntegritySupport() { |
| 12902 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12903 | throw new UnsupportedOperationException( |
| 12904 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12905 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12906 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12907 | throw new UnsupportedOperationException( |
| 12908 | "Null cipher and integrity operations unsupported by modem"); |
| 12909 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12910 | } |
| 12911 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12912 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12913 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12914 | throw new UnsupportedOperationException( |
| 12915 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12916 | + "above"); |
| 12917 | } |
| 12918 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12919 | throw new UnsupportedOperationException( |
| 12920 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12921 | } |
| 12922 | } |
| 12923 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12924 | private void checkForNullCipherNotificationSupport() { |
| 12925 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12926 | throw new UnsupportedOperationException( |
| 12927 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12928 | } |
| 12929 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12930 | throw new UnsupportedOperationException( |
| 12931 | "Null cipher notification operations unsupported by modem"); |
| 12932 | } |
| 12933 | } |
| 12934 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12935 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12936 | * Get the SIM state for the slot index. |
| 12937 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12938 | * |
| 12939 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12940 | */ |
| 12941 | @Override |
| 12942 | @SimState |
| 12943 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 12944 | if (!mApp.getResources().getBoolean( |
| 12945 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 12946 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12947 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12948 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12949 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12950 | IccCardConstants.State simState; |
| 12951 | if (slotIndex < 0) { |
| 12952 | simState = IccCardConstants.State.UNKNOWN; |
| 12953 | } else { |
| 12954 | Phone phone = null; |
| 12955 | try { |
| 12956 | phone = PhoneFactory.getPhone(slotIndex); |
| 12957 | } catch (IllegalStateException e) { |
| 12958 | // ignore |
| 12959 | } |
| 12960 | if (phone == null) { |
| 12961 | simState = IccCardConstants.State.UNKNOWN; |
| 12962 | } else { |
| 12963 | IccCard icc = phone.getIccCard(); |
| 12964 | if (icc == null) { |
| 12965 | simState = IccCardConstants.State.UNKNOWN; |
| 12966 | } else { |
| 12967 | simState = icc.getState(); |
| 12968 | } |
| 12969 | } |
| 12970 | } |
| 12971 | return simState.ordinal(); |
| 12972 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12973 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12974 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12975 | boolean enableLogcat, |
| 12976 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12977 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12978 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12979 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12980 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12981 | ecdDataBuilder |
| 12982 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12983 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12984 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12985 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12986 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12987 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12988 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12989 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12990 | Executors.newCachedThreadPool(), db, |
| 12991 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12992 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12993 | } |
| 12994 | |
| 12995 | /** |
| 12996 | * Request telephony to persist state for debugging emergency call failures. |
| 12997 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12998 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12999 | * @param enableLogcat whether to collect logcat output |
| 13000 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13001 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13002 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13003 | */ |
| 13004 | @Override |
| 13005 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13006 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13007 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13008 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13009 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13010 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13011 | && Flags.enableReadDropboxPermission()) { |
| 13012 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13013 | "persistEmergencyCallDiagnosticData"); |
| 13014 | } else { |
| 13015 | // Otherwise, enforce legacy permission. |
| 13016 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13017 | "persistEmergencyCallDiagnosticData"); |
| 13018 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13019 | final long identity = Binder.clearCallingIdentity(); |
| 13020 | try { |
| 13021 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13022 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13023 | |
| 13024 | } finally { |
| 13025 | Binder.restoreCallingIdentity(identity); |
| 13026 | } |
| 13027 | } |
| 13028 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13029 | /** |
| 13030 | * Get current cell broadcast ranges. |
| 13031 | */ |
| 13032 | @Override |
| 13033 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13034 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13035 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13036 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13037 | |
| 13038 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13039 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13040 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13041 | final long identity = Binder.clearCallingIdentity(); |
| 13042 | try { |
| 13043 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13044 | } finally { |
| 13045 | Binder.restoreCallingIdentity(identity); |
| 13046 | } |
| 13047 | } |
| 13048 | |
| 13049 | /** |
| 13050 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13051 | * |
| 13052 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13053 | */ |
| 13054 | @Override |
| 13055 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13056 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13057 | @Nullable IIntegerConsumer callback) { |
| 13058 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13059 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13060 | |
| 13061 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13062 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13063 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13064 | final long identity = Binder.clearCallingIdentity(); |
| 13065 | try { |
| 13066 | Phone phone = getPhoneFromSubId(subId); |
| 13067 | if (DBG) { |
| 13068 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13069 | } |
| 13070 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13071 | if (callback != null) { |
| 13072 | try { |
| 13073 | callback.accept(result); |
| 13074 | } catch (RemoteException e) { |
| 13075 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13076 | } |
| 13077 | } |
| 13078 | }); |
| 13079 | } finally { |
| 13080 | Binder.restoreCallingIdentity(identity); |
| 13081 | } |
| 13082 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13083 | |
| 13084 | /** |
| 13085 | * Returns whether the device supports the domain selection service. |
| 13086 | * |
| 13087 | * @return {@code true} if the device supports the domain selection service. |
| 13088 | */ |
| 13089 | @Override |
| 13090 | public boolean isDomainSelectionSupported() { |
| 13091 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13092 | "isDomainSelectionSupported"); |
| 13093 | |
| 13094 | final long identity = Binder.clearCallingIdentity(); |
| 13095 | try { |
| 13096 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13097 | } finally { |
| 13098 | Binder.restoreCallingIdentity(identity); |
| 13099 | } |
| 13100 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13101 | |
| 13102 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13103 | * Returns whether the AOSP domain selection service is supported. |
| 13104 | * |
| 13105 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13106 | * {@code false} otherwise. |
| 13107 | */ |
| 13108 | @Override |
| 13109 | public boolean isAospDomainSelectionService() { |
| 13110 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13111 | "isAospDomainSelectionService"); |
| 13112 | |
| 13113 | final long identity = Binder.clearCallingIdentity(); |
| 13114 | try { |
| 13115 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13116 | String dssComponentName = mApp.getResources().getString( |
| 13117 | R.string.config_domain_selection_service_component_name); |
| 13118 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13119 | TelephonyDomainSelectionService.class.getName()); |
| 13120 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13121 | + ", aosp=" + componentName.flattenToString()); |
| 13122 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13123 | } |
| 13124 | } finally { |
| 13125 | Binder.restoreCallingIdentity(identity); |
| 13126 | } |
| 13127 | return false; |
| 13128 | } |
| 13129 | |
| 13130 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13131 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13132 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13133 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13134 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13135 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13136 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13137 | * {@code false} to disable. |
| 13138 | * @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] | 13139 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13140 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13141 | * |
| 13142 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13143 | */ |
| 13144 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13145 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13146 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13147 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13148 | if (enableSatellite) { |
| 13149 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13150 | @Override |
| 13151 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13152 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13153 | + ", resultData=" + resultData); |
| 13154 | boolean isAllowed = false; |
| 13155 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13156 | callback::accept); |
| 13157 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13158 | if (resultData != null |
| 13159 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13160 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13161 | } else { |
| 13162 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13163 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13164 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13165 | result.accept(resultCode); |
| 13166 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13167 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13168 | if (isAllowed) { |
| 13169 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13170 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13171 | } else { |
| 13172 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13173 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13174 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13175 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13176 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13177 | subId, resultReceiver); |
| 13178 | } else { |
| 13179 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13180 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13181 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13182 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13183 | } |
| 13184 | |
| 13185 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13186 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13187 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13188 | * @param subId The subId of the subscription to check whether satellite is enabled for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13189 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13190 | * 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] | 13191 | * |
| 13192 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13193 | */ |
| 13194 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13195 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13196 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13197 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13198 | } |
| 13199 | |
| 13200 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13201 | * Request to get whether the satellite service demo mode is enabled. |
| 13202 | * |
| 13203 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13204 | * is enabled for. |
| 13205 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13206 | * if the request is successful or an error code if the request failed. |
| 13207 | * |
| 13208 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13209 | */ |
| 13210 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13211 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13212 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13213 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13214 | } |
| 13215 | |
| 13216 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13217 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13218 | * |
| 13219 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13220 | * is enabled for. |
| 13221 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13222 | * enabled if the request is successful or an error code if the request failed. |
| 13223 | * |
| 13224 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13225 | */ |
| 13226 | @Override |
| 13227 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13228 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
joonhunshin | fd78fd5 | 2024-07-11 05:28:13 +0000 | [diff] [blame] | 13229 | mSatelliteController.requestIsEmergencyModeEnabled(subId, result); |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13230 | } |
| 13231 | |
| 13232 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13233 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13234 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13235 | * @param subId The subId of the subscription to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13236 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13237 | * 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] | 13238 | */ |
| 13239 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13240 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13241 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13242 | } |
| 13243 | |
| 13244 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13245 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13246 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13247 | * @param subId The subId of the subscription to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13248 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13249 | * 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] | 13250 | * |
| 13251 | * @throws SecurityException if the caller doesn't have required permission. |
| 13252 | */ |
| 13253 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13254 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13255 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13256 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13257 | } |
| 13258 | |
| 13259 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13260 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13261 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13262 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13263 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13264 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13265 | * @param resultCallback The callback to get the result of the request. |
| 13266 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13267 | * |
| 13268 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13269 | */ |
| 13270 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13271 | public void startSatelliteTransmissionUpdates(int subId, |
| 13272 | @NonNull IIntegerConsumer resultCallback, |
| 13273 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13274 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13275 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13276 | } |
| 13277 | |
| 13278 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13279 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13280 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13281 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13282 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13283 | * @param resultCallback The callback to get the result of the request. |
| 13284 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13285 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13286 | * |
| 13287 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13288 | */ |
| 13289 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13290 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13291 | @NonNull IIntegerConsumer resultCallback, |
| 13292 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13293 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13294 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13295 | } |
| 13296 | |
| 13297 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13298 | * Register the subscription with a satellite provider. |
| 13299 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13300 | * |
| 13301 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13302 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13303 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13304 | * @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] | 13305 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13306 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13307 | * @return The signal transport used by the caller to cancel the provision request, |
| 13308 | * or {@code null} if the request failed. |
| 13309 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13310 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13311 | */ |
| 13312 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13313 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13314 | @NonNull String token, @NonNull byte[] provisionData, |
| 13315 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13316 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13317 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13318 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13319 | } |
| 13320 | |
| 13321 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13322 | * Unregister the device/subscription with the satellite provider. |
| 13323 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13324 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13325 | * should report as deprovisioned. |
| 13326 | * |
| 13327 | * @param subId The subId of the subscription to be deprovisioned. |
| 13328 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13329 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13330 | * |
| 13331 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13332 | */ |
| 13333 | @Override |
| 13334 | public void deprovisionSatelliteService(int subId, |
| 13335 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13336 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13337 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13341 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13342 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13343 | * @param subId The subId of the subscription to register for provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13344 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13345 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13346 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13347 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13348 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13349 | */ |
| 13350 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13351 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13352 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13353 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13354 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13355 | } |
| 13356 | |
| 13357 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13358 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13359 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13360 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13361 | * @param subId The subId of the subscription to unregister for provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13362 | * @param callback The callback that was passed to |
| 13363 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13364 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13365 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13366 | */ |
| 13367 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13368 | public void unregisterForSatelliteProvisionStateChanged( |
| 13369 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13370 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13371 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13372 | } |
| 13373 | |
| 13374 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13375 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13376 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13377 | * @param subId The subId of the subscription to get whether the device is provisioned for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13378 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13379 | * satellite provider if the request is successful or an error code if the |
| 13380 | * request failed. |
| 13381 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13382 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13383 | */ |
| 13384 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13385 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13386 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13387 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13388 | } |
| 13389 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13390 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13391 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13392 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13393 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13394 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13395 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13396 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13397 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13398 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13399 | */ |
| 13400 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13401 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13402 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13403 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13404 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13405 | } |
| 13406 | |
| 13407 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13408 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13409 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13410 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13411 | * @param subId The subId of the subscription to unregister for satellite modem state changed. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13412 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13413 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13414 | * |
| 13415 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13416 | */ |
| 13417 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13418 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13419 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13420 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13421 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13422 | } |
| 13423 | |
| 13424 | /** |
| 13425 | * Register to receive incoming datagrams over satellite. |
| 13426 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13427 | * @param subId The subId of the subscription to register for incoming satellite datagrams. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13428 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13429 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13430 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13431 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13432 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13433 | */ |
| 13434 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13435 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13436 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13437 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13438 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13439 | } |
| 13440 | |
| 13441 | /** |
| 13442 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13443 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13444 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13445 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13446 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13447 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13448 | * |
| 13449 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13450 | */ |
| 13451 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13452 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13453 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13454 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13455 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13456 | } |
| 13457 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13458 | /** |
| 13459 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13460 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13461 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13462 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13463 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13464 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13465 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13466 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13467 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13468 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13469 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13470 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13471 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13472 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13473 | } |
| 13474 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13475 | /** |
| 13476 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13477 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13478 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13479 | * input to this method. Datagram received here will be passed down to modem without any |
| 13480 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13481 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13482 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13483 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13484 | * SOS_SMS or LOCATION_SHARING. |
| 13485 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13486 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13487 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13488 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13489 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13490 | * |
| 13491 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13492 | */ |
| 13493 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13494 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13495 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13496 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13497 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13498 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13499 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13500 | } |
| 13501 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13502 | /** |
| 13503 | * Request to get whether satellite communication is allowed for the current location. |
| 13504 | * |
| 13505 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13506 | * allowed for the current location for. |
| 13507 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13508 | * for the current location if the request is successful or an error code |
| 13509 | * if the request failed. |
| 13510 | * |
| 13511 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13512 | */ |
| 13513 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13514 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13515 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13516 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13517 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13518 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13519 | } |
| 13520 | |
| 13521 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13522 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13523 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13524 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13525 | * @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] | 13526 | * be visible if the request is successful or an error code if the request failed. |
| 13527 | * |
| 13528 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13529 | */ |
| 13530 | @Override |
| 13531 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13532 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13533 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13534 | } |
| 13535 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13536 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13537 | * Inform that Device is aligned to satellite for demo mode. |
| 13538 | * |
| 13539 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13540 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13541 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13542 | * |
| 13543 | * @throws SecurityException if the caller doesn't have required permission. |
| 13544 | */ |
| 13545 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13546 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13547 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13548 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13549 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13550 | } |
| 13551 | |
| 13552 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13553 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13554 | * by modem. |
| 13555 | * |
| 13556 | * @param subId The subId of the subscription to request for. |
| 13557 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13558 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13559 | * operation. |
| 13560 | * |
| 13561 | * @throws SecurityException if the caller doesn't have required permission. |
| 13562 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13563 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13564 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13565 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13566 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13567 | final long identity = Binder.clearCallingIdentity(); |
| 13568 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13569 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13570 | } finally { |
| 13571 | Binder.restoreCallingIdentity(identity); |
| 13572 | } |
| 13573 | } |
| 13574 | |
| 13575 | /** |
| 13576 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13577 | * by modem. |
| 13578 | * |
| 13579 | * @param subId The subId of the subscription to request for. |
| 13580 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13581 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13582 | * operation. |
| 13583 | * |
| 13584 | * @throws SecurityException if the caller doesn't have required permission. |
| 13585 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13586 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13587 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13588 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13589 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13590 | final long identity = Binder.clearCallingIdentity(); |
| 13591 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13592 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13593 | } finally { |
| 13594 | Binder.restoreCallingIdentity(identity); |
| 13595 | } |
| 13596 | } |
| 13597 | |
| 13598 | /** |
| 13599 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13600 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13601 | * |
| 13602 | * @param subId The subId of the subscription to request for. |
| 13603 | * |
| 13604 | * @return Integer array of reasons for disallowing satellite communication. |
| 13605 | * |
| 13606 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13607 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13608 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13609 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13610 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13611 | final long identity = Binder.clearCallingIdentity(); |
| 13612 | try { |
| 13613 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13614 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13615 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13616 | } finally { |
| 13617 | Binder.restoreCallingIdentity(identity); |
| 13618 | } |
| 13619 | } |
| 13620 | |
| 13621 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13622 | * Request to get the signal strength of the satellite connection. |
| 13623 | * |
| 13624 | * @param subId The subId of the subscription to request for. |
| 13625 | * @param result Result receiver to get the error code of the request and the current signal |
| 13626 | * strength of the satellite connection. |
| 13627 | * |
| 13628 | * @throws SecurityException if the caller doesn't have required permission. |
| 13629 | */ |
| 13630 | @Override |
| 13631 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13632 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13633 | final long identity = Binder.clearCallingIdentity(); |
| 13634 | try { |
| 13635 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13636 | } finally { |
| 13637 | Binder.restoreCallingIdentity(identity); |
| 13638 | } |
| 13639 | } |
| 13640 | |
| 13641 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13642 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13643 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13644 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13645 | * |
| 13646 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13647 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13648 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13649 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13650 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13651 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13652 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13653 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13654 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13655 | */ |
| 13656 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13657 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13658 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13659 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13660 | final long identity = Binder.clearCallingIdentity(); |
| 13661 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13662 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13663 | } finally { |
| 13664 | Binder.restoreCallingIdentity(identity); |
| 13665 | } |
| 13666 | } |
| 13667 | |
| 13668 | /** |
| 13669 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13670 | * If callback was not registered before, the request will be ignored. |
| 13671 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13672 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13673 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13674 | * @param callback The callback that was passed to |
| 13675 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13676 | * |
| 13677 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13678 | */ |
| 13679 | @Override |
| 13680 | public void unregisterForNtnSignalStrengthChanged( |
| 13681 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13682 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13683 | final long identity = Binder.clearCallingIdentity(); |
| 13684 | try { |
| 13685 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13686 | } finally { |
| 13687 | Binder.restoreCallingIdentity(identity); |
| 13688 | } |
| 13689 | } |
| 13690 | |
| 13691 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13692 | * Registers for satellite capabilities change event from the satellite service. |
| 13693 | * |
| 13694 | * @param subId The subId of the subscription to request for. |
| 13695 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13696 | * |
| 13697 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13698 | * |
| 13699 | * @throws SecurityException if the caller doesn't have required permission. |
| 13700 | */ |
| 13701 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13702 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13703 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13704 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13705 | final long identity = Binder.clearCallingIdentity(); |
| 13706 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13707 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13708 | } finally { |
| 13709 | Binder.restoreCallingIdentity(identity); |
| 13710 | } |
| 13711 | } |
| 13712 | |
| 13713 | /** |
| 13714 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13715 | * If callback was not registered before, the request will be ignored. |
| 13716 | * |
| 13717 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13718 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13719 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 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 | public void unregisterForCapabilitiesChanged(int subId, |
| 13725 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13726 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13727 | final long identity = Binder.clearCallingIdentity(); |
| 13728 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13729 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13730 | } finally { |
| 13731 | Binder.restoreCallingIdentity(identity); |
| 13732 | } |
| 13733 | } |
| 13734 | |
| 13735 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13736 | * Registers for the satellite supported state changed. |
| 13737 | * |
| 13738 | * @param subId The subId of the subscription to register for supported state changed. |
| 13739 | * @param callback The callback to handle the satellite supported state changed event. |
| 13740 | * |
| 13741 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13742 | * |
| 13743 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13744 | */ |
| 13745 | @Override |
| 13746 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13747 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13748 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13749 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13750 | } |
| 13751 | |
| 13752 | /** |
| 13753 | * Unregisters for the satellite supported state changed. |
| 13754 | * If callback was not registered before, the request will be ignored. |
| 13755 | * |
| 13756 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13757 | * @param callback The callback that was passed to |
| 13758 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13759 | * |
| 13760 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13761 | */ |
| 13762 | @Override |
| 13763 | public void unregisterForSatelliteSupportedStateChanged( |
| 13764 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13765 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13766 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13767 | } |
| 13768 | |
| 13769 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13770 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13771 | * |
| 13772 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13773 | * @param provisioned Whether satellite should be provisioned or not. |
| 13774 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13775 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13776 | * {@code false} otherwise. |
| 13777 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13778 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 13779 | String provisioned) { |
| 13780 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 13781 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13782 | TelephonyPermissions.enforceShellOnly( |
| 13783 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13785 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13786 | "setSatelliteServicePackageName"); |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13787 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 13788 | provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13789 | } |
| 13790 | |
| 13791 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13792 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13793 | * |
| 13794 | * @param servicePackageName The package name of the satellite gateway service. |
| 13795 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13796 | * {@code false} otherwise. |
| 13797 | */ |
| 13798 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13799 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13800 | TelephonyPermissions.enforceShellOnly( |
| 13801 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13803 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13804 | "setSatelliteGatewayServicePackageName"); |
| 13805 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13806 | } |
| 13807 | |
| 13808 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13809 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13810 | * |
| 13811 | * @param packageName The package name of the satellite pointing UI app. |
| 13812 | * @param className The class name of the satellite pointing UI app. |
| 13813 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13814 | * {@code false} otherwise. |
| 13815 | */ |
| 13816 | public boolean setSatellitePointingUiClassName( |
| 13817 | @Nullable String packageName, @Nullable String className) { |
| 13818 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13819 | + ", className=" + className); |
| 13820 | TelephonyPermissions.enforceShellOnly( |
| 13821 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13823 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13824 | "setSatelliteGatewayServicePackageName"); |
| 13825 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13826 | } |
| 13827 | |
| 13828 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13829 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13830 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13831 | * listening mode. |
| 13832 | * |
| 13833 | * @param timeoutMillis The timeout duration in millisecond. |
| 13834 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13835 | */ |
| 13836 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13837 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13838 | TelephonyPermissions.enforceShellOnly( |
| 13839 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13841 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13842 | "setSatelliteListeningTimeoutDuration"); |
| 13843 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13844 | } |
| 13845 | |
| 13846 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13847 | * This API can be used by only CTS to override the timeout durations used by the |
| 13848 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13849 | * |
| 13850 | * @param timeoutMillis The timeout duration in millisecond. |
| 13851 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13852 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13853 | public boolean setDatagramControllerTimeoutDuration( |
| 13854 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13855 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13856 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13857 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13858 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13860 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13861 | "setDatagramControllerTimeoutDuration"); |
| 13862 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13863 | reset, timeoutType, timeoutMillis); |
| 13864 | } |
| 13865 | |
| 13866 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 13867 | * This API can be used by only CTS to override the boolean configs used by the |
| 13868 | * DatagramController module. |
| 13869 | * |
| 13870 | * @param enable Whether to enable or disable boolean config. |
| 13871 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 13872 | */ |
| 13873 | public boolean setDatagramControllerBooleanConfig( |
| 13874 | boolean reset, int booleanType, boolean enable) { |
| 13875 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 13876 | + ", reset=" + reset + ", enable=" + enable); |
| 13877 | TelephonyPermissions.enforceShellOnly( |
| 13878 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 13879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13880 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13881 | "ssetDatagramControllerBooleanConfig"); |
| 13882 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable); |
| 13883 | } |
| 13884 | |
| 13885 | |
| 13886 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13887 | * This API can be used by only CTS to override the timeout durations used by the |
| 13888 | * SatelliteController module. |
| 13889 | * |
| 13890 | * @param timeoutMillis The timeout duration in millisecond. |
| 13891 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13892 | */ |
| 13893 | public boolean setSatelliteControllerTimeoutDuration( |
| 13894 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13895 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13896 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13897 | TelephonyPermissions.enforceShellOnly( |
| 13898 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13900 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13901 | "setSatelliteControllerTimeoutDuration"); |
| 13902 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13903 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13904 | } |
| 13905 | |
| 13906 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13907 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13908 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13909 | * |
| 13910 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13911 | * of the following values to enable the override: |
| 13912 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13913 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13914 | * To disable the override, use -1 for handoverType. |
| 13915 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13916 | * delaySeconds after the emergency call starts. |
| 13917 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13918 | */ |
| 13919 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13920 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13921 | TelephonyPermissions.enforceShellOnly( |
| 13922 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13924 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13925 | "setEmergencyCallToSatelliteHandoverType"); |
| 13926 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13927 | handoverType, delaySeconds); |
| 13928 | } |
| 13929 | |
| 13930 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13931 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13932 | * |
| 13933 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13934 | * otherwise. |
| 13935 | * @param isProvisioned The overriding provision status. |
| 13936 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13937 | */ |
| 13938 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13939 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13940 | + ", isProvisioned=" + isProvisioned); |
| 13941 | TelephonyPermissions.enforceShellOnly( |
| 13942 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13944 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13945 | "setOemEnabledSatelliteProvisionStatus"); |
| 13946 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13947 | } |
| 13948 | |
| 13949 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13950 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13951 | * |
| 13952 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13953 | */ |
| 13954 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13955 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13956 | long locationCountryCodeTimestampNanos) { |
| 13957 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13958 | + String.join(", ", currentNetworkCountryCodes) |
| 13959 | + ", locationCountryCode=" + locationCountryCode |
| 13960 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13961 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13962 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13963 | TelephonyPermissions.enforceShellOnly( |
| 13964 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13966 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13967 | "setCachedLocationCountryCode"); |
| 13968 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13969 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13970 | locationCountryCodeTimestampNanos); |
| 13971 | } |
| 13972 | |
| 13973 | /** |
| 13974 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13975 | * access controller. |
| 13976 | * |
| 13977 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13978 | * otherwise. |
| 13979 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13980 | */ |
| 13981 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13982 | String s2CellFile, long locationFreshDurationNanos, |
| 13983 | List<String> satelliteCountryCodes) { |
| 13984 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13985 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13986 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13987 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13988 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13989 | TelephonyPermissions.enforceShellOnly( |
| 13990 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13992 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13993 | "setSatelliteAccessControlOverlayConfigs"); |
| 13994 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13995 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13996 | } |
| 13997 | |
| 13998 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13999 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14000 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14001 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14002 | * |
| 14003 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14004 | * satellite modem or not. |
| 14005 | * |
| 14006 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14007 | */ |
| 14008 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14009 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14010 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14011 | + "disabled"); |
| 14012 | return false; |
| 14013 | } |
| 14014 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14015 | TelephonyPermissions.enforceShellOnly( |
| 14016 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14018 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14019 | "setShouldSendDatagramToModemInDemoMode"); |
| 14020 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14021 | shouldSendToModemInDemoMode); |
| 14022 | } |
| 14023 | |
| 14024 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14025 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14026 | * |
| 14027 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14028 | * the allowed state. |
| 14029 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14030 | */ |
| 14031 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14032 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14033 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14034 | + "oemEnabledSatelliteFlag is disabled"); |
| 14035 | return false; |
| 14036 | } |
| 14037 | |
| 14038 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14039 | + "state=" + state); |
| 14040 | TelephonyPermissions.enforceShellOnly( |
| 14041 | Binder.getCallingUid(), |
| 14042 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14044 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14045 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14046 | return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache( |
| 14047 | state); |
| 14048 | } |
| 14049 | |
| 14050 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14051 | * Sets the service defined in ComponentName to be bound. |
| 14052 | * |
| 14053 | * This should only be used for testing. |
| 14054 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14055 | * {@code false} otherwise. |
| 14056 | */ |
| 14057 | @Override |
| 14058 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14059 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14060 | |
| 14061 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14062 | "setDomainSelectionServiceOverride"); |
| 14063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14064 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14065 | |
| 14066 | final long identity = Binder.clearCallingIdentity(); |
| 14067 | try { |
| 14068 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14069 | return DomainSelectionResolver.getInstance() |
| 14070 | .setDomainSelectionServiceOverride(componentName); |
| 14071 | } |
| 14072 | } finally { |
| 14073 | Binder.restoreCallingIdentity(identity); |
| 14074 | } |
| 14075 | return false; |
| 14076 | } |
| 14077 | |
| 14078 | /** |
| 14079 | * Clears the DomainSelectionService override. |
| 14080 | * |
| 14081 | * This should only be used for testing. |
| 14082 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14083 | * {@code false} otherwise. |
| 14084 | */ |
| 14085 | @Override |
| 14086 | public boolean clearDomainSelectionServiceOverride() { |
| 14087 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14088 | |
| 14089 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14090 | "clearDomainSelectionServiceOverride"); |
| 14091 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14092 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14093 | |
| 14094 | final long identity = Binder.clearCallingIdentity(); |
| 14095 | try { |
| 14096 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14097 | return DomainSelectionResolver.getInstance() |
| 14098 | .clearDomainSelectionServiceOverride(); |
| 14099 | } |
| 14100 | } finally { |
| 14101 | Binder.restoreCallingIdentity(identity); |
| 14102 | } |
| 14103 | return false; |
| 14104 | } |
| 14105 | |
| 14106 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14107 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14108 | * |
| 14109 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14110 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14111 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14112 | * |
| 14113 | * @param enable if notifications about disclosure events should be enabled |
| 14114 | * @throws SecurityException if the caller does not have the required privileges |
| 14115 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14116 | */ |
| 14117 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14118 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14119 | enforceModifyPermission(); |
| 14120 | checkForIdentifierDisclosureNotificationSupport(); |
| 14121 | |
| 14122 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14123 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14124 | editor.apply(); |
| 14125 | |
| 14126 | // Each phone instance is responsible for updating its respective modem immediately |
| 14127 | // after we've made a preference change. |
| 14128 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14129 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14130 | } |
| 14131 | } |
| 14132 | |
| 14133 | /** |
| 14134 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14135 | * |
| 14136 | * @throws SecurityException if the caller does not have the required privileges |
| 14137 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14138 | */ |
| 14139 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14140 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14141 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14142 | checkForIdentifierDisclosureNotificationSupport(); |
| 14143 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14144 | } |
| 14145 | |
| 14146 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14147 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14148 | * are in use by the cellular modem. |
| 14149 | * |
| 14150 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14151 | * @throws SecurityException if the caller does not have the required privileges |
| 14152 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14153 | * and integrity algorithms in use |
| 14154 | * @hide |
| 14155 | */ |
| 14156 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14157 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14158 | enforceModifyPermission(); |
| 14159 | checkForNullCipherNotificationSupport(); |
| 14160 | |
| 14161 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14162 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14163 | editor.apply(); |
| 14164 | |
| 14165 | // Each phone instance is responsible for updating its respective modem immediately |
| 14166 | // after a preference change. |
| 14167 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14168 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14169 | } |
| 14170 | } |
| 14171 | |
| 14172 | /** |
| 14173 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14174 | * cellular modem. |
| 14175 | * |
| 14176 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14177 | * @throws SecurityException if the caller does not have the required privileges |
| 14178 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14179 | * and integrity algorithms in use |
| 14180 | * @hide |
| 14181 | */ |
| 14182 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14183 | public boolean isNullCipherNotificationsEnabled() { |
| 14184 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14185 | checkForNullCipherNotificationSupport(); |
| 14186 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14187 | } |
| 14188 | |
| 14189 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14190 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14191 | * |
| 14192 | * <p>This method behaves in one of the following ways: |
| 14193 | * <ul> |
| 14194 | * <li>return true : if the calling package has the appop permission {@link |
| 14195 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14196 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14197 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14198 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14199 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14200 | * </ul> |
| 14201 | */ |
| 14202 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14203 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14204 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14205 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14206 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14207 | return true; |
| 14208 | } |
| 14209 | } |
| 14210 | return false; |
| 14211 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14212 | |
| 14213 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14214 | * @return The subscription manager service instance. |
| 14215 | */ |
| 14216 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14217 | return SubscriptionManagerService.getInstance(); |
| 14218 | } |
| 14219 | |
| 14220 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14221 | * Class binds the consumer[callback] and carrierId. |
| 14222 | */ |
| 14223 | private static class CallerCallbackInfo { |
| 14224 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14225 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14226 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14227 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14228 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14229 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14230 | } |
| 14231 | |
| 14232 | public Consumer<Integer> getConsumer() { |
| 14233 | return mConsumer; |
| 14234 | } |
| 14235 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14236 | public Set<Integer> getCarrierIds() { |
| 14237 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14238 | } |
| 14239 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14240 | |
| 14241 | /* |
| 14242 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14243 | * But the context that is passed in is unused if the phone app is already alive. |
| 14244 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14245 | */ |
| 14246 | @VisibleForTesting |
| 14247 | public void setPackageManager(PackageManager packageManager) { |
| 14248 | mPackageManager = packageManager; |
| 14249 | } |
| 14250 | |
| 14251 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14252 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14253 | * But the context that is passed in is unused if the phone app is already alive. |
| 14254 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14255 | */ |
| 14256 | @VisibleForTesting |
| 14257 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14258 | mAppOps = appOps; |
| 14259 | } |
| 14260 | |
| 14261 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14262 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14263 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14264 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14265 | */ |
| 14266 | @VisibleForTesting |
| 14267 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14268 | mFeatureFlags = featureFlags; |
| 14269 | } |
| 14270 | |
| 14271 | /** |
| 14272 | * Make sure the device has required telephony feature |
| 14273 | * |
| 14274 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14275 | */ |
| 14276 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14277 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14278 | if (callingPackage == null || mPackageManager == null) { |
| 14279 | return; |
| 14280 | } |
| 14281 | |
| 14282 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14283 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14284 | Binder.getCallingUserHandle()) |
| 14285 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14286 | // Skip to check associated telephony feature, |
| 14287 | // if compatibility change is not enabled for the current process or |
| 14288 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14289 | return; |
| 14290 | } |
| 14291 | |
| 14292 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14293 | throw new UnsupportedOperationException( |
| 14294 | methodName + " is unsupported without " + telephonyFeature); |
| 14295 | } |
| 14296 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14297 | |
| 14298 | /** |
| 14299 | * Registers for the satellite communication allowed state changed. |
| 14300 | * |
| 14301 | * @param subId The subId of the subscription to register for the satellite communication |
| 14302 | * allowed state changed. |
| 14303 | * @param callback The callback to handle the satellite communication allowed |
| 14304 | * state changed event. |
| 14305 | * |
| 14306 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14307 | * |
| 14308 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14309 | */ |
| 14310 | @Override |
| 14311 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14312 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14313 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
| 14314 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14315 | subId, callback); |
| 14316 | } |
| 14317 | |
| 14318 | /** |
| 14319 | * Unregisters for the satellite communication allowed state changed. |
| 14320 | * If callback was not registered before, the request will be ignored. |
| 14321 | * |
| 14322 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14323 | * allowed state changed. |
| 14324 | * @param callback The callback that was passed to |
| 14325 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14326 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14327 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14328 | */ |
| 14329 | @Override |
| 14330 | public void unregisterForCommunicationAllowedStateChanged( |
| 14331 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14332 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
| 14333 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback); |
| 14334 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14335 | |
| 14336 | /** |
| 14337 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14338 | * |
| 14339 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14340 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14341 | * if the request is successful or an error code if the request failed. |
| 14342 | * |
| 14343 | * @throws SecurityException if the caller doesn't have required permission. |
| 14344 | */ |
| 14345 | @Override |
| 14346 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14347 | enforceModifyPermission(); |
| 14348 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
| 14349 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14350 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14351 | |
| 14352 | /** |
| 14353 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14354 | * |
| 14355 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14356 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14357 | * |
| 14358 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14359 | */ |
| 14360 | @Override |
| 14361 | public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) { |
| 14362 | enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds"); |
| 14363 | mSatelliteController.requestProvisionSubscriberIds(result); |
| 14364 | } |
| 14365 | |
| 14366 | /** |
| 14367 | * Request to get provisioned status for given a satellite subscriber id. |
| 14368 | * |
| 14369 | * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check. |
| 14370 | * @param result The result receiver, which returns the provisioned status of the token if the |
| 14371 | * request is successful or an error code if the request failed. |
| 14372 | * |
| 14373 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14374 | */ |
| 14375 | @Override |
Hyosun Kim | c7ae4d5 | 2024-07-05 02:44:27 +0000 | [diff] [blame] | 14376 | public void requestIsProvisioned(@NonNull String satelliteSubscriberId, |
| 14377 | @NonNull ResultReceiver result) { |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14378 | enforceSatelliteCommunicationPermission("requestIsProvisioned"); |
| 14379 | mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result); |
| 14380 | } |
| 14381 | |
| 14382 | /** |
| 14383 | * Deliver the list of provisioned satellite subscriber ids. |
| 14384 | * |
| 14385 | * @param list List of provisioned satellite subscriber ids. |
| 14386 | * @param result The result receiver that returns whether deliver success or fail. |
| 14387 | * |
| 14388 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14389 | */ |
| 14390 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame^] | 14391 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14392 | @NonNull ResultReceiver result) { |
| 14393 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
| 14394 | mSatelliteController.provisionSatellite(list, result); |
| 14395 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14396 | } |