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; |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 167 | import android.telephony.satellite.ProvisionSubscriberId; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
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 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 482 | /** |
| 483 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 484 | * one ICCID active at the same time. |
| 485 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 486 | * |
| 487 | * @hide |
| 488 | */ |
| 489 | @ChangeId |
| 490 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 491 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 492 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 493 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 494 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 495 | * operation fails. |
| 496 | */ |
| 497 | @ChangeId |
| 498 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 499 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 500 | |
| 501 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 502 | * A request object to use for transmitting data to an ICC. |
| 503 | */ |
| 504 | private static final class IccAPDUArgument { |
| 505 | public int channel, cla, command, p1, p2, p3; |
| 506 | public String data; |
| 507 | |
| 508 | public IccAPDUArgument(int channel, int cla, int command, |
| 509 | int p1, int p2, int p3, String data) { |
| 510 | this.channel = channel; |
| 511 | this.cla = cla; |
| 512 | this.command = command; |
| 513 | this.p1 = p1; |
| 514 | this.p2 = p2; |
| 515 | this.p3 = p3; |
| 516 | this.data = data; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 521 | * A request object to use for transmitting data to an ICC. |
| 522 | */ |
| 523 | private static final class ManualNetworkSelectionArgument { |
| 524 | public OperatorInfo operatorInfo; |
| 525 | public boolean persistSelection; |
| 526 | |
| 527 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 528 | this.operatorInfo = operatorInfo; |
| 529 | this.persistSelection = persistSelection; |
| 530 | } |
| 531 | } |
| 532 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 533 | private static final class PurchasePremiumCapabilityArgument { |
| 534 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 535 | public @NonNull IIntegerConsumer callback; |
| 536 | |
| 537 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 538 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 539 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 540 | this.callback = callback; |
| 541 | } |
| 542 | } |
| 543 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 544 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 546 | * request after sending. The main thread will notify the request when it is complete. |
| 547 | */ |
| 548 | private static final class MainThreadRequest { |
| 549 | /** The argument to use for the request */ |
| 550 | public Object argument; |
| 551 | /** The result of the request that is run on the main thread */ |
| 552 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 553 | // The subscriber id that this request applies to. Defaults to |
| 554 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 555 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 557 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 558 | public Phone phone; |
| 559 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 560 | public WorkSource workSource; |
| 561 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 562 | public MainThreadRequest(Object argument) { |
| 563 | this.argument = argument; |
| 564 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 565 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 566 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 567 | this.argument = argument; |
| 568 | if (phone != null) { |
| 569 | this.phone = phone; |
| 570 | } |
| 571 | this.workSource = workSource; |
| 572 | } |
| 573 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 574 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 575 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 576 | if (subId != null) { |
| 577 | this.subId = subId; |
| 578 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 579 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 583 | private static final class IncomingThirdPartyCallArgs { |
| 584 | public final ComponentName component; |
| 585 | public final String callId; |
| 586 | public final String callerDisplayName; |
| 587 | |
| 588 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 589 | String callerDisplayName) { |
| 590 | this.component = component; |
| 591 | this.callId = callId; |
| 592 | this.callerDisplayName = callerDisplayName; |
| 593 | } |
| 594 | } |
| 595 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 596 | /** |
| 597 | * A handler that processes messages on the main thread in the phone process. Since many |
| 598 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 599 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 600 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 601 | * on, which will be notified when the operation completes and will contain the result of the |
| 602 | * request. |
| 603 | * |
| 604 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 605 | * note that request.result must be set to something non-null for the calling thread to |
| 606 | * unblock. |
| 607 | */ |
| 608 | private final class MainThreadHandler extends Handler { |
| 609 | @Override |
| 610 | public void handleMessage(Message msg) { |
| 611 | MainThreadRequest request; |
| 612 | Message onCompleted; |
| 613 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 614 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 616 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 617 | |
| 618 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | case CMD_HANDLE_USSD_REQUEST: { |
| 620 | request = (MainThreadRequest) msg.obj; |
| 621 | final Phone phone = getPhoneFromRequest(request); |
| 622 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 623 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 625 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | if (!isUssdApiAllowed(request.subId)) { |
| 627 | // Carrier does not support use of this API, return failure. |
| 628 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 629 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 630 | Bundle returnData = new Bundle(); |
| 631 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 632 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 633 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | request.result = true; |
| 635 | notifyRequester(request); |
| 636 | return; |
| 637 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 638 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | try { |
| 640 | request.result = phone != null |
| 641 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 642 | } catch (CallStateException cse) { |
| 643 | request.result = false; |
| 644 | } |
| 645 | // Wake up the requesting thread |
| 646 | notifyRequester(request); |
| 647 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 650 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 651 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 652 | final Phone phone = getPhoneFromRequest(request); |
| 653 | request.result = phone != null ? |
| 654 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 655 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 656 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 658 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 659 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 660 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 664 | uiccPort = getUiccPortFromRequest(request); |
| 665 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 666 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 671 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 672 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 673 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 674 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 675 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | ar = (AsyncResult) msg.obj; |
| 681 | request = (MainThreadRequest) ar.userObj; |
| 682 | if (ar.exception == null && ar.result != null) { |
| 683 | request.result = ar.result; |
| 684 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 685 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | if (ar.result == null) { |
| 687 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } else { |
| 692 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 693 | } |
| 694 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 695 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | break; |
| 697 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 698 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 699 | request = (MainThreadRequest) msg.obj; |
| 700 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 701 | uiccPort = getUiccPortFromRequest(request); |
| 702 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 704 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | } else { |
| 707 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 708 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 709 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 710 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 711 | iccArgument.p2, |
| 712 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 713 | } |
| 714 | break; |
| 715 | |
| 716 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 717 | ar = (AsyncResult) msg.obj; |
| 718 | request = (MainThreadRequest) ar.userObj; |
| 719 | if (ar.exception == null && ar.result != null) { |
| 720 | request.result = ar.result; |
| 721 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 722 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | if (ar.result == null) { |
| 724 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 725 | } else if (ar.exception instanceof CommandException) { |
| 726 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 727 | ar.exception); |
| 728 | } else { |
| 729 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 730 | } |
| 731 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case CMD_EXCHANGE_SIM_IO: |
| 736 | request = (MainThreadRequest) msg.obj; |
| 737 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 738 | uiccPort = getUiccPortFromRequest(request); |
| 739 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 740 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 741 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | } else { |
| 744 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 745 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 746 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 747 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 748 | iccArgument.data, onCompleted); |
| 749 | } |
| 750 | break; |
| 751 | |
| 752 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 753 | ar = (AsyncResult) msg.obj; |
| 754 | request = (MainThreadRequest) ar.userObj; |
| 755 | if (ar.exception == null && ar.result != null) { |
| 756 | request.result = ar.result; |
| 757 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 758 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 763 | case CMD_SEND_ENVELOPE: |
| 764 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 765 | uiccPort = getUiccPortFromRequest(request); |
| 766 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 768 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 769 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | } else { |
| 771 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 772 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 774 | break; |
| 775 | |
| 776 | case EVENT_SEND_ENVELOPE_DONE: |
| 777 | ar = (AsyncResult) msg.obj; |
| 778 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 779 | if (ar.exception == null && ar.result != null) { |
| 780 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 781 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 782 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 783 | if (ar.result == null) { |
| 784 | loge("sendEnvelopeWithStatus: Empty response"); |
| 785 | } else if (ar.exception instanceof CommandException) { |
| 786 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 787 | ar.exception); |
| 788 | } else { |
| 789 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 790 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 791 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 792 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 793 | break; |
| 794 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 795 | case CMD_OPEN_CHANNEL: |
| 796 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 797 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 798 | IccLogicalChannelRequest openChannelRequest = |
| 799 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 800 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 801 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 802 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 803 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 804 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 805 | } else { |
| 806 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 807 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 808 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 809 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case EVENT_OPEN_CHANNEL_DONE: |
| 813 | ar = (AsyncResult) msg.obj; |
| 814 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 815 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 817 | int[] result = (int[]) ar.result; |
| 818 | int channelId = result[0]; |
| 819 | byte[] selectResponse = null; |
| 820 | if (result.length > 1) { |
| 821 | selectResponse = new byte[result.length - 1]; |
| 822 | for (int i = 1; i < result.length; ++i) { |
| 823 | selectResponse[i - 1] = (byte) result[i]; |
| 824 | } |
| 825 | } |
| 826 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 828 | |
| 829 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 830 | if (uiccPort == null) { |
| 831 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 832 | } else { |
| 833 | IccLogicalChannelRequest channelRequest = |
| 834 | (IccLogicalChannelRequest) request.argument; |
| 835 | channelRequest.channel = channelId; |
| 836 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 837 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 838 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 839 | if (ar.result == null) { |
| 840 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 842 | if (ar.exception != null) { |
| 843 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 844 | } |
| 845 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 846 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 847 | if (ar.exception instanceof CommandException) { |
| 848 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 849 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 850 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 851 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 852 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 853 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 857 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 858 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 859 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 860 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case CMD_CLOSE_CHANNEL: |
| 864 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 865 | uiccPort = getUiccPortFromRequest(request); |
| 866 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 867 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 868 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 869 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 870 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 871 | } else { |
| 872 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 873 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 874 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
| 880 | if (ar.exception == null) { |
| 881 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 882 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 883 | if (uiccPort == null) { |
| 884 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 885 | } else { |
| 886 | final int channelId = (Integer) request.argument; |
| 887 | uiccPort.onLogicalChannelClosed(channelId); |
| 888 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 889 | } else { |
| 890 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 891 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 892 | if (ar.exception instanceof CommandException) { |
| 893 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 894 | CommandException.Error error = |
| 895 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 896 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 897 | // should only throw exceptions from the binder threads. |
| 898 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 899 | "iccCloseLogicalChannel: invalid argument "); |
| 900 | } |
| 901 | } else { |
| 902 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 903 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 904 | request.result = (exception != null) ? exception : |
| 905 | new IllegalStateException( |
| 906 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 907 | } |
| 908 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case CMD_NV_READ_ITEM: |
| 912 | request = (MainThreadRequest) msg.obj; |
| 913 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 914 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 915 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 919 | ar = (AsyncResult) msg.obj; |
| 920 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | if (ar.exception == null && ar.result != null) { |
| 922 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 923 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 924 | request.result = ""; |
| 925 | if (ar.result == null) { |
| 926 | loge("nvReadItem: Empty response"); |
| 927 | } else if (ar.exception instanceof CommandException) { |
| 928 | loge("nvReadItem: CommandException: " + |
| 929 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 930 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 932 | } |
| 933 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 934 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 935 | break; |
| 936 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 937 | case CMD_NV_WRITE_ITEM: |
| 938 | request = (MainThreadRequest) msg.obj; |
| 939 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 940 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 941 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 942 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 943 | break; |
| 944 | |
| 945 | case EVENT_NV_WRITE_ITEM_DONE: |
| 946 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 947 | break; |
| 948 | |
| 949 | case CMD_NV_WRITE_CDMA_PRL: |
| 950 | request = (MainThreadRequest) msg.obj; |
| 951 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 952 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 956 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 957 | break; |
| 958 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 959 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 960 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 961 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 962 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 963 | break; |
| 964 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 965 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 966 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 967 | break; |
| 968 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 969 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 972 | request); |
| 973 | Phone phone = getPhoneFromRequest(request); |
| 974 | if (phone != null) { |
| 975 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 976 | } else { |
| 977 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 978 | request.result = false; |
| 979 | notifyRequester(request); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | |
| 984 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
| 987 | if (ar.exception == null && ar.result != null) { |
| 988 | request.result = ar.result; |
| 989 | } else { |
| 990 | // request.result must be set to something non-null |
| 991 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 992 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 993 | request.result = ar.result; |
| 994 | } else { |
| 995 | request.result = false; |
| 996 | } |
| 997 | if (ar.result == null) { |
| 998 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 999 | } else if (ar.exception instanceof CommandException) { |
| 1000 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1001 | + ar.exception); |
| 1002 | } else { |
| 1003 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1004 | } |
| 1005 | } |
| 1006 | notifyRequester(request); |
| 1007 | break; |
| 1008 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1009 | case CMD_IS_VONR_ENABLED: { |
| 1010 | request = (MainThreadRequest) msg.obj; |
| 1011 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1012 | request); |
| 1013 | Phone phone = getPhoneFromRequest(request); |
| 1014 | if (phone != null) { |
| 1015 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1016 | } else { |
| 1017 | loge("isVoNrEnabled: No phone object"); |
| 1018 | request.result = false; |
| 1019 | notifyRequester(request); |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | if (ar.exception == null && ar.result != null) { |
| 1028 | request.result = ar.result; |
| 1029 | } else { |
| 1030 | // request.result must be set to something non-null |
| 1031 | // for the calling thread to unblock |
| 1032 | if (ar.result != null) { |
| 1033 | request.result = ar.result; |
| 1034 | } else { |
| 1035 | request.result = false; |
| 1036 | } |
| 1037 | if (ar.result == null) { |
| 1038 | loge("isVoNrEnabled: Empty response"); |
| 1039 | } else if (ar.exception instanceof CommandException) { |
| 1040 | loge("isVoNrEnabled: CommandException: " |
| 1041 | + ar.exception); |
| 1042 | } else { |
| 1043 | loge("isVoNrEnabled: Unknown exception"); |
| 1044 | } |
| 1045 | } |
| 1046 | notifyRequester(request); |
| 1047 | break; |
| 1048 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1049 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1052 | Phone phone = getPhoneFromRequest(request); |
| 1053 | if (phone != null) { |
| 1054 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1055 | request.workSource); |
| 1056 | } else { |
| 1057 | loge("enableNrDualConnectivity: No phone object"); |
| 1058 | request.result = |
| 1059 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1060 | notifyRequester(request); |
| 1061 | } |
| 1062 | break; |
| 1063 | } |
| 1064 | |
| 1065 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null) { |
| 1069 | request.result = |
| 1070 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1071 | } else { |
| 1072 | request.result = |
| 1073 | TelephonyManager |
| 1074 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1075 | if (ar.exception instanceof CommandException) { |
| 1076 | CommandException.Error error = |
| 1077 | ((CommandException) (ar.exception)).getCommandError(); |
| 1078 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1079 | request.result = |
| 1080 | TelephonyManager |
| 1081 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1082 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1083 | request.result = |
| 1084 | TelephonyManager |
| 1085 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1086 | } |
| 1087 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1088 | + ar.exception); |
| 1089 | } else { |
| 1090 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1091 | } |
| 1092 | } |
| 1093 | notifyRequester(request); |
| 1094 | break; |
| 1095 | } |
| 1096 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1097 | case CMD_ENABLE_VONR: { |
| 1098 | request = (MainThreadRequest) msg.obj; |
| 1099 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1100 | Phone phone = getPhoneFromRequest(request); |
| 1101 | if (phone != null) { |
| 1102 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1103 | request.workSource); |
| 1104 | } else { |
| 1105 | loge("setVoNrEnabled: No phone object"); |
| 1106 | request.result = |
| 1107 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1108 | notifyRequester(request); |
| 1109 | } |
| 1110 | break; |
| 1111 | } |
| 1112 | |
| 1113 | case EVENT_ENABLE_VONR_DONE: { |
| 1114 | ar = (AsyncResult) msg.obj; |
| 1115 | request = (MainThreadRequest) ar.userObj; |
| 1116 | if (ar.exception == null) { |
| 1117 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1118 | } else { |
| 1119 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1120 | if (ar.exception instanceof CommandException) { |
| 1121 | CommandException.Error error = |
| 1122 | ((CommandException) (ar.exception)).getCommandError(); |
| 1123 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1124 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1125 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1126 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1127 | } else { |
| 1128 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1129 | } |
| 1130 | loge("setVoNrEnabled" + ": CommandException: " |
| 1131 | + ar.exception); |
| 1132 | } else { |
| 1133 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1134 | } |
| 1135 | } |
| 1136 | notifyRequester(request); |
| 1137 | break; |
| 1138 | } |
| 1139 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1143 | request); |
| 1144 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1145 | break; |
| 1146 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1147 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1148 | ar = (AsyncResult) msg.obj; |
| 1149 | request = (MainThreadRequest) ar.userObj; |
| 1150 | if (ar.exception == null && ar.result != null) { |
| 1151 | request.result = ar.result; // Integer |
| 1152 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1153 | // request.result must be set to something non-null |
| 1154 | // for the calling thread to unblock |
| 1155 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1157 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1159 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1160 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1161 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1162 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1165 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1166 | break; |
| 1167 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1168 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1169 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1170 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1171 | request); |
| 1172 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1173 | (Pair<Integer, Long>) request.argument; |
| 1174 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1175 | reasonWithNetworkTypes.first, |
| 1176 | reasonWithNetworkTypes.second, |
| 1177 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1178 | break; |
| 1179 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1180 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1181 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1182 | break; |
| 1183 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1184 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1187 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1188 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1189 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1193 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1194 | break; |
| 1195 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1196 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1197 | request = (MainThreadRequest) msg.obj; |
| 1198 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1199 | request); |
| 1200 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1201 | break; |
| 1202 | |
| 1203 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1204 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1205 | break; |
| 1206 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1207 | case CMD_PERFORM_NETWORK_SCAN: |
| 1208 | request = (MainThreadRequest) msg.obj; |
| 1209 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1210 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1211 | break; |
| 1212 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | request = (MainThreadRequest) msg.obj; |
| 1215 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1217 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1218 | request.argument; |
| 1219 | int callForwardingReason = args.first; |
| 1220 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | } |
| 1223 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | ar = (AsyncResult) msg.obj; |
| 1225 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1227 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1228 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1229 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1232 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1233 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1234 | // any service for voice call. |
| 1235 | if ((callForwardInfo.serviceClass |
| 1236 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1237 | callForwardingInfo = new CallForwardingInfo( |
| 1238 | callForwardInfo.status |
| 1239 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | callForwardInfo.reason, |
| 1241 | callForwardInfo.number, |
| 1242 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | break; |
| 1244 | } |
| 1245 | } |
| 1246 | // Didn't find a call forward info for voice call. |
| 1247 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1249 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | } else { |
| 1253 | if (ar.result == null) { |
| 1254 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1255 | } |
| 1256 | if (ar.exception != null) { |
| 1257 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1258 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1259 | int errorCode = TelephonyManager |
| 1260 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | if (ar.exception instanceof CommandException) { |
| 1262 | CommandException.Error error = |
| 1263 | ((CommandException) (ar.exception)).getCommandError(); |
| 1264 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1265 | errorCode = TelephonyManager |
| 1266 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1268 | errorCode = TelephonyManager |
| 1269 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | } |
| 1271 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | request = (MainThreadRequest) msg.obj; |
| 1279 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1283 | request.argument).first; |
| 1284 | request.phone.setCallForwardingOption( |
| 1285 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1286 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | callForwardingInfoToSet.getReason(), |
| 1289 | callForwardingInfoToSet.getNumber(), |
| 1290 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1291 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | ar = (AsyncResult) msg.obj; |
| 1296 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | Consumer<Integer> callback = |
| 1298 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1299 | request.argument).second; |
| 1300 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1302 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1303 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | if (ar.exception instanceof CommandException) { |
| 1305 | CommandException.Error error = |
| 1306 | ((CommandException) (ar.exception)).getCommandError(); |
| 1307 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1308 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1309 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1311 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1312 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | callback.accept(errorCode); |
| 1316 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1317 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | request = (MainThreadRequest) msg.obj; |
| 1324 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1325 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1326 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1327 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | ar = (AsyncResult) msg.obj; |
| 1331 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1333 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1335 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | // Service Class is a bit mask per 3gpp 27.007. |
| 1337 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1338 | if (callForwardResults.length > 1 |
| 1339 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1340 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1341 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1343 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1344 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1345 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | } |
| 1347 | } else { |
| 1348 | if (ar.result == null) { |
| 1349 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1350 | } |
| 1351 | if (ar.exception != null) { |
| 1352 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1353 | } |
| 1354 | if (ar.exception instanceof CommandException) { |
| 1355 | CommandException.Error error = |
| 1356 | ((CommandException) (ar.exception)).getCommandError(); |
| 1357 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1358 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1359 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1360 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1361 | callWaitingStatus = |
| 1362 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1363 | } |
| 1364 | } |
| 1365 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1366 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1367 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1368 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1371 | request = (MainThreadRequest) msg.obj; |
| 1372 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1374 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | ar = (AsyncResult) msg.obj; |
| 1380 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1382 | Consumer<Integer> callback = |
| 1383 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1384 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1385 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1386 | if (ar.exception instanceof CommandException) { |
| 1387 | CommandException.Error error = |
| 1388 | ((CommandException) (ar.exception)).getCommandError(); |
| 1389 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1390 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1391 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1392 | callback.accept( |
| 1393 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1394 | } else { |
| 1395 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1396 | } |
| 1397 | } else { |
| 1398 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1399 | } |
| 1400 | } else { |
| 1401 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1402 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1403 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1404 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1405 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1406 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1407 | ar = (AsyncResult) msg.obj; |
| 1408 | request = (MainThreadRequest) ar.userObj; |
| 1409 | CellNetworkScanResult cellScanResult; |
| 1410 | if (ar.exception == null && ar.result != null) { |
| 1411 | cellScanResult = new CellNetworkScanResult( |
| 1412 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1413 | (List<OperatorInfo>) ar.result); |
| 1414 | } else { |
| 1415 | if (ar.result == null) { |
| 1416 | loge("getCellNetworkScanResults: Empty response"); |
| 1417 | } |
| 1418 | if (ar.exception != null) { |
| 1419 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1420 | } |
| 1421 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1422 | if (ar.exception instanceof CommandException) { |
| 1423 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1424 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1425 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1426 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1427 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1428 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1429 | } |
| 1430 | } |
| 1431 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1432 | } |
| 1433 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1434 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1435 | break; |
| 1436 | |
| 1437 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1438 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1439 | ManualNetworkSelectionArgument selArg = |
| 1440 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1441 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1442 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1443 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1444 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
| 1450 | if (ar.exception == null) { |
| 1451 | request.result = true; |
| 1452 | } else { |
| 1453 | request.result = false; |
| 1454 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1455 | } |
| 1456 | notifyRequester(request); |
| 1457 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1458 | break; |
| 1459 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1460 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1461 | request = (MainThreadRequest) msg.obj; |
| 1462 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1463 | if (defaultPhone != null) { |
| 1464 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | } else { |
| 1466 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1467 | Bundle bundle = new Bundle(); |
| 1468 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1469 | new ModemActivityInfo(0, 0, 0, |
| 1470 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1471 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1472 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1475 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1476 | ar = (AsyncResult) msg.obj; |
| 1477 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1478 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1479 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1480 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1481 | if (mLastModemActivityInfo == null) { |
| 1482 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1483 | mLastModemActivitySpecificInfo[0] = |
| 1484 | new ActivityStatsTechSpecificInfo( |
| 1485 | 0, |
| 1486 | 0, |
| 1487 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1488 | 0); |
| 1489 | mLastModemActivityInfo = |
| 1490 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1491 | } |
| 1492 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1494 | // Update the last modem activity info and the result of the request. |
| 1495 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1496 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1497 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1498 | } else { |
| 1499 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1500 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1501 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1502 | // We don't want to return mLastModemActivityInfo which is updated |
| 1503 | // inside mergeModemActivityInfo() |
| 1504 | ret = new ModemActivityInfo( |
| 1505 | mLastModemActivityInfo.getTimestampMillis(), |
| 1506 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1507 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1508 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1509 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1510 | } else { |
| 1511 | if (ar.result == null) { |
| 1512 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1513 | error = TelephonyManager.ModemActivityInfoException |
| 1514 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1515 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1516 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1517 | error = TelephonyManager.ModemActivityInfoException |
| 1518 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1519 | } else { |
| 1520 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1521 | error = TelephonyManager.ModemActivityInfoException |
| 1522 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1523 | } |
| 1524 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1525 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1526 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1527 | bundle.putParcelable( |
| 1528 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1529 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1530 | } else { |
| 1531 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1532 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1533 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1534 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1535 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1536 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1537 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1538 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1539 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1540 | CarrierRestrictionRules argument = |
| 1541 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1542 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1543 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1544 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1545 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1546 | |
| 1547 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1548 | ar = (AsyncResult) msg.obj; |
| 1549 | request = (MainThreadRequest) ar.userObj; |
| 1550 | if (ar.exception == null && ar.result != null) { |
| 1551 | request.result = ar.result; |
| 1552 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1553 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1554 | if (ar.exception instanceof CommandException) { |
| 1555 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1556 | CommandException.Error error = |
| 1557 | ((CommandException) (ar.exception)).getCommandError(); |
| 1558 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1559 | request.result = |
| 1560 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1561 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1562 | } else { |
| 1563 | loge("setAllowedCarriers: Unknown exception"); |
| 1564 | } |
| 1565 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1566 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1567 | break; |
| 1568 | |
| 1569 | case CMD_GET_ALLOWED_CARRIERS: |
| 1570 | request = (MainThreadRequest) msg.obj; |
| 1571 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1572 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1576 | ar = (AsyncResult) msg.obj; |
| 1577 | request = (MainThreadRequest) ar.userObj; |
| 1578 | if (ar.exception == null && ar.result != null) { |
| 1579 | request.result = ar.result; |
| 1580 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1581 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1582 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1583 | if (ar.result == null) { |
| 1584 | loge("getAllowedCarriers: Empty response"); |
| 1585 | } else if (ar.exception instanceof CommandException) { |
| 1586 | loge("getAllowedCarriers: CommandException: " + |
| 1587 | ar.exception); |
| 1588 | } else { |
| 1589 | loge("getAllowedCarriers: Unknown exception"); |
| 1590 | } |
| 1591 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1592 | if (request.argument != null) { |
| 1593 | // This is for the implementation of carrierRestrictionStatus. |
| 1594 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1595 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1596 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1597 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1598 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1599 | CarrierRestrictionRules carrierRestrictionRules = |
| 1600 | (CarrierRestrictionRules) ar.result; |
| 1601 | int carrierId = -1; |
| 1602 | try { |
| 1603 | CarrierIdentifier carrierIdentifier = |
| 1604 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1605 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1606 | carrierIdentifier); |
| 1607 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1608 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1609 | } |
| 1610 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1611 | int restrictedStatus = |
| 1612 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1613 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1614 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1615 | lockStatus = TelephonyManager |
| 1616 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1617 | } |
| 1618 | } else { |
| 1619 | Rlog.e(LOG_TAG, |
| 1620 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1621 | } |
| 1622 | callback.accept(lockStatus); |
| 1623 | } else { |
| 1624 | // This is for the implementation of getAllowedCarriers. |
| 1625 | notifyRequester(request); |
| 1626 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1627 | break; |
| 1628 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1629 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1630 | ar = (AsyncResult) msg.obj; |
| 1631 | request = (MainThreadRequest) ar.userObj; |
| 1632 | if (ar.exception == null && ar.result != null) { |
| 1633 | request.result = ar.result; |
| 1634 | } else { |
| 1635 | request.result = new IllegalArgumentException( |
| 1636 | "Failed to retrieve Forbidden Plmns"); |
| 1637 | if (ar.result == null) { |
| 1638 | loge("getForbiddenPlmns: Empty response"); |
| 1639 | } else { |
| 1640 | loge("getForbiddenPlmns: Unknown exception"); |
| 1641 | } |
| 1642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1643 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1644 | break; |
| 1645 | |
| 1646 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1647 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1648 | uiccPort = getUiccPortFromRequest(request); |
| 1649 | if (uiccPort == null) { |
| 1650 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1651 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1652 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1654 | break; |
| 1655 | } |
| 1656 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1657 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1658 | if (uiccApp == null) { |
| 1659 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1660 | + appType); |
| 1661 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1662 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | } else { |
| 1665 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1666 | + " specified type -- " + appType); |
| 1667 | } |
| 1668 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1669 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1670 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1671 | break; |
| 1672 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1673 | case CMD_SWITCH_SLOTS: |
| 1674 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1675 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1676 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1677 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1678 | break; |
| 1679 | |
| 1680 | case EVENT_SWITCH_SLOTS_DONE: |
| 1681 | ar = (AsyncResult) msg.obj; |
| 1682 | request = (MainThreadRequest) ar.userObj; |
| 1683 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1684 | notifyRequester(request); |
| 1685 | break; |
| 1686 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1687 | request = (MainThreadRequest) msg.obj; |
| 1688 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1689 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1690 | break; |
| 1691 | |
| 1692 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1693 | ar = (AsyncResult) msg.obj; |
| 1694 | request = (MainThreadRequest) ar.userObj; |
| 1695 | if (ar.exception != null) { |
| 1696 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1697 | } else { |
| 1698 | int mode = ((int[]) ar.result)[0]; |
| 1699 | if (mode == 0) { |
| 1700 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1701 | } else { |
| 1702 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1703 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1705 | notifyRequester(request); |
| 1706 | break; |
| 1707 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1710 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1711 | break; |
| 1712 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1713 | ar = (AsyncResult) msg.obj; |
| 1714 | request = (MainThreadRequest) ar.userObj; |
| 1715 | if (ar.exception != null) { |
| 1716 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1717 | } else { |
| 1718 | request.result = ((int[]) ar.result)[0]; |
| 1719 | } |
| 1720 | notifyRequester(request); |
| 1721 | break; |
| 1722 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1723 | request = (MainThreadRequest) msg.obj; |
| 1724 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1725 | int mode = (int) request.argument; |
| 1726 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1727 | break; |
| 1728 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1729 | ar = (AsyncResult) msg.obj; |
| 1730 | request = (MainThreadRequest) ar.userObj; |
| 1731 | request.result = ar.exception == null; |
| 1732 | notifyRequester(request); |
| 1733 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1734 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1735 | request = (MainThreadRequest) msg.obj; |
| 1736 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1737 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1738 | break; |
| 1739 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1740 | ar = (AsyncResult) msg.obj; |
| 1741 | request = (MainThreadRequest) ar.userObj; |
| 1742 | if (ar.exception != null) { |
| 1743 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1744 | } else { |
| 1745 | request.result = ((int[]) ar.result)[0]; |
| 1746 | } |
| 1747 | notifyRequester(request); |
| 1748 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1749 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1750 | request = (MainThreadRequest) msg.obj; |
| 1751 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1752 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1753 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1754 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1755 | break; |
| 1756 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | request.result = ar.exception == null; |
| 1760 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1761 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1762 | case CMD_GET_ALL_CELL_INFO: |
| 1763 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1764 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1765 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1766 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1767 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1768 | ar = (AsyncResult) msg.obj; |
| 1769 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1770 | // If a timeout occurs, the response will be null |
| 1771 | request.result = (ar.exception == null && ar.result != null) |
| 1772 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1773 | synchronized (request) { |
| 1774 | request.notifyAll(); |
| 1775 | } |
| 1776 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1777 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1778 | request = (MainThreadRequest) msg.obj; |
| 1779 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1780 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1781 | break; |
| 1782 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1783 | ar = (AsyncResult) msg.obj; |
| 1784 | request = (MainThreadRequest) ar.userObj; |
| 1785 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1786 | try { |
| 1787 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1788 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1789 | cb.onError( |
| 1790 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1791 | ar.exception.getClass().getName(), |
| 1792 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1793 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1794 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1795 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1796 | } else { |
| 1797 | // use the result as returned |
| 1798 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1799 | } |
| 1800 | } catch (RemoteException re) { |
| 1801 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1802 | } |
| 1803 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1804 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1805 | request = (MainThreadRequest) msg.obj; |
| 1806 | WorkSource ws = (WorkSource) request.argument; |
| 1807 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1808 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1809 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1810 | } |
| 1811 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1812 | ar = (AsyncResult) msg.obj; |
| 1813 | request = (MainThreadRequest) ar.userObj; |
| 1814 | if (ar.exception == null) { |
| 1815 | request.result = ar.result; |
| 1816 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1817 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1818 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1819 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | synchronized (request) { |
| 1823 | request.notifyAll(); |
| 1824 | } |
| 1825 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1826 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1827 | case CMD_MODEM_REBOOT: |
| 1828 | request = (MainThreadRequest) msg.obj; |
| 1829 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1830 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1831 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1832 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1833 | handleNullReturnEvent(msg, "rebootModem"); |
| 1834 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1835 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1836 | request = (MainThreadRequest) msg.obj; |
| 1837 | boolean enable = (boolean) request.argument; |
| 1838 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1839 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1840 | PhoneConfigurationManager.getInstance() |
| 1841 | .enablePhone(request.phone, enable, onCompleted); |
| 1842 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1843 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1844 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1845 | ar = (AsyncResult) msg.obj; |
| 1846 | request = (MainThreadRequest) ar.userObj; |
| 1847 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1848 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1849 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1850 | if ((boolean) request.result) { |
| 1851 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1852 | updateModemStateMetrics(); |
| 1853 | } else { |
| 1854 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1855 | + ar.exception); |
| 1856 | } |
| 1857 | notifyRequester(request); |
| 1858 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1859 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1860 | case CMD_GET_MODEM_STATUS: |
| 1861 | request = (MainThreadRequest) msg.obj; |
| 1862 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1863 | PhoneConfigurationManager.getInstance() |
| 1864 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1865 | break; |
| 1866 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | int id = request.phone.getPhoneId(); |
| 1870 | if (ar.exception == null && ar.result != null) { |
| 1871 | request.result = ar.result; |
| 1872 | //update the cache as modem status has changed |
| 1873 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1874 | (boolean) request.result); |
| 1875 | } else { |
| 1876 | // Return true if modem status cannot be retrieved. For most cases, |
| 1877 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1878 | // and disable modem are not supported. Modem is always on. |
| 1879 | // TODO: this should be fixed in R to support a third |
| 1880 | // status UNKNOWN b/131631629 |
| 1881 | request.result = true; |
| 1882 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1883 | + ar.exception); |
| 1884 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1885 | notifyRequester(request); |
| 1886 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1887 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1888 | request = (MainThreadRequest) msg.obj; |
| 1889 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1890 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1891 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1892 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1893 | break; |
| 1894 | } |
| 1895 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1896 | ar = (AsyncResult) msg.obj; |
| 1897 | request = (MainThreadRequest) ar.userObj; |
| 1898 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1899 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1900 | args.second.accept(ar.exception == null); |
| 1901 | notifyRequester(request); |
| 1902 | break; |
| 1903 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1904 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1905 | request = (MainThreadRequest) msg.obj; |
| 1906 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1907 | Phone phone = getPhoneFromRequest(request); |
| 1908 | if (phone != null) { |
| 1909 | phone.getSystemSelectionChannels(onCompleted); |
| 1910 | } else { |
| 1911 | loge("getSystemSelectionChannels: No phone object"); |
| 1912 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1913 | notifyRequester(request); |
| 1914 | } |
| 1915 | break; |
| 1916 | } |
| 1917 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1918 | ar = (AsyncResult) msg.obj; |
| 1919 | request = (MainThreadRequest) ar.userObj; |
| 1920 | if (ar.exception == null && ar.result != null) { |
| 1921 | request.result = ar.result; |
| 1922 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1923 | request.result = new IllegalStateException( |
| 1924 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1925 | if (ar.result == null) { |
| 1926 | loge("getSystemSelectionChannels: Empty response"); |
| 1927 | } else { |
| 1928 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1929 | } |
| 1930 | } |
| 1931 | notifyRequester(request); |
| 1932 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1933 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1934 | ar = (AsyncResult) msg.obj; |
| 1935 | request = (MainThreadRequest) ar.userObj; |
| 1936 | if (ar.exception == null && ar.result != null) { |
| 1937 | request.result = ar.result; |
| 1938 | } else { |
| 1939 | request.result = -1; |
| 1940 | loge("Failed to set Forbidden Plmns"); |
| 1941 | if (ar.result == null) { |
| 1942 | loge("setForbidenPlmns: Empty response"); |
| 1943 | } else if (ar.exception != null) { |
| 1944 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1945 | request.result = -1; |
| 1946 | } else { |
| 1947 | loge("setForbiddenPlmns: Unknown exception"); |
| 1948 | } |
| 1949 | } |
| 1950 | notifyRequester(request); |
| 1951 | break; |
| 1952 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1953 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1954 | uiccPort = getUiccPortFromRequest(request); |
| 1955 | if (uiccPort == null) { |
| 1956 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1957 | request.result = -1; |
| 1958 | notifyRequester(request); |
| 1959 | break; |
| 1960 | } |
| 1961 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1962 | (Pair<Integer, List<String>>) request.argument; |
| 1963 | appType = setFplmnsArgs.first; |
| 1964 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1965 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1966 | if (uiccApp == null) { |
| 1967 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1968 | request.result = -1; |
| 1969 | loge("Failed to get UICC App"); |
| 1970 | notifyRequester(request); |
| 1971 | } else { |
| 1972 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1973 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1974 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1975 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1976 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1977 | case CMD_ERASE_MODEM_CONFIG: |
| 1978 | request = (MainThreadRequest) msg.obj; |
| 1979 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1980 | defaultPhone.eraseModemConfig(onCompleted); |
| 1981 | break; |
| 1982 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1983 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1984 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1985 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1986 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1987 | request = (MainThreadRequest) msg.obj; |
| 1988 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1989 | notifyRequester(request); |
| 1990 | break; |
| 1991 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1992 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1993 | request = (MainThreadRequest) msg.obj; |
| 1994 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1995 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1996 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1997 | changed.first, changed.second, onCompleted); |
| 1998 | break; |
| 1999 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2000 | ar = (AsyncResult) msg.obj; |
| 2001 | request = (MainThreadRequest) ar.userObj; |
| 2002 | if (ar.exception == null) { |
| 2003 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2004 | // If the operation is successful, update the PIN storage |
| 2005 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2006 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2007 | UiccController.getInstance().getPinStorage() |
| 2008 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2009 | } else { |
| 2010 | request.result = msg.arg1; |
| 2011 | } |
| 2012 | notifyRequester(request); |
| 2013 | break; |
| 2014 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2015 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2016 | request = (MainThreadRequest) msg.obj; |
| 2017 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2018 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2019 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2020 | enabled.first, enabled.second, onCompleted); |
| 2021 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2022 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2023 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2024 | ar = (AsyncResult) msg.obj; |
| 2025 | request = (MainThreadRequest) ar.userObj; |
| 2026 | if (ar.exception == null) { |
| 2027 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2028 | // If the operation is successful, update the PIN storage |
| 2029 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2030 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2031 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2032 | UiccController.getInstance().getPinStorage() |
| 2033 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2034 | } else { |
| 2035 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2036 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2037 | } else { |
| 2038 | request.result = msg.arg1; |
| 2039 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2040 | |
| 2041 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2042 | notifyRequester(request); |
| 2043 | break; |
| 2044 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2045 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2046 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2047 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2048 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2049 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2050 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2051 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2052 | |
| 2053 | case CMD_SET_DATA_THROTTLING: { |
| 2054 | request = (MainThreadRequest) msg.obj; |
| 2055 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2056 | DataThrottlingRequest dataThrottlingRequest = |
| 2057 | (DataThrottlingRequest) request.argument; |
| 2058 | Phone phone = getPhoneFromRequest(request); |
| 2059 | if (phone != null) { |
| 2060 | phone.setDataThrottling(onCompleted, |
| 2061 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2062 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2063 | } else { |
| 2064 | loge("setDataThrottling: No phone object"); |
| 2065 | request.result = |
| 2066 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2067 | notifyRequester(request); |
| 2068 | } |
| 2069 | |
| 2070 | break; |
| 2071 | } |
| 2072 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2073 | ar = (AsyncResult) msg.obj; |
| 2074 | request = (MainThreadRequest) ar.userObj; |
| 2075 | |
| 2076 | if (ar.exception == null) { |
| 2077 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2078 | } else if (ar.exception instanceof CommandException) { |
| 2079 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2080 | CommandException.Error error = |
| 2081 | ((CommandException) (ar.exception)).getCommandError(); |
| 2082 | |
| 2083 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2084 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2085 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2086 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2087 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2088 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2089 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2090 | } else { |
| 2091 | request.result = |
| 2092 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2093 | } |
| 2094 | } else { |
| 2095 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2096 | } |
| 2097 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2098 | notifyRequester(request); |
| 2099 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2100 | |
| 2101 | case CMD_SET_SIM_POWER: { |
| 2102 | request = (MainThreadRequest) msg.obj; |
| 2103 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2104 | request = (MainThreadRequest) msg.obj; |
| 2105 | int stateToSet = |
| 2106 | ((Pair<Integer, IIntegerConsumer>) |
| 2107 | request.argument).first; |
| 2108 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2109 | break; |
| 2110 | } |
| 2111 | case EVENT_SET_SIM_POWER_DONE: { |
| 2112 | ar = (AsyncResult) msg.obj; |
| 2113 | request = (MainThreadRequest) ar.userObj; |
| 2114 | IIntegerConsumer callback = |
| 2115 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2116 | if (ar.exception != null) { |
| 2117 | loge("setSimPower exception: " + ar.exception); |
| 2118 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2119 | .RESULT_ERROR_UNKNOWN; |
| 2120 | if (ar.exception instanceof CommandException) { |
| 2121 | CommandException.Error error = |
| 2122 | ((CommandException) (ar.exception)).getCommandError(); |
| 2123 | if (error == CommandException.Error.SIM_ERR) { |
| 2124 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2125 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2126 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2127 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2128 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2129 | } else { |
| 2130 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2131 | } |
| 2132 | } |
| 2133 | try { |
| 2134 | callback.accept(errorCode); |
| 2135 | } catch (RemoteException e) { |
| 2136 | // Ignore if the remote process is no longer available to call back. |
| 2137 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2138 | } |
| 2139 | } else { |
| 2140 | try { |
| 2141 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2142 | } catch (RemoteException e) { |
| 2143 | // Ignore if the remote process is no longer available to call back. |
| 2144 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2145 | } |
| 2146 | } |
| 2147 | break; |
| 2148 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2149 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2150 | request = (MainThreadRequest) msg.obj; |
| 2151 | |
| 2152 | final Phone phone = getPhoneFromRequest(request); |
| 2153 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2154 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2155 | notifyRequester(request); |
| 2156 | break; |
| 2157 | } |
| 2158 | |
| 2159 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2160 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2161 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2162 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2163 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2164 | request.subId, pair.first /*callingUid*/, |
| 2165 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2166 | break; |
| 2167 | } |
| 2168 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2169 | ar = (AsyncResult) msg.obj; |
| 2170 | request = (MainThreadRequest) ar.userObj; |
| 2171 | // request.result will be the exception of ar if present, true otherwise. |
| 2172 | // Be cautious not to leave result null which will wait() forever |
| 2173 | request.result = ar.exception != null ? ar.exception : true; |
| 2174 | notifyRequester(request); |
| 2175 | break; |
| 2176 | } |
| 2177 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2178 | request = (MainThreadRequest) msg.obj; |
| 2179 | |
| 2180 | Phone phone = getPhoneFromRequest(request); |
| 2181 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2182 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2183 | notifyRequester(request); |
| 2184 | break; |
| 2185 | } |
| 2186 | |
| 2187 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2188 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2189 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2190 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2191 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2192 | request.subId, pair.first /*callingUid*/, |
| 2193 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2197 | ar = (AsyncResult) msg.obj; |
| 2198 | request = (MainThreadRequest) ar.userObj; |
| 2199 | request.result = ar.exception != null ? ar.exception : true; |
| 2200 | notifyRequester(request); |
| 2201 | break; |
| 2202 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2203 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2204 | case CMD_GET_SLICING_CONFIG: { |
| 2205 | request = (MainThreadRequest) msg.obj; |
| 2206 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2207 | request.phone.getSlicingConfig(onCompleted); |
| 2208 | break; |
| 2209 | } |
| 2210 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2211 | ar = (AsyncResult) msg.obj; |
| 2212 | request = (MainThreadRequest) ar.userObj; |
| 2213 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2214 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2215 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2216 | Bundle bundle = new Bundle(); |
| 2217 | int resultCode = 0; |
| 2218 | if (ar.exception != null) { |
| 2219 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2220 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2221 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2222 | } else if (ar.result == null) { |
| 2223 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2224 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2225 | } else { |
| 2226 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2227 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2228 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2232 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2233 | } |
| 2234 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2235 | result.send(resultCode, bundle); |
| 2236 | notifyRequester(request); |
| 2237 | break; |
| 2238 | } |
| 2239 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | request = (MainThreadRequest) msg.obj; |
| 2242 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2243 | PurchasePremiumCapabilityArgument arg = |
| 2244 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2245 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2246 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2247 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2248 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2249 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2251 | ar = (AsyncResult) msg.obj; |
| 2252 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2253 | PurchasePremiumCapabilityArgument arg = |
| 2254 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2255 | try { |
| 2256 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2257 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2258 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2259 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2260 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2262 | } catch (RemoteException e) { |
| 2263 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2264 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2265 | + " failed: " + e; |
| 2266 | if (DBG) log(logStr); |
| 2267 | AnomalyReporter.reportAnomaly( |
| 2268 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2269 | } |
| 2270 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2271 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2272 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2273 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2274 | request = (MainThreadRequest) msg.obj; |
| 2275 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2276 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2277 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2278 | notifyRequester(request); |
| 2279 | break; |
| 2280 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | default: |
| 2282 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2283 | break; |
| 2284 | } |
| 2285 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2286 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2287 | private void notifyRequester(MainThreadRequest request) { |
| 2288 | synchronized (request) { |
| 2289 | request.notifyAll(); |
| 2290 | } |
| 2291 | } |
| 2292 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2293 | private void handleNullReturnEvent(Message msg, String command) { |
| 2294 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2295 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2296 | if (ar.exception == null) { |
| 2297 | request.result = true; |
| 2298 | } else { |
| 2299 | request.result = false; |
| 2300 | if (ar.exception instanceof CommandException) { |
| 2301 | loge(command + ": CommandException: " + ar.exception); |
| 2302 | } else { |
| 2303 | loge(command + ": Unknown exception"); |
| 2304 | } |
| 2305 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2306 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2307 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * Posts the specified command to be executed on the main thread, |
| 2312 | * waits for the request to complete, and returns the result. |
| 2313 | * @see #sendRequestAsync |
| 2314 | */ |
| 2315 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2316 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2317 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Posts the specified command to be executed on the main thread, |
| 2322 | * waits for the request to complete, and returns the result. |
| 2323 | * @see #sendRequestAsync |
| 2324 | */ |
| 2325 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2326 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2327 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Posts the specified command to be executed on the main thread, |
| 2332 | * waits for the request to complete, and returns the result. |
| 2333 | * @see #sendRequestAsync |
| 2334 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2335 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2336 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2337 | } |
| 2338 | |
| 2339 | /** |
| 2340 | * Posts the specified command to be executed on the main thread, |
| 2341 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2342 | * if not timeout or null otherwise. |
| 2343 | * @see #sendRequestAsync |
| 2344 | */ |
| 2345 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2346 | long timeoutInMs) { |
| 2347 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
| 2351 | * Posts the specified command to be executed on the main thread, |
| 2352 | * waits for the request to complete, and returns the result. |
| 2353 | * @see #sendRequestAsync |
| 2354 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2355 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * Posts the specified command to be executed on the main thread, |
| 2361 | * waits for the request to complete, and returns the result. |
| 2362 | * @see #sendRequestAsync |
| 2363 | */ |
| 2364 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2365 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2366 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2370 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2371 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2372 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2373 | * @see #sendRequestAsync |
| 2374 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2375 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2376 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2378 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2379 | } |
| 2380 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2381 | MainThreadRequest request = null; |
| 2382 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2383 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2384 | } else if (phone != null) { |
| 2385 | request = new MainThreadRequest(argument, phone, workSource); |
| 2386 | } else { |
| 2387 | request = new MainThreadRequest(argument, subId, workSource); |
| 2388 | } |
| 2389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2391 | msg.sendToTarget(); |
| 2392 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2395 | if (timeoutInMs >= 0) { |
| 2396 | // Wait for at least timeoutInMs before returning null request result |
| 2397 | long now = SystemClock.elapsedRealtime(); |
| 2398 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2399 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2400 | try { |
| 2401 | request.wait(deadline - now); |
| 2402 | } catch (InterruptedException e) { |
| 2403 | // Do nothing, go back and check if request is completed or timeout |
| 2404 | } finally { |
| 2405 | now = SystemClock.elapsedRealtime(); |
| 2406 | } |
| 2407 | } |
| 2408 | } else { |
| 2409 | // Wait for the request to complete |
| 2410 | while (request.result == null) { |
| 2411 | try { |
| 2412 | request.wait(); |
| 2413 | } catch (InterruptedException e) { |
| 2414 | // Do nothing, go back and wait until the request is complete |
| 2415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2419 | if (request.result == null) { |
| 2420 | Log.wtf(LOG_TAG, |
| 2421 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2422 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | return request.result; |
| 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2428 | * Posts the specified command to be executed on the main thread, and |
| 2429 | * returns immediately. |
| 2430 | * @see #sendRequest |
| 2431 | */ |
| 2432 | private void sendRequestAsync(int command) { |
| 2433 | mMainThreadHandler.sendEmptyMessage(command); |
| 2434 | } |
| 2435 | |
| 2436 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2437 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2438 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2439 | */ |
| 2440 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2441 | sendRequestAsync(command, argument, null, null); |
| 2442 | } |
| 2443 | |
| 2444 | /** |
| 2445 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2446 | * @see {@link #sendRequest(int,Object)} |
| 2447 | */ |
| 2448 | private void sendRequestAsync( |
| 2449 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2450 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2451 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2452 | msg.sendToTarget(); |
| 2453 | } |
| 2454 | |
| 2455 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2457 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2458 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2459 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | synchronized (PhoneInterfaceManager.class) { |
| 2461 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2462 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } else { |
| 2464 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2465 | } |
| 2466 | return sInstance; |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2471 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2473 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2474 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2476 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2477 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2478 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2480 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2481 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2482 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2483 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2484 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2485 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2486 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2487 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2488 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2489 | mVendorApiLevel = SystemProperties.getInt( |
| 2490 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2491 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2492 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2494 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2495 | |
| 2496 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2497 | // entitlementStatus for satellite service. |
| 2498 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2501 | @VisibleForTesting |
| 2502 | public SharedPreferences getSharedPreferences() { |
| 2503 | return mTelephonySharedPreferences; |
| 2504 | } |
| 2505 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2506 | /** |
| 2507 | * Get the default phone for this device. |
| 2508 | */ |
| 2509 | @VisibleForTesting |
| 2510 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2511 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2512 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2513 | } |
| 2514 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2515 | private void publish() { |
| 2516 | if (DBG) log("publish: " + this); |
| 2517 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2518 | TelephonyFrameworkInitializer |
| 2519 | .getTelephonyServiceManager() |
| 2520 | .getTelephonyServiceRegisterer() |
| 2521 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2524 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2525 | if (request.phone != null) { |
| 2526 | return request.phone; |
| 2527 | } else { |
| 2528 | return getPhoneFromSubId(request.subId); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | private Phone getPhoneFromSubId(int subId) { |
| 2533 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2534 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2537 | /** |
| 2538 | * Get phone object associated with a subscription. |
| 2539 | * Return default phone if phone object associated with subscription is null |
| 2540 | * @param subId - subscriptionId |
| 2541 | * @return phone object associated with a subscription or default phone if null. |
| 2542 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2543 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2544 | Phone phone = getPhoneFromSubId(subId); |
| 2545 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2546 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2547 | phone = getDefaultPhone(); |
| 2548 | } |
| 2549 | return phone; |
| 2550 | } |
| 2551 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2552 | @Nullable |
| 2553 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2554 | Phone phone = getPhoneFromRequest(request); |
| 2555 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2556 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2559 | /** |
| 2560 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2561 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2562 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2563 | * @return The Phone associated the sub Id |
| 2564 | */ |
| 2565 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2566 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2569 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2570 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2571 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2572 | } |
| 2573 | |
| 2574 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2575 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2576 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2579 | private boolean isImsAvailableOnDevice() { |
| 2580 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2581 | if (pm == null) { |
| 2582 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2583 | // so do not throw error and allow. |
| 2584 | return true; |
| 2585 | } |
| 2586 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2587 | } |
| 2588 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2590 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2591 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2592 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2593 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2596 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | if (DBG) log("dial: " + number); |
| 2598 | // No permission check needed here: This is just a wrapper around the |
| 2599 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2600 | // the UI before it does anything. |
| 2601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | String url = createTelUrl(number); |
| 2605 | if (url == null) { |
| 2606 | return; |
| 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2610 | PhoneConstants.State state = mCM.getState(subId); |
| 2611 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2612 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2613 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2614 | mApp.startActivity(intent); |
| 2615 | } |
| 2616 | } finally { |
| 2617 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2622 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2625 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | if (DBG) log("call: " + number); |
| 2627 | |
| 2628 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2629 | // need to do a permission check since we're calling startActivity() |
| 2630 | // from the context of the phone app. |
| 2631 | enforceCallPermission(); |
| 2632 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2633 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | != AppOpsManager.MODE_ALLOWED) { |
| 2635 | return; |
| 2636 | } |
| 2637 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2638 | enforceTelephonyFeatureWithException(callingPackage, |
| 2639 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | String url = createTelUrl(number); |
| 2644 | if (url == null) { |
| 2645 | return; |
| 2646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | boolean isValid = false; |
| 2649 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2650 | if (slist != null) { |
| 2651 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2652 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2653 | isValid = true; |
| 2654 | break; |
| 2655 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2656 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | if (!isValid) { |
| 2659 | return; |
| 2660 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2661 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2663 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2664 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2665 | mApp.startActivity(intent); |
| 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
| 2668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2671 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2672 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2673 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2674 | } |
| 2675 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2676 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2677 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2678 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2679 | } |
| 2680 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2681 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2684 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2685 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2686 | "supplyPinReportResultForSubscriber"); |
| 2687 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2690 | Phone phone = getPhone(subId); |
| 2691 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | checkSimPin.start(); |
| 2693 | return checkSimPin.unlockSim(null, pin); |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(identity); |
| 2696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2699 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2702 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2703 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2707 | Phone phone = getPhone(subId); |
| 2708 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | checkSimPuk.start(); |
| 2710 | return checkSimPuk.unlockSim(puk, pin); |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
| 2713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2717 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | * a synchronous one. |
| 2719 | */ |
| 2720 | private static class UnlockSim extends Thread { |
| 2721 | |
| 2722 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2723 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | |
| 2725 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2726 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2727 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2728 | |
| 2729 | // For replies from SimCard interface |
| 2730 | private Handler mHandler; |
| 2731 | |
| 2732 | // For async handler to identify request type |
| 2733 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2734 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2735 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2736 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2737 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2739 | UnlockSim(int phoneId, IccCard simCard) { |
| 2740 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | mSimCard = simCard; |
| 2742 | } |
| 2743 | |
| 2744 | @Override |
| 2745 | public void run() { |
| 2746 | Looper.prepare(); |
| 2747 | synchronized (UnlockSim.this) { |
| 2748 | mHandler = new Handler() { |
| 2749 | @Override |
| 2750 | public void handleMessage(Message msg) { |
| 2751 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2752 | switch (msg.what) { |
| 2753 | case SUPPLY_PIN_COMPLETE: |
| 2754 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2755 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2756 | mRetryCount = msg.arg1; |
| 2757 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2758 | CommandException.Error error = null; |
| 2759 | if (ar.exception instanceof CommandException) { |
| 2760 | error = ((CommandException) (ar.exception)) |
| 2761 | .getCommandError(); |
| 2762 | } |
| 2763 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2764 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2765 | } else if (error == CommandException.Error.ABORTED) { |
| 2766 | /* When UiccCardApp dispose, handle message and return |
| 2767 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2768 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2769 | } else { |
| 2770 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2771 | } |
| 2772 | } else { |
| 2773 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2774 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2776 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | UnlockSim.this.notifyAll(); |
| 2778 | } |
| 2779 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2780 | case SUPPLY_PIN_DELAYED: |
| 2781 | if(!mDone) { |
| 2782 | String logStr = "Delay in receiving SIM PIN response "; |
| 2783 | if (DBG) log(logStr); |
| 2784 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2785 | } |
| 2786 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
| 2788 | } |
| 2789 | }; |
| 2790 | UnlockSim.this.notifyAll(); |
| 2791 | } |
| 2792 | Looper.loop(); |
| 2793 | } |
| 2794 | |
| 2795 | /* |
| 2796 | * Use PIN or PUK to unlock SIM card |
| 2797 | * |
| 2798 | * If PUK is null, unlock SIM card with PIN |
| 2799 | * |
| 2800 | * 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] | 2801 | * |
| 2802 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2803 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2804 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2805 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2806 | |
| 2807 | while (mHandler == null) { |
| 2808 | try { |
| 2809 | wait(); |
| 2810 | } catch (InterruptedException e) { |
| 2811 | Thread.currentThread().interrupt(); |
| 2812 | } |
| 2813 | } |
| 2814 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2815 | |
| 2816 | if (puk == null) { |
| 2817 | mSimCard.supplyPin(pin, callback); |
| 2818 | } else { |
| 2819 | mSimCard.supplyPuk(puk, pin, callback); |
| 2820 | } |
| 2821 | |
| 2822 | while (!mDone) { |
| 2823 | try { |
| 2824 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2825 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2826 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | wait(); |
| 2828 | } catch (InterruptedException e) { |
| 2829 | // Restore the interrupted status |
| 2830 | Thread.currentThread().interrupt(); |
| 2831 | } |
| 2832 | } |
| 2833 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2834 | int[] resultArray = new int[2]; |
| 2835 | resultArray[0] = mResult; |
| 2836 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2837 | |
| 2838 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2839 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2840 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2841 | // This instance is no longer reused, so quit its thread's looper. |
| 2842 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2843 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2844 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2848 | /** |
| 2849 | * This method has been removed due to privacy and stability concerns. |
| 2850 | */ |
| 2851 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2852 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2853 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2854 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2857 | @Override |
| 2858 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2859 | mApp.getSystemService(AppOpsManager.class) |
| 2860 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2861 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2862 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2863 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2864 | // Callers targeting S have no business invoking this method. |
| 2865 | return; |
| 2866 | } |
| 2867 | |
| 2868 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2869 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2870 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2871 | .setCallingPackage(callingPackage) |
| 2872 | .setCallingFeatureId(null) |
| 2873 | .setCallingPid(Binder.getCallingPid()) |
| 2874 | .setCallingUid(Binder.getCallingUid()) |
| 2875 | .setMethod("updateServiceLocation") |
| 2876 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2877 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2878 | .build()); |
| 2879 | // Apps that lack location permission have no business calling this method; |
| 2880 | // however, because no permission was declared in the public API, denials must |
| 2881 | // all be "soft". |
| 2882 | switch (locationResult) { |
| 2883 | case DENIED_HARD: /* fall through */ |
| 2884 | case DENIED_SOFT: |
| 2885 | return; |
| 2886 | } |
| 2887 | |
| 2888 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2891 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | } finally { |
| 2893 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2894 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2897 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2898 | @Override |
| 2899 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2900 | return isRadioOnWithFeature(callingPackage, null); |
| 2901 | } |
| 2902 | |
| 2903 | |
| 2904 | @Override |
| 2905 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2906 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2907 | callingFeatureId); |
| 2908 | } |
| 2909 | |
| 2910 | @Deprecated |
| 2911 | @Override |
| 2912 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2913 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2916 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2917 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2918 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2919 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2920 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2921 | return false; |
| 2922 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2923 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2924 | enforceTelephonyFeatureWithException(callingPackage, |
| 2925 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2926 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2927 | final long identity = Binder.clearCallingIdentity(); |
| 2928 | try { |
| 2929 | return isRadioOnForSubscriber(subId); |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
| 2932 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | final Phone phone = getPhone(subId); |
| 2939 | if (phone != null) { |
| 2940 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2941 | } else { |
| 2942 | return false; |
| 2943 | } |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2946 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2950 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2951 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2952 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2953 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2954 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2955 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2956 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2957 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | final Phone phone = getPhone(subId); |
| 2962 | if (phone != null) { |
| 2963 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2964 | } |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2967 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2971 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2974 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2975 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
| 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | final Phone phone = getPhone(subId); |
| 2980 | if (phone == null) { |
| 2981 | return false; |
| 2982 | } |
| 2983 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2984 | toggleRadioOnOffForSubscriber(subId); |
| 2985 | } |
| 2986 | return true; |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2991 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2992 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2993 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2994 | |
| 2995 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2996 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2997 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2998 | /* |
| 2999 | * If any of the Radios are available, it will need to be |
| 3000 | * shutdown. So return true if any Radio is available. |
| 3001 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3005 | Phone phone = PhoneFactory.getPhone(i); |
| 3006 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3007 | } |
| 3008 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3009 | return false; |
| 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3012 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3016 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | enforceModifyPermission(); |
| 3018 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3019 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3020 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3021 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | final long identity = Binder.clearCallingIdentity(); |
| 3023 | try { |
| 3024 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3025 | logv("Shutting down Phone " + i); |
| 3026 | shutdownRadioUsingPhoneId(i); |
| 3027 | } |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3034 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3035 | if (phone != null && phone.isRadioAvailable()) { |
| 3036 | phone.shutdownRadio(); |
| 3037 | } |
| 3038 | } |
| 3039 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3040 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3041 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3042 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3043 | if (!turnOn) { |
| 3044 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3045 | } |
| 3046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
| 3049 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3050 | if (defaultPhone != null) { |
| 3051 | defaultPhone.setRadioPower(turnOn); |
| 3052 | return true; |
| 3053 | } else { |
| 3054 | loge("There's no default phone."); |
| 3055 | return false; |
| 3056 | } |
| 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3059 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3062 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3064 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3065 | if (!turnOn) { |
| 3066 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3067 | + ",callingPackage=" + getCurrentPackageName()); |
| 3068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | final Phone phone = getPhone(subId); |
| 3072 | if (phone != null) { |
| 3073 | phone.setRadioPower(turnOn); |
| 3074 | return true; |
| 3075 | } else { |
| 3076 | return false; |
| 3077 | } |
| 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3080 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3083 | /** |
| 3084 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3085 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3086 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3087 | * powering it off, and these radio off votes will be cleared. |
| 3088 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3089 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3090 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3091 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3092 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3093 | * check its vote. |
| 3094 | * |
| 3095 | * @param subId The subscription ID. |
| 3096 | * @param reason The reason for powering off radio. |
| 3097 | * @return true on success and false on failure. |
| 3098 | */ |
| 3099 | public boolean requestRadioPowerOffForReason(int subId, |
| 3100 | @TelephonyManager.RadioPowerReason int reason) { |
| 3101 | enforceModifyPermission(); |
| 3102 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3103 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3104 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3105 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3106 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3107 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3108 | final long identity = Binder.clearCallingIdentity(); |
| 3109 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3110 | boolean result = false; |
| 3111 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3112 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3113 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3114 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3115 | if (!result) { |
| 3116 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3117 | } |
| 3118 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(identity); |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3126 | * {@link requestRadioPowerOffForReason}. |
| 3127 | * |
| 3128 | * @param subId The subscription ID. |
| 3129 | * @param reason The reason for powering off radio. |
| 3130 | * @return true on success and false on failure. |
| 3131 | */ |
| 3132 | public boolean clearRadioPowerOffForReason(int subId, |
| 3133 | @TelephonyManager.RadioPowerReason int reason) { |
| 3134 | enforceModifyPermission(); |
| 3135 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3136 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3137 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3138 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3141 | boolean result = false; |
| 3142 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3143 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3144 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3145 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3146 | if (!result) { |
| 3147 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3148 | } |
| 3149 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
| 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | /** |
| 3156 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3157 | * |
| 3158 | * @param subId The subscription ID. |
| 3159 | * @param callingPackage The package making the call. |
| 3160 | * @param callingFeatureId The feature in the package. |
| 3161 | * @return List of reasons for powering off radio. |
| 3162 | */ |
| 3163 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3164 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3165 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3166 | enforceTelephonyFeatureWithException(callingPackage, |
| 3167 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3168 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | List result = new ArrayList(); |
| 3171 | try { |
| 3172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3173 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3174 | return result; |
| 3175 | } |
| 3176 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3177 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3178 | if (phone != null) { |
| 3179 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3180 | } else { |
| 3181 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3182 | } |
| 3183 | } finally { |
| 3184 | Binder.restoreCallingIdentity(identity); |
| 3185 | } |
| 3186 | return result; |
| 3187 | } |
| 3188 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3189 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3190 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3191 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3193 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3194 | enforceTelephonyFeatureWithException(callingPackage, |
| 3195 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3196 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | final long identity = Binder.clearCallingIdentity(); |
| 3198 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3199 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3201 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3202 | phone.getDataSettingsManager().setDataEnabled( |
| 3203 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3204 | return true; |
| 3205 | } else { |
| 3206 | return false; |
| 3207 | } |
| 3208 | } finally { |
| 3209 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3213 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3214 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3215 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3217 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3218 | enforceTelephonyFeatureWithException(callingPackage, |
| 3219 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3223 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3225 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3226 | phone.getDataSettingsManager().setDataEnabled( |
| 3227 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3228 | return true; |
| 3229 | } else { |
| 3230 | return false; |
| 3231 | } |
| 3232 | } finally { |
| 3233 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3234 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3238 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3239 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3240 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
| 3244 | final Phone phone = getPhone(subId); |
| 3245 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3246 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | } else { |
| 3248 | return false; |
| 3249 | } |
| 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3256 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3259 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3260 | enforceCallPermission(); |
| 3261 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3262 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3263 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3265 | final long identity = Binder.clearCallingIdentity(); |
| 3266 | try { |
| 3267 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3268 | return; |
| 3269 | } |
| 3270 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3271 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3272 | } finally { |
| 3273 | Binder.restoreCallingIdentity(identity); |
| 3274 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3275 | }; |
| 3276 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3277 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3279 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3280 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3281 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3282 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
| 3285 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3286 | return false; |
| 3287 | } |
| 3288 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3289 | } finally { |
| 3290 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3294 | /** |
| 3295 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3296 | * tag on getCallState Binder call. |
| 3297 | */ |
| 3298 | @Deprecated |
| 3299 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3300 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3301 | if (CompatChanges.isChangeEnabled( |
| 3302 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3303 | Binder.getCallingUid())) { |
| 3304 | // Do not allow this API to be called on API version 31+, it should only be |
| 3305 | // called on old apps using this Binder call directly. |
| 3306 | throw new SecurityException("This method can only be used for applications " |
| 3307 | + "targeting API version 30 or less."); |
| 3308 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | final long identity = Binder.clearCallingIdentity(); |
| 3310 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3311 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3312 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | @Override |
| 3319 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3320 | if (CompatChanges.isChangeEnabled( |
| 3321 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3322 | Binder.getCallingUid())) { |
| 3323 | // Check READ_PHONE_STATE for API version 31+ |
| 3324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3325 | featureId, "getCallStateForSubscription")) { |
| 3326 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3327 | + "targeting API level 31+."); |
| 3328 | } |
| 3329 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3330 | |
| 3331 | enforceTelephonyFeatureWithException(callingPackage, |
| 3332 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3333 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3337 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3338 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(identity); |
| 3341 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3344 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3345 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3346 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | @Override |
| 3350 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3351 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3352 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3356 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3358 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3359 | } else { |
| 3360 | return PhoneConstantConversions.convertDataState( |
| 3361 | PhoneConstants.DataState.DISCONNECTED); |
| 3362 | } |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3368 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3369 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3370 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3374 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3375 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3376 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 | final long identity = Binder.clearCallingIdentity(); |
| 3379 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3382 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | } else { |
| 3384 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3385 | } |
| 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3392 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3393 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3394 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3395 | |
| 3396 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3397 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3398 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3399 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3400 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3401 | .setCallingPid(Binder.getCallingPid()) |
| 3402 | .setCallingUid(Binder.getCallingUid()) |
| 3403 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3404 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3405 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3406 | .build()); |
| 3407 | switch (locationResult) { |
| 3408 | case DENIED_HARD: |
| 3409 | throw new SecurityException("Not allowed to access cell location"); |
| 3410 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3411 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3412 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3415 | enforceTelephonyFeatureWithException(callingPackage, |
| 3416 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3417 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3418 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3422 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3423 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3429 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3430 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3431 | if (!mApp.getResources().getBoolean( |
| 3432 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3433 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3434 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3435 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3436 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3437 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3438 | // registered cell info, so return a NULL country instead. |
| 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3441 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3442 | // Get default phone in this case. |
| 3443 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3444 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3445 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3447 | if (phone == null) return ""; |
| 3448 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3449 | if (sst == null) return ""; |
| 3450 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3451 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3452 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3458 | /** |
| 3459 | * This method was removed due to potential issues caused by performing partial |
| 3460 | * updates of service state, and lack of a credible use case. |
| 3461 | * |
| 3462 | * This has the ability to break the telephony implementation by disabling notification of |
| 3463 | * changes in device connectivity. DO NOT USE THIS! |
| 3464 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3465 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3466 | public void enableLocationUpdates() { |
| 3467 | mApp.enforceCallingOrSelfPermission( |
| 3468 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3471 | /** |
| 3472 | * This method was removed due to potential issues caused by performing partial |
| 3473 | * updates of service state, and lack of a credible use case. |
| 3474 | * |
| 3475 | * This has the ability to break the telephony implementation by disabling notification of |
| 3476 | * changes in device connectivity. DO NOT USE THIS! |
| 3477 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | @Override |
| 3479 | public void disableLocationUpdates() { |
| 3480 | mApp.enforceCallingOrSelfPermission( |
| 3481 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | @Override |
| 3485 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3486 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3487 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3488 | try { |
| 3489 | mApp.getSystemService(AppOpsManager.class) |
| 3490 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3491 | } catch (SecurityException e) { |
| 3492 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3493 | throw e; |
| 3494 | } |
| 3495 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3496 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3497 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3498 | throw new SecurityException( |
| 3499 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3500 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3501 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3502 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3503 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3504 | return null; |
| 3505 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3506 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3507 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3508 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3509 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3510 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3511 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3512 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3513 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3515 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3516 | for (CellInfo ci : info) { |
| 3517 | if (ci instanceof CellInfoGsm) { |
| 3518 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3519 | } else if (ci instanceof CellInfoWcdma) { |
| 3520 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3523 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3526 | private List<CellInfo> getCachedCellInfo() { |
| 3527 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3528 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3529 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3530 | if (info != null) cellInfos.addAll(info); |
| 3531 | } |
| 3532 | return cellInfos; |
| 3533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3534 | |
| 3535 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3536 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3537 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3538 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3539 | |
| 3540 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3541 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3542 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3543 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3544 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3545 | .setCallingPid(Binder.getCallingPid()) |
| 3546 | .setCallingUid(Binder.getCallingUid()) |
| 3547 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3548 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3549 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3550 | .build()); |
| 3551 | switch (locationResult) { |
| 3552 | case DENIED_HARD: |
| 3553 | throw new SecurityException("Not allowed to access cell info"); |
| 3554 | case DENIED_SOFT: |
| 3555 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3558 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3559 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3560 | return getCachedCellInfo(); |
| 3561 | } |
| 3562 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3563 | enforceTelephonyFeatureWithException(callingPackage, |
| 3564 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3565 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3566 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3567 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3571 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3572 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3573 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3574 | if (info != null) cellInfos.addAll(info); |
| 3575 | } |
| 3576 | return cellInfos; |
| 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3582 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3583 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3584 | String callingFeatureId) { |
| 3585 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3586 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3590 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3591 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3592 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3593 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3596 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3597 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3598 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3599 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3600 | |
| 3601 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3602 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3603 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3604 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3605 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3606 | .setCallingPid(Binder.getCallingPid()) |
| 3607 | .setCallingUid(Binder.getCallingUid()) |
| 3608 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3609 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3610 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3611 | .build()); |
| 3612 | switch (locationResult) { |
| 3613 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3614 | if (TelephonyPermissions |
| 3615 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3616 | // Safetynet logging for b/154934934 |
| 3617 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3618 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3619 | throw new SecurityException("Not allowed to access cell info"); |
| 3620 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3621 | if (TelephonyPermissions |
| 3622 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3623 | // Safetynet logging for b/154934934 |
| 3624 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3625 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3626 | try { |
| 3627 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3628 | } catch (RemoteException re) { |
| 3629 | // Drop without consequences |
| 3630 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3631 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3634 | enforceTelephonyFeatureWithException(callingPackage, |
| 3635 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3636 | |
| 3637 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3638 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3639 | |
| 3640 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3641 | } |
| 3642 | |
| 3643 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3644 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3645 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3646 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | |
| 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3650 | Phone phone = getPhone(subId); |
| 3651 | if (phone == null) { |
| 3652 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3653 | } else { |
| 3654 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | } finally { |
| 3657 | Binder.restoreCallingIdentity(identity); |
| 3658 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3661 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3662 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3663 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3664 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3665 | return null; |
| 3666 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3667 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3668 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3669 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3670 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3671 | return null; |
| 3672 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3674 | enforceTelephonyFeatureWithException(callingPackage, |
| 3675 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | return phone.getImei(); |
| 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
| 3682 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3686 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3687 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3688 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3689 | callingFeatureId, "getPrimaryImei")) { |
| 3690 | throw new SecurityException("Caller does not have permission"); |
| 3691 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3692 | |
| 3693 | enforceTelephonyFeatureWithException(callingPackage, |
| 3694 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3695 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3699 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3700 | return phone.getImei(); |
| 3701 | } |
| 3702 | } |
| 3703 | throw new UnsupportedOperationException("Operation not supported"); |
| 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3710 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3711 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3712 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3713 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3714 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3715 | String tac = null; |
| 3716 | if (phone != null) { |
| 3717 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3718 | try { |
| 3719 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3720 | } catch (IndexOutOfBoundsException e) { |
| 3721 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3722 | return null; |
| 3723 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3724 | } |
| 3725 | return tac; |
| 3726 | } |
| 3727 | |
| 3728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3729 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3730 | try { |
| 3731 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3732 | } catch (SecurityException se) { |
| 3733 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3734 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3735 | + Binder.getCallingUid()); |
| 3736 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3737 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3738 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3739 | return null; |
| 3740 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3742 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3743 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3744 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3745 | return null; |
| 3746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3748 | enforceTelephonyFeatureWithException(callingPackage, |
| 3749 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | return phone.getMeid(); |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(identity); |
| 3756 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3760 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3761 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3762 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3763 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3764 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3765 | String manufacturerCode = null; |
| 3766 | if (phone != null) { |
| 3767 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3768 | try { |
| 3769 | manufacturerCode = |
| 3770 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3771 | } catch (IndexOutOfBoundsException e) { |
| 3772 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3773 | return null; |
| 3774 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3775 | } |
| 3776 | return manufacturerCode; |
| 3777 | } |
| 3778 | |
| 3779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3780 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3781 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3783 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3784 | return null; |
| 3785 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3786 | int subId = phone.getSubId(); |
| 3787 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3788 | mApp, subId, callingPackage, callingFeatureId, |
| 3789 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3790 | return null; |
| 3791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3793 | enforceTelephonyFeatureWithException(callingPackage, |
| 3794 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | return phone.getDeviceSvn(); |
| 3799 | } finally { |
| 3800 | Binder.restoreCallingIdentity(identity); |
| 3801 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3804 | @Override |
| 3805 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3806 | if (!mApp.getResources().getBoolean( |
| 3807 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3808 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3809 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3810 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | final Phone phone = getPhone(subId); |
| 3815 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3816 | } finally { |
| 3817 | Binder.restoreCallingIdentity(identity); |
| 3818 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | @Override |
| 3822 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3823 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3824 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3826 | final long identity = Binder.clearCallingIdentity(); |
| 3827 | try { |
| 3828 | final Phone phone = getPhone(subId); |
| 3829 | return phone == null ? null : phone.getCarrierName(); |
| 3830 | } finally { |
| 3831 | Binder.restoreCallingIdentity(identity); |
| 3832 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3833 | } |
| 3834 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3835 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3836 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3837 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3838 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3839 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3840 | final long identity = Binder.clearCallingIdentity(); |
| 3841 | try { |
| 3842 | final Phone phone = getPhone(subId); |
| 3843 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3844 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3851 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3852 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3853 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3854 | "getSubscriptionSpecificCarrierName"); |
| 3855 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3859 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(identity); |
| 3862 | } |
| 3863 | } |
| 3864 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3865 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3866 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3867 | if (!isSubscriptionMccMnc) { |
| 3868 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3869 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3870 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3871 | if (phone == null) { |
| 3872 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3873 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3874 | |
| 3875 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3876 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3877 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3878 | final long identity = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
| 3883 | } |
| 3884 | } |
| 3885 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3886 | // |
| 3887 | // Internal helper methods. |
| 3888 | // |
| 3889 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3890 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3891 | * Make sure the caller is the calling package itself |
| 3892 | * |
| 3893 | * @throws SecurityException if the caller is not the calling package |
| 3894 | */ |
| 3895 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3896 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3897 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3898 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3899 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3900 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3901 | } catch (PackageManager.NameNotFoundException e) { |
| 3902 | // packageUid is -1 |
| 3903 | } |
| 3904 | if (packageUid != callingUid) { |
| 3905 | throw new SecurityException(message + ": Package " + callingPackage |
| 3906 | + " does not belong to " + callingUid); |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3911 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3912 | * |
| 3913 | * @throws SecurityException if the caller does not have the required permission |
| 3914 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3915 | @VisibleForTesting |
| 3916 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3917 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3918 | } |
| 3919 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3920 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3921 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3922 | * |
| 3923 | * @throws SecurityException if the caller does not have the required permission |
| 3924 | */ |
| 3925 | @VisibleForTesting |
| 3926 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3927 | enforceReadPermission(null); |
| 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3932 | * |
| 3933 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3934 | */ |
| 3935 | @VisibleForTesting |
| 3936 | public void enforceReadPermission(String msg) { |
| 3937 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3940 | private void enforceActiveEmergencySessionPermission() { |
| 3941 | mApp.enforceCallingOrSelfPermission( |
| 3942 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3943 | } |
| 3944 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | /** |
| 3946 | * Make sure the caller has the CALL_PHONE permission. |
| 3947 | * |
| 3948 | * @throws SecurityException if the caller does not have the required permission |
| 3949 | */ |
| 3950 | private void enforceCallPermission() { |
| 3951 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3952 | } |
| 3953 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3954 | private void enforceSettingsPermission() { |
| 3955 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3956 | } |
| 3957 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3958 | private void enforceRebootPermission() { |
| 3959 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3960 | } |
| 3961 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3962 | /** |
| 3963 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3964 | * @param message - log message to print. |
| 3965 | * @throws SecurityException if the caller does not have the required permission |
| 3966 | */ |
| 3967 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3968 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3969 | } |
| 3970 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3971 | /** |
| 3972 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3973 | * @param message - log message to print. |
| 3974 | * @throws SecurityException if the caller does not have the required permission |
| 3975 | */ |
| 3976 | private void enforcePackageUsageStatsPermission(String message) { |
| 3977 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3978 | } |
| 3979 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3980 | private String createTelUrl(String number) { |
| 3981 | if (TextUtils.isEmpty(number)) { |
| 3982 | return null; |
| 3983 | } |
| 3984 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3985 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3988 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3989 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3992 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3993 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3996 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3997 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4000 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4001 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4002 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4005 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4006 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4007 | if (!mApp.getResources().getBoolean( |
| 4008 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4009 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4010 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4011 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
| 4015 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4016 | if (phone == null) { |
| 4017 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4018 | } else { |
| 4019 | return phone.getPhoneType(); |
| 4020 | } |
| 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4023 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Returns the CDMA ERI icon index to display |
| 4028 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4029 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4030 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4031 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4032 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4035 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4036 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4037 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4038 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4039 | mApp, subId, callingPackage, callingFeatureId, |
| 4040 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4041 | return -1; |
| 4042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4043 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4044 | enforceTelephonyFeatureWithException(callingPackage, |
| 4045 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4046 | "getCdmaEriIconIndexForSubscriber"); |
| 4047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | final long identity = Binder.clearCallingIdentity(); |
| 4049 | try { |
| 4050 | final Phone phone = getPhone(subId); |
| 4051 | if (phone != null) { |
| 4052 | return phone.getCdmaEriIconIndex(); |
| 4053 | } else { |
| 4054 | return -1; |
| 4055 | } |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4058 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
| 4062 | * Returns the CDMA ERI icon mode, |
| 4063 | * 0 - ON |
| 4064 | * 1 - FLASHING |
| 4065 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4066 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4067 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4068 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4069 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4072 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4073 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4074 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4075 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4076 | mApp, subId, callingPackage, callingFeatureId, |
| 4077 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4078 | return -1; |
| 4079 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | |
| 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | final Phone phone = getPhone(subId); |
| 4084 | if (phone != null) { |
| 4085 | return phone.getCdmaEriIconMode(); |
| 4086 | } else { |
| 4087 | return -1; |
| 4088 | } |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4091 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | /** |
| 4095 | * Returns the CDMA ERI text, |
| 4096 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4097 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4098 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4099 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4100 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4103 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4104 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4105 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4107 | mApp, subId, callingPackage, callingFeatureId, |
| 4108 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4109 | return null; |
| 4110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | |
| 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | final Phone phone = getPhone(subId); |
| 4115 | if (phone != null) { |
| 4116 | return phone.getCdmaEriText(); |
| 4117 | } else { |
| 4118 | return null; |
| 4119 | } |
| 4120 | } finally { |
| 4121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4126 | * Returns the CDMA MDN. |
| 4127 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4128 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4129 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4131 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4133 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4134 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
| 4138 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4139 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | return phone.getLine1Number(); |
| 4141 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4142 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4143 | return null; |
| 4144 | } |
| 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | /** |
| 4151 | * Returns the CDMA MIN. |
| 4152 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4153 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4154 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4156 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4157 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4159 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4160 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | final Phone phone = getPhone(subId); |
| 4164 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4165 | return phone.getCdmaMin(); |
| 4166 | } else { |
| 4167 | return null; |
| 4168 | } |
| 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4174 | @Override |
| 4175 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4176 | INumberVerificationCallback callback, String callingPackage) { |
| 4177 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4178 | != PERMISSION_GRANTED) { |
| 4179 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4180 | } |
| 4181 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4182 | |
| 4183 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4184 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4185 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4186 | + "calling package: " + callingPackage |
| 4187 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4190 | enforceTelephonyFeatureWithException(callingPackage, |
| 4191 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4192 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4193 | if (range == null) { |
| 4194 | throw new NullPointerException("Range must be non-null"); |
| 4195 | } |
| 4196 | |
| 4197 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4198 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4199 | |
| 4200 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4201 | } |
| 4202 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4203 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4204 | * Returns true if CDMA provisioning needs to run. |
| 4205 | */ |
| 4206 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4207 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4208 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4210 | final long identity = Binder.clearCallingIdentity(); |
| 4211 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4212 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
| 4215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4219 | * Sets the voice mail number of a given subId. |
| 4220 | */ |
| 4221 | @Override |
| 4222 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4223 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4224 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4225 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4226 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4227 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
| 4231 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4232 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4233 | return success; |
| 4234 | } finally { |
| 4235 | Binder.restoreCallingIdentity(identity); |
| 4236 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4237 | } |
| 4238 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4239 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4240 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4241 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4242 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4243 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4244 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4245 | throw new SecurityException("caller must be system dialer"); |
| 4246 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4248 | enforceTelephonyFeatureWithException(callingPackage, |
| 4249 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | final long identity = Binder.clearCallingIdentity(); |
| 4252 | try { |
| 4253 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4254 | if (phoneAccountHandle == null) { |
| 4255 | return null; |
| 4256 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4257 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4260 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4264 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4265 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4266 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4268 | mApp, subId, callingPackage, callingFeatureId, |
| 4269 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4270 | return null; |
| 4271 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4272 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4273 | enforceTelephonyFeatureWithException(callingPackage, |
| 4274 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4275 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4278 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4285 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4286 | VisualVoicemailSmsFilterSettings settings) { |
| 4287 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4288 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4289 | enforceTelephonyFeatureWithException(callingPackage, |
| 4290 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4291 | final long identity = Binder.clearCallingIdentity(); |
| 4292 | try { |
| 4293 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4294 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(identity); |
| 4297 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4301 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4302 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4303 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4304 | enforceTelephonyFeatureWithException(callingPackage, |
| 4305 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
| 4309 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4310 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | } finally { |
| 4312 | Binder.restoreCallingIdentity(identity); |
| 4313 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4317 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4318 | String callingPackage, int subId) { |
| 4319 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4320 | |
| 4321 | final long identity = Binder.clearCallingIdentity(); |
| 4322 | try { |
| 4323 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4324 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(identity); |
| 4327 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4331 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4332 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | |
| 4334 | final long identity = Binder.clearCallingIdentity(); |
| 4335 | try { |
| 4336 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4337 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
| 4340 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4344 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4345 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4346 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4347 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4348 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4349 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4350 | |
| 4351 | enforceTelephonyFeatureWithException(callingPackage, |
| 4352 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4353 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4354 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4355 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4356 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4357 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4358 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4359 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4360 | * Sets the voice activation state of a given subId. |
| 4361 | */ |
| 4362 | @Override |
| 4363 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4365 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4367 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4368 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4369 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | final long identity = Binder.clearCallingIdentity(); |
| 4371 | try { |
| 4372 | final Phone phone = getPhone(subId); |
| 4373 | if (phone != null) { |
| 4374 | phone.setVoiceActivationState(activationState); |
| 4375 | } else { |
| 4376 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4377 | } |
| 4378 | } finally { |
| 4379 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | /** |
| 4384 | * Sets the data activation state of a given subId. |
| 4385 | */ |
| 4386 | @Override |
| 4387 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4389 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4390 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4391 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4392 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4393 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | final long identity = Binder.clearCallingIdentity(); |
| 4395 | try { |
| 4396 | final Phone phone = getPhone(subId); |
| 4397 | if (phone != null) { |
| 4398 | phone.setDataActivationState(activationState); |
| 4399 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4400 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | } |
| 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * Returns the voice activation state of a given subId. |
| 4409 | */ |
| 4410 | @Override |
| 4411 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4412 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4414 | enforceTelephonyFeatureWithException(callingPackage, |
| 4415 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4416 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4417 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4418 | final long identity = Binder.clearCallingIdentity(); |
| 4419 | try { |
| 4420 | if (phone != null) { |
| 4421 | return phone.getVoiceActivationState(); |
| 4422 | } else { |
| 4423 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4424 | } |
| 4425 | } finally { |
| 4426 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | /** |
| 4431 | * Returns the data activation state of a given subId. |
| 4432 | */ |
| 4433 | @Override |
| 4434 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4435 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4436 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4437 | enforceTelephonyFeatureWithException(callingPackage, |
| 4438 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4439 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4440 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | final long identity = Binder.clearCallingIdentity(); |
| 4442 | try { |
| 4443 | if (phone != null) { |
| 4444 | return phone.getDataActivationState(); |
| 4445 | } else { |
| 4446 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4447 | } |
| 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4454 | * Returns the unread count of voicemails for a subId |
| 4455 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4457 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4458 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4459 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4460 | mApp, subId, callingPackage, callingFeatureId, |
| 4461 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4462 | return 0; |
| 4463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
| 4466 | final Phone phone = getPhone(subId); |
| 4467 | if (phone != null) { |
| 4468 | return phone.getVoiceMessageCount(); |
| 4469 | } else { |
| 4470 | return 0; |
| 4471 | } |
| 4472 | } finally { |
| 4473 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4474 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4478 | * returns true, if the device is in a state where both voice and data |
| 4479 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4480 | */ |
| 4481 | @Override |
| 4482 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4483 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4484 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4485 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4486 | final long identity = Binder.clearCallingIdentity(); |
| 4487 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4488 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(identity); |
| 4491 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4495 | * Send the dialer code if called from the current default dialer or the caller has |
| 4496 | * carrier privilege. |
| 4497 | * @param inputCode The dialer code to send |
| 4498 | */ |
| 4499 | @Override |
| 4500 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4501 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4502 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4503 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4504 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4505 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4506 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4507 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4510 | enforceTelephonyFeatureWithException(callingPackage, |
| 4511 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4513 | final long identity = Binder.clearCallingIdentity(); |
| 4514 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4515 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | } finally { |
| 4517 | Binder.restoreCallingIdentity(identity); |
| 4518 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4519 | } |
| 4520 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4521 | @Override |
| 4522 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4523 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4524 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4525 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4526 | |
| 4527 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4528 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4529 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
| 4532 | if (!isActiveSubscription(subId)) { |
| 4533 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4534 | } |
| 4535 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4536 | } finally { |
| 4537 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4538 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4541 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4542 | public boolean isInEmergencySmsMode() { |
| 4543 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4544 | |
| 4545 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4546 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4547 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4548 | final long identity = Binder.clearCallingIdentity(); |
| 4549 | try { |
| 4550 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4551 | if (phone.isInEmergencySmsMode()) { |
| 4552 | return true; |
| 4553 | } |
| 4554 | } |
| 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
| 4557 | } |
| 4558 | return false; |
| 4559 | } |
| 4560 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4561 | /** |
| 4562 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4563 | * @param subId The subscription to use to check the configuration. |
| 4564 | * @param c The callback that will be used to send the result. |
| 4565 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4566 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4567 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4568 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4569 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4570 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4571 | |
| 4572 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4573 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4574 | "IMS not available on device."); |
| 4575 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4576 | final long token = Binder.clearCallingIdentity(); |
| 4577 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4578 | int slotId = getSlotIndexOrException(subId); |
| 4579 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4580 | |
| 4581 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4582 | if (controller != null) { |
| 4583 | ImsManager imsManager = controller.getImsManager(subId); |
| 4584 | if (imsManager != null) { |
| 4585 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4586 | } else { |
| 4587 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4588 | } |
| 4589 | } else { |
| 4590 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4591 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4592 | } catch (ImsException e) { |
| 4593 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4594 | } finally { |
| 4595 | Binder.restoreCallingIdentity(token); |
| 4596 | } |
| 4597 | } |
| 4598 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4599 | /** |
| 4600 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4601 | * @param subId The subscription to use to check the configuration. |
| 4602 | * @param c The callback that will be used to send the result. |
| 4603 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4604 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4605 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4606 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4607 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4609 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4610 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4611 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4612 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4613 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4614 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4615 | if (controller != null) { |
| 4616 | ImsManager imsManager = controller.getImsManager(subId); |
| 4617 | if (imsManager != null) { |
| 4618 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4619 | } else { |
| 4620 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4621 | + "is inactive, ignoring unregister."); |
| 4622 | // If the ImsManager is not valid, just return, since the callback |
| 4623 | // will already have been removed internally. |
| 4624 | } |
| 4625 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4626 | } finally { |
| 4627 | Binder.restoreCallingIdentity(token); |
| 4628 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4631 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4632 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4633 | * @param subId The subscription to use to check the configuration. |
| 4634 | * @param c The callback that will be used to send the result. |
| 4635 | */ |
| 4636 | @Override |
| 4637 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4638 | throws RemoteException { |
| 4639 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4640 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4641 | |
| 4642 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4643 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4644 | "IMS not available on device."); |
| 4645 | } |
| 4646 | final long token = Binder.clearCallingIdentity(); |
| 4647 | try { |
| 4648 | int slotId = getSlotIndexOrException(subId); |
| 4649 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4650 | |
| 4651 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4652 | if (controller != null) { |
| 4653 | ImsManager imsManager = controller.getImsManager(subId); |
| 4654 | if (imsManager != null) { |
| 4655 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4656 | } else { |
| 4657 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4658 | } |
| 4659 | } else { |
| 4660 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4661 | } |
| 4662 | } catch (ImsException e) { |
| 4663 | throw new ServiceSpecificException(e.getCode()); |
| 4664 | } finally { |
| 4665 | Binder.restoreCallingIdentity(token); |
| 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | /** |
| 4670 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4671 | * @param subId The subscription to use to check the configuration. |
| 4672 | * @param c The callback that will be used to send the result. |
| 4673 | */ |
| 4674 | @Override |
| 4675 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4676 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4677 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4678 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4679 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4680 | } |
| 4681 | final long token = Binder.clearCallingIdentity(); |
| 4682 | |
| 4683 | try { |
| 4684 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4685 | if (controller != null) { |
| 4686 | ImsManager imsManager = controller.getImsManager(subId); |
| 4687 | if (imsManager != null) { |
| 4688 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4689 | } else { |
| 4690 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4691 | + "is inactive, ignoring unregister."); |
| 4692 | // If the ImsManager is not valid, just return, since the callback |
| 4693 | // will already have been removed internally. |
| 4694 | } |
| 4695 | } |
| 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(token); |
| 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4702 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4703 | */ |
| 4704 | @Override |
| 4705 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4706 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4707 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4708 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4709 | "IMS not available on device."); |
| 4710 | } |
| 4711 | final long token = Binder.clearCallingIdentity(); |
| 4712 | try { |
| 4713 | Phone phone = getPhone(subId); |
| 4714 | if (phone == null) { |
| 4715 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4716 | + subId + "'"); |
| 4717 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4718 | } |
| 4719 | phone.getImsRegistrationState(regState -> { |
| 4720 | try { |
| 4721 | consumer.accept((regState == null) |
| 4722 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4723 | } catch (RemoteException e) { |
| 4724 | // Ignore if the remote process is no longer available to call back. |
| 4725 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4726 | } |
| 4727 | }); |
| 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(token); |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | /** |
| 4734 | * Get the transport type for the IMS service registration state. |
| 4735 | */ |
| 4736 | @Override |
| 4737 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4738 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4739 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4740 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4742 | "IMS not available on device."); |
| 4743 | } |
| 4744 | final long token = Binder.clearCallingIdentity(); |
| 4745 | try { |
| 4746 | Phone phone = getPhone(subId); |
| 4747 | if (phone == null) { |
| 4748 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4749 | + subId + "'"); |
| 4750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4751 | } |
| 4752 | phone.getImsRegistrationTech(regTech -> { |
| 4753 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4754 | int regTechConverted = (regTech == null) |
| 4755 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4756 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4757 | regTechConverted); |
| 4758 | try { |
| 4759 | consumer.accept(regTechConverted); |
| 4760 | } catch (RemoteException e) { |
| 4761 | // Ignore if the remote process is no longer available to call back. |
| 4762 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4763 | } |
| 4764 | }); |
| 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(token); |
| 4767 | } |
| 4768 | } |
| 4769 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4770 | /** |
| 4771 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4772 | * @param subId The subscription to use to check the configuration. |
| 4773 | * @param c The callback that will be used to send the result. |
| 4774 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4775 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4776 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4777 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4778 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4779 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4780 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4781 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4782 | "IMS not available on device."); |
| 4783 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | final long token = Binder.clearCallingIdentity(); |
| 4785 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4786 | int slotId = getSlotIndexOrException(subId); |
| 4787 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4788 | |
| 4789 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4790 | if (controller != null) { |
| 4791 | ImsManager imsManager = controller.getImsManager(subId); |
| 4792 | if (imsManager != null) { |
| 4793 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4794 | } else { |
| 4795 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4796 | } |
| 4797 | } else { |
| 4798 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4799 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4800 | } catch (ImsException e) { |
| 4801 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(token); |
| 4804 | } |
| 4805 | } |
| 4806 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4807 | /** |
| 4808 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4809 | * @param subId The subscription to use to check the configuration. |
| 4810 | * @param c The callback that will be used to send the result. |
| 4811 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4812 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4813 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4814 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4815 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4816 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4817 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4818 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4819 | |
| 4820 | final long token = Binder.clearCallingIdentity(); |
| 4821 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4822 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4823 | if (controller != null) { |
| 4824 | ImsManager imsManager = controller.getImsManager(subId); |
| 4825 | if (imsManager != null) { |
| 4826 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4827 | } else { |
| 4828 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4829 | + " is inactive, ignoring unregister."); |
| 4830 | // If the ImsManager is not valid, just return, since the callback |
| 4831 | // will already have been removed internally. |
| 4832 | } |
| 4833 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4834 | } finally { |
| 4835 | Binder.restoreCallingIdentity(token); |
| 4836 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4840 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4841 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4842 | |
| 4843 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4844 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4845 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4846 | final long token = Binder.clearCallingIdentity(); |
| 4847 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4848 | int slotId = getSlotIndexOrException(subId); |
| 4849 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4850 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4851 | } catch (com.android.ims.ImsException e) { |
| 4852 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4853 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4854 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4855 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4856 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4857 | } finally { |
| 4858 | Binder.restoreCallingIdentity(token); |
| 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4863 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4864 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4865 | |
| 4866 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4867 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4868 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4869 | final long token = Binder.clearCallingIdentity(); |
| 4870 | try { |
| 4871 | Phone phone = getPhone(subId); |
| 4872 | if (phone == null) return false; |
| 4873 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4874 | } catch (com.android.ims.ImsException e) { |
| 4875 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4876 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4877 | } finally { |
| 4878 | Binder.restoreCallingIdentity(token); |
| 4879 | } |
| 4880 | } |
| 4881 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4882 | /** |
| 4883 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4884 | * subscription. |
| 4885 | * @param subId The subscription to use to check the configuration. |
| 4886 | * @param callback The callback that will be used to send the result. |
| 4887 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4888 | * @param transportType The transport type of the MmTelFeature capability. |
| 4889 | */ |
| 4890 | @Override |
| 4891 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4892 | int transportType) { |
| 4893 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4894 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4895 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4896 | "IMS not available on device."); |
| 4897 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4898 | final long token = Binder.clearCallingIdentity(); |
| 4899 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4900 | int slotId = getSlotIndex(subId); |
| 4901 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4902 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4903 | + subId + "'"); |
| 4904 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4905 | } |
| 4906 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4907 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4908 | transportType, aBoolean -> { |
| 4909 | try { |
| 4910 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4911 | } catch (RemoteException e) { |
| 4912 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4913 | + "running. Ignore"); |
| 4914 | } |
| 4915 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4916 | } catch (ImsException e) { |
| 4917 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(token); |
| 4920 | } |
| 4921 | } |
| 4922 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4923 | /** |
| 4924 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4925 | * @param subId The subscription to use to check the configuration. |
| 4926 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4927 | @Override |
| 4928 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4929 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4930 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4931 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4932 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4933 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4934 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4935 | final long token = Binder.clearCallingIdentity(); |
| 4936 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4937 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4938 | // 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] | 4939 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4940 | } catch (ImsException e) { |
| 4941 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(token); |
| 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4948 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4950 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4951 | |
| 4952 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4953 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4954 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4955 | final long identity = Binder.clearCallingIdentity(); |
| 4956 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4957 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4958 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4959 | // 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] | 4960 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4961 | } catch (ImsException e) { |
| 4962 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(identity); |
| 4965 | } |
| 4966 | } |
| 4967 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4968 | /** |
| 4969 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4970 | * @param subId The subscription to use to check the configuration. |
| 4971 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4973 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4974 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4975 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4976 | |
| 4977 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4978 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4979 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | final long identity = Binder.clearCallingIdentity(); |
| 4981 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4982 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4983 | // 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] | 4984 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4985 | } catch (ImsException e) { |
| 4986 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4993 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4995 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4996 | |
| 4997 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4998 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4999 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5000 | final long identity = Binder.clearCallingIdentity(); |
| 5001 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5002 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5003 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5004 | // 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] | 5005 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5006 | } catch (ImsException e) { |
| 5007 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5008 | } finally { |
| 5009 | Binder.restoreCallingIdentity(identity); |
| 5010 | } |
| 5011 | } |
| 5012 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5013 | /** |
| 5014 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5015 | * @param subId The subscription to use to check the configuration. |
| 5016 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5017 | @Override |
| 5018 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5019 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5020 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5021 | |
| 5022 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5023 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5024 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5025 | final long identity = Binder.clearCallingIdentity(); |
| 5026 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5027 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5028 | // 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] | 5029 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5030 | } catch (ImsException e) { |
| 5031 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5032 | } finally { |
| 5033 | Binder.restoreCallingIdentity(identity); |
| 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5038 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5040 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5041 | |
| 5042 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5043 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5044 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5047 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5048 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5049 | // 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] | 5050 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5051 | } catch (ImsException e) { |
| 5052 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5053 | } finally { |
| 5054 | Binder.restoreCallingIdentity(identity); |
| 5055 | } |
| 5056 | } |
| 5057 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5058 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5059 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5060 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5061 | * @param subId The subscription to use to check the configuration. |
| 5062 | */ |
| 5063 | @Override |
| 5064 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5065 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5066 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5067 | |
| 5068 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5069 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5070 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5071 | final long identity = Binder.clearCallingIdentity(); |
| 5072 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5073 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5074 | // 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] | 5075 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5076 | } catch (ImsException e) { |
| 5077 | throw new ServiceSpecificException(e.getCode()); |
| 5078 | } finally { |
| 5079 | Binder.restoreCallingIdentity(identity); |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | /** |
| 5084 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5085 | * Requires MODIFY_PHONE_STATE permission. |
| 5086 | * @param subId The subscription to use to check the configuration. |
| 5087 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5088 | * false otherwise |
| 5089 | */ |
| 5090 | @Override |
| 5091 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5093 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5094 | |
| 5095 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5096 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5097 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5098 | final long identity = Binder.clearCallingIdentity(); |
| 5099 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5100 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5101 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5102 | // 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] | 5103 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5104 | } catch (ImsException e) { |
| 5105 | throw new ServiceSpecificException(e.getCode()); |
| 5106 | } finally { |
| 5107 | Binder.restoreCallingIdentity(identity); |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5112 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5113 | * @param subId The subscription to use to check the configuration. |
| 5114 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5115 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5116 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5117 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5118 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5119 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5120 | |
| 5121 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5122 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5123 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5124 | final long identity = Binder.clearCallingIdentity(); |
| 5125 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5126 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5127 | // 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] | 5128 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5129 | } catch (ImsException e) { |
| 5130 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(identity); |
| 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5137 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5139 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5140 | |
| 5141 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5142 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5143 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | final long identity = Binder.clearCallingIdentity(); |
| 5145 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5146 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5147 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5148 | // 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] | 5149 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5150 | } catch (ImsException e) { |
| 5151 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | @Override |
| 5158 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5160 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5161 | |
| 5162 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5163 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5164 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5167 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5168 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5169 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5170 | } catch (ImsException e) { |
| 5171 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5172 | } finally { |
| 5173 | Binder.restoreCallingIdentity(identity); |
| 5174 | } |
| 5175 | } |
| 5176 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5177 | /** |
| 5178 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5179 | * @param subId The subscription to use to check the configuration. |
| 5180 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5181 | @Override |
| 5182 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5183 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5184 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5185 | |
| 5186 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5187 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5188 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5189 | final long identity = Binder.clearCallingIdentity(); |
| 5190 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5191 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5192 | // 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] | 5193 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5194 | } catch (ImsException e) { |
| 5195 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5196 | } finally { |
| 5197 | Binder.restoreCallingIdentity(identity); |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | @Override |
| 5202 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5203 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5204 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5205 | |
| 5206 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5207 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5208 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5209 | final long identity = Binder.clearCallingIdentity(); |
| 5210 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5211 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5212 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5213 | // 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] | 5214 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5215 | } catch (ImsException e) { |
| 5216 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5217 | } finally { |
| 5218 | Binder.restoreCallingIdentity(identity); |
| 5219 | } |
| 5220 | } |
| 5221 | |
| 5222 | @Override |
| 5223 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5224 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5225 | |
| 5226 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5227 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5228 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5229 | final long identity = Binder.clearCallingIdentity(); |
| 5230 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5231 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5232 | // 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] | 5233 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5234 | } catch (ImsException e) { |
| 5235 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5236 | } finally { |
| 5237 | Binder.restoreCallingIdentity(identity); |
| 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | @Override |
| 5242 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5244 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5245 | |
| 5246 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5247 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5248 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5249 | final long identity = Binder.clearCallingIdentity(); |
| 5250 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5251 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5252 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5253 | // 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] | 5254 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5255 | } catch (ImsException e) { |
| 5256 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5257 | } finally { |
| 5258 | Binder.restoreCallingIdentity(identity); |
| 5259 | } |
| 5260 | } |
| 5261 | |
| 5262 | @Override |
| 5263 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5265 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5266 | |
| 5267 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5268 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5269 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5272 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5273 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5274 | // 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] | 5275 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5276 | } catch (ImsException e) { |
| 5277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5278 | } finally { |
| 5279 | Binder.restoreCallingIdentity(identity); |
| 5280 | } |
| 5281 | } |
| 5282 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5283 | /** |
| 5284 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5285 | * @param subId The subscription to use to check the configuration. |
| 5286 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5287 | @Override |
| 5288 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5289 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5290 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5291 | |
| 5292 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5293 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5294 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5295 | final long identity = Binder.clearCallingIdentity(); |
| 5296 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5297 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5298 | // 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] | 5299 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5300 | } catch (ImsException e) { |
| 5301 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
| 5305 | } |
| 5306 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5307 | @Override |
| 5308 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5309 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5310 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5311 | final long identity = Binder.clearCallingIdentity(); |
| 5312 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5313 | if (!isImsAvailableOnDevice()) { |
| 5314 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5315 | "IMS not available on device."); |
| 5316 | } |
| 5317 | int slotId = getSlotIndexOrException(subId); |
| 5318 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5319 | |
| 5320 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5321 | if (controller != null) { |
| 5322 | ImsManager imsManager = controller.getImsManager(subId); |
| 5323 | if (imsManager != null) { |
| 5324 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5325 | } else { |
| 5326 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5327 | } |
| 5328 | } else { |
| 5329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5330 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5331 | } catch (ImsException e) { |
| 5332 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | @Override |
| 5339 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5340 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5341 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5342 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5343 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5344 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5345 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5346 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5347 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5348 | if (controller != null) { |
| 5349 | ImsManager imsManager = controller.getImsManager(subId); |
| 5350 | if (imsManager != null) { |
| 5351 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5352 | } else { |
| 5353 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5354 | + " is inactive, ignoring unregister."); |
| 5355 | // If the ImsManager is not valid, just return, since the callback will already |
| 5356 | // have been removed internally. |
| 5357 | } |
| 5358 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5359 | } finally { |
| 5360 | Binder.restoreCallingIdentity(identity); |
| 5361 | } |
| 5362 | } |
| 5363 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5364 | @Override |
| 5365 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5366 | IFeatureProvisioningCallback callback) { |
| 5367 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5368 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5369 | |
| 5370 | final long identity = Binder.clearCallingIdentity(); |
| 5371 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5372 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5373 | } |
| 5374 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5375 | try { |
| 5376 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5377 | if (controller == null) { |
| 5378 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5379 | "Device does not support IMS"); |
| 5380 | } |
| 5381 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
| 5384 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | @Override |
| 5388 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5389 | IFeatureProvisioningCallback callback) { |
| 5390 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5391 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5392 | |
| 5393 | final long identity = Binder.clearCallingIdentity(); |
| 5394 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5395 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5396 | } |
| 5397 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5398 | try { |
| 5399 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5400 | if (controller == null) { |
| 5401 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5402 | return; |
| 5403 | } |
| 5404 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5405 | } finally { |
| 5406 | Binder.restoreCallingIdentity(identity); |
| 5407 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5408 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5409 | |
| 5410 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5412 | message); |
| 5413 | } |
| 5414 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5415 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5416 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5417 | boolean isProvisioned) { |
| 5418 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5419 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5420 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5421 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5422 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5423 | final long identity = Binder.clearCallingIdentity(); |
| 5424 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5425 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5426 | if (controller == null) { |
| 5427 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5428 | return; |
| 5429 | } |
| 5430 | controller.setRcsProvisioningStatusForCapability( |
| 5431 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5432 | } finally { |
| 5433 | Binder.restoreCallingIdentity(identity); |
| 5434 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | |
| 5438 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5439 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5440 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5441 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5442 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5443 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5444 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5445 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5446 | final long identity = Binder.clearCallingIdentity(); |
| 5447 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5448 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5449 | if (controller == null) { |
| 5450 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5451 | |
| 5452 | // device does not support IMS, this method will return true always. |
| 5453 | return true; |
| 5454 | } |
| 5455 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
| 5458 | } |
| 5459 | } |
| 5460 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5461 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5462 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5463 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5464 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5466 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5467 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5468 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5469 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5470 | final long identity = Binder.clearCallingIdentity(); |
| 5471 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5472 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5473 | if (controller == null) { |
| 5474 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5475 | return; |
| 5476 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5477 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5478 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | @Override |
| 5485 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5486 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5487 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5488 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5489 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5490 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5491 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5492 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5493 | final long identity = Binder.clearCallingIdentity(); |
| 5494 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5495 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5496 | if (controller == null) { |
| 5497 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5498 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5499 | // device does not support IMS, this method will return true always. |
| 5500 | return true; |
| 5501 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5502 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5503 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5504 | } finally { |
| 5505 | Binder.restoreCallingIdentity(identity); |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5510 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5511 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5512 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5513 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5514 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5515 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5516 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5517 | final long identity = Binder.clearCallingIdentity(); |
| 5518 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5519 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5520 | if (controller == null) { |
| 5521 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5522 | |
| 5523 | // device does not support IMS, this method will return false |
| 5524 | return false; |
| 5525 | } |
| 5526 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5527 | } finally { |
| 5528 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5529 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5533 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5534 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5535 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5536 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5537 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5538 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5539 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5540 | final long identity = Binder.clearCallingIdentity(); |
| 5541 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5542 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5543 | if (controller == null) { |
| 5544 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5545 | |
| 5546 | // device does not support IMS, this method will return false |
| 5547 | return false; |
| 5548 | } |
| 5549 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5550 | } finally { |
| 5551 | Binder.restoreCallingIdentity(identity); |
| 5552 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5553 | } |
| 5554 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5555 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5556 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5557 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5558 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5559 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5560 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5561 | mApp, subId, "getImsProvisioningInt"); |
| 5562 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5563 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5564 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5565 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5566 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5567 | final long identity = Binder.clearCallingIdentity(); |
| 5568 | try { |
| 5569 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5570 | int slotId = getSlotIndex(subId); |
| 5571 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5572 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5573 | + subId + "' for key:" + key); |
| 5574 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5575 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5576 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5577 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5578 | if (controller == null) { |
| 5579 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5580 | |
| 5581 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5582 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5583 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5584 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5585 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5586 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5587 | return retVal; |
| 5588 | } |
| 5589 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5590 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5591 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5592 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5593 | + subId + "' for key:" + key); |
| 5594 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | @Override |
| 5601 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5602 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5603 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5604 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5605 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5606 | mApp, subId, "getImsProvisioningString"); |
| 5607 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5608 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5609 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5610 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5611 | final long identity = Binder.clearCallingIdentity(); |
| 5612 | try { |
| 5613 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5614 | int slotId = getSlotIndex(subId); |
| 5615 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5616 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5617 | + subId + "' for key:" + key); |
| 5618 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5619 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5620 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5621 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5622 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5623 | + subId + "' for key:" + key); |
| 5624 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(identity); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | @Override |
| 5631 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5632 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5633 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5634 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5636 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5637 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5638 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5639 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5640 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5641 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
| 5644 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5645 | int slotId = getSlotIndex(subId); |
| 5646 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5647 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5648 | + subId + "' for key:" + key); |
| 5649 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5650 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5651 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5652 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5653 | if (controller == null) { |
| 5654 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5655 | |
| 5656 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5657 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5658 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5659 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5660 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5661 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5662 | return retVal; |
| 5663 | } |
| 5664 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5665 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5666 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5667 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5668 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5669 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
| 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | @Override |
| 5676 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5677 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5678 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5679 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5681 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5682 | |
| 5683 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5684 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5685 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
| 5688 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5689 | int slotId = getSlotIndex(subId); |
| 5690 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5691 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5692 | + subId + "' for key:" + key); |
| 5693 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5694 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5695 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5696 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5697 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5698 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5699 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
| 5702 | } |
| 5703 | } |
| 5704 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5705 | /** |
| 5706 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5707 | * for the given slot ID or no ImsResolver instance has been created. |
| 5708 | * @param slotId The slot ID that the IMS service is created for. |
| 5709 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5710 | */ |
| 5711 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5712 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5713 | ImsFeature.FEATURE_MMTEL)) { |
| 5714 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5715 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5716 | } |
| 5717 | } |
| 5718 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5719 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5720 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5721 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5722 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5723 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5724 | } |
| 5725 | return slotId; |
| 5726 | } |
| 5727 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5728 | private int getSlotIndex(int subId) { |
| 5729 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5730 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5731 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5732 | } |
| 5733 | return slotId; |
| 5734 | } |
| 5735 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5736 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5737 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5738 | */ |
| 5739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5740 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5741 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5742 | try { |
| 5743 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5744 | } catch (SecurityException se) { |
| 5745 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5746 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5747 | + Binder.getCallingUid()); |
| 5748 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5749 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5750 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5751 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5752 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5753 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5754 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5755 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5756 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5757 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5758 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5759 | enforceTelephonyFeatureWithException(callingPackage, |
| 5760 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5761 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5762 | final long identity = Binder.clearCallingIdentity(); |
| 5763 | try { |
| 5764 | final Phone phone = getPhone(subId); |
| 5765 | if (phone != null) { |
| 5766 | return phone.getServiceState().getDataNetworkType(); |
| 5767 | } else { |
| 5768 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5769 | } |
| 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5772 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | /** |
| 5776 | * Returns the data network type |
| 5777 | */ |
| 5778 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5779 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5780 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5781 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * Returns the data network type for a subId |
| 5786 | */ |
| 5787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5788 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5789 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5790 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5791 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5792 | mApp, functionName)) { |
| 5793 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5794 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5795 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5796 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5799 | enforceTelephonyFeatureWithException(callingPackage, |
| 5800 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5801 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 | final long identity = Binder.clearCallingIdentity(); |
| 5803 | try { |
| 5804 | final Phone phone = getPhone(subId); |
| 5805 | if (phone != null) { |
| 5806 | return phone.getServiceState().getDataNetworkType(); |
| 5807 | } else { |
| 5808 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5809 | } |
| 5810 | } finally { |
| 5811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5816 | * Returns the Voice network type for a subId |
| 5817 | */ |
| 5818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5819 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5820 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5821 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5822 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5823 | mApp, functionName)) { |
| 5824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5825 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5826 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5827 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5828 | } |
| 5829 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5830 | enforceTelephonyFeatureWithException(callingPackage, |
| 5831 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | final long identity = Binder.clearCallingIdentity(); |
| 5834 | try { |
| 5835 | final Phone phone = getPhone(subId); |
| 5836 | if (phone != null) { |
| 5837 | return phone.getServiceState().getVoiceNetworkType(); |
| 5838 | } else { |
| 5839 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5840 | } |
| 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
| 5846 | /** |
| 5847 | * @return true if a ICC card is present |
| 5848 | */ |
| 5849 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5850 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5851 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5852 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5856 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5857 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5858 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5859 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5860 | if (!mApp.getResources().getBoolean( |
| 5861 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5862 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5863 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5864 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | final long identity = Binder.clearCallingIdentity(); |
| 5867 | try { |
| 5868 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5869 | if (phone != null) { |
| 5870 | return phone.getIccCard().hasIccCard(); |
| 5871 | } else { |
| 5872 | return false; |
| 5873 | } |
| 5874 | } finally { |
| 5875 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | /** |
| 5880 | * Return if the current radio is LTE on CDMA. This |
| 5881 | * is a tri-state return value as for a period of time |
| 5882 | * the mode may be unknown. |
| 5883 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5884 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5885 | * @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] | 5886 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5887 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5888 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5889 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5890 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5891 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5894 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5895 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5896 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5897 | try { |
| 5898 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5899 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5900 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5901 | } |
| 5902 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5903 | enforceTelephonyFeatureWithException(callingPackage, |
| 5904 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5905 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
| 5908 | final Phone phone = getPhone(subId); |
| 5909 | if (phone == null) { |
| 5910 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5911 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5912 | return TelephonyProperties.lte_on_cdma_device() |
| 5913 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | } |
| 5915 | } finally { |
| 5916 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5917 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5920 | /** |
| 5921 | * {@hide} |
| 5922 | * Returns Default subId, 0 in the case of single standby. |
| 5923 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5924 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5925 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5928 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5929 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5930 | } |
| 5931 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5932 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5933 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5934 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5935 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5936 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5937 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5938 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5941 | /** |
| 5942 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5943 | */ |
| 5944 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | final long identity = Binder.clearCallingIdentity(); |
| 5946 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5947 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5949 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5950 | } finally { |
| 5951 | Binder.restoreCallingIdentity(identity); |
| 5952 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | /** |
| 5956 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5957 | */ |
| 5958 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | final long identity = Binder.clearCallingIdentity(); |
| 5960 | try { |
| 5961 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5962 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5964 | } finally { |
| 5965 | Binder.restoreCallingIdentity(identity); |
| 5966 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5967 | } |
| 5968 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5969 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5970 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5971 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5972 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5973 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5974 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5975 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5976 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5977 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5978 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5979 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5980 | } |
| 5981 | return PhoneFactory.getPhone(phoneId); |
| 5982 | } |
| 5983 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5984 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5985 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5986 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5987 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5988 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5989 | /*message=*/ "iccOpenLogicalChannel"); |
| 5990 | |
| 5991 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5992 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5993 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5994 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5995 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5996 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5997 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5998 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5999 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6000 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6001 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6002 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6003 | Phone phone; |
| 6004 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6006 | mApp, request.subId, message); |
| 6007 | phone = getPhoneFromSubId(request.subId); |
| 6008 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6009 | enforceModifyPermission(); |
| 6010 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6011 | } else { |
| 6012 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6013 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6014 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6018 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | final long identity = Binder.clearCallingIdentity(); |
| 6020 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6021 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6023 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6024 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6025 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6026 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | loge("The calling package is not allowed to access ISD-R."); |
| 6028 | throw new SecurityException( |
| 6029 | "The calling package is not allowed to access ISD-R."); |
| 6030 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6031 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6034 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6035 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | return response; |
| 6037 | } finally { |
| 6038 | Binder.restoreCallingIdentity(identity); |
| 6039 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6043 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6044 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6045 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6046 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6047 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6048 | /*message=*/"iccCloseLogicalChannel"); |
| 6049 | |
| 6050 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6051 | |
| 6052 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6053 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6054 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6055 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6056 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6057 | // before this feature is enabled, this API should only return false if |
| 6058 | // the operation fails instead of throwing runtime exception for |
| 6059 | // backward-compatibility. |
| 6060 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6061 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | final long identity = Binder.clearCallingIdentity(); |
| 6063 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6064 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6065 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6067 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6068 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6069 | Boolean success = false; |
| 6070 | if (result instanceof RuntimeException) { |
| 6071 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6072 | if (shouldThrowExceptionOnFailure) { |
| 6073 | throw (RuntimeException) result; |
| 6074 | } else { |
| 6075 | return false; |
| 6076 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6077 | } else if (result instanceof Boolean) { |
| 6078 | success = (Boolean) result; |
| 6079 | } else { |
| 6080 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6081 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6082 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6083 | return success; |
| 6084 | } finally { |
| 6085 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6086 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6090 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6091 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6093 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6094 | |
| 6095 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6096 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6097 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6098 | if (DBG) { |
| 6099 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6100 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6101 | + p3 + " data=" + data); |
| 6102 | } |
| 6103 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6104 | command, p1, p2, p3, data); |
| 6105 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6106 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6107 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6108 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6109 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6110 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6111 | |
| 6112 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6113 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6114 | "iccTransmitApduLogicalChannelBySlot"); |
| 6115 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6116 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6117 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6118 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6119 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6120 | } |
| 6121 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6122 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6123 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6127 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | final long identity = Binder.clearCallingIdentity(); |
| 6129 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6130 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | return ""; |
| 6132 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6133 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6135 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6136 | null /* workSource */); |
| 6137 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | // Append the returned status code to the end of the response payload. |
| 6140 | String s = Integer.toHexString( |
| 6141 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6142 | if (response.payload != null) { |
| 6143 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6144 | } |
| 6145 | return s; |
| 6146 | } finally { |
| 6147 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6148 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6149 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6150 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6151 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6152 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6153 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6155 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6157 | |
| 6158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6159 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6160 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6161 | if (DBG) { |
| 6162 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6163 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6164 | } |
| 6165 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6166 | cla, command, p1, p2, p3, data); |
| 6167 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6168 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6169 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6170 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6171 | 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] | 6172 | enforceModifyPermission(); |
| 6173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6174 | |
| 6175 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6176 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6177 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6178 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6179 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6180 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6181 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6185 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6186 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6190 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6191 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
| 6194 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6195 | && TextUtils.equals(ISDR_AID, data)) { |
| 6196 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6197 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6198 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6199 | if (bestComponent == null |
| 6200 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6201 | loge("The calling package is not allowed to select ISD-R."); |
| 6202 | throw new SecurityException( |
| 6203 | "The calling package is not allowed to select ISD-R."); |
| 6204 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6205 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6208 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6209 | null /* workSource */); |
| 6210 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6211 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6212 | // Append the returned status code to the end of the response payload. |
| 6213 | String s = Integer.toHexString( |
| 6214 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6215 | if (response.payload != null) { |
| 6216 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6217 | } |
| 6218 | return s; |
| 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6221 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6225 | 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] | 6226 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6228 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6229 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6231 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6232 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | final long identity = Binder.clearCallingIdentity(); |
| 6234 | try { |
| 6235 | if (DBG) { |
| 6236 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6237 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6238 | } |
| 6239 | |
| 6240 | IccIoResult response = |
| 6241 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6242 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6243 | subId); |
| 6244 | |
| 6245 | if (DBG) { |
| 6246 | log("Exchange SIM_IO [R]" + response); |
| 6247 | } |
| 6248 | |
| 6249 | byte[] result = null; |
| 6250 | int length = 2; |
| 6251 | if (response.payload != null) { |
| 6252 | length = 2 + response.payload.length; |
| 6253 | result = new byte[length]; |
| 6254 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6255 | } else { |
| 6256 | result = new byte[length]; |
| 6257 | } |
| 6258 | |
| 6259 | result[length - 1] = (byte) response.sw2; |
| 6260 | result[length - 2] = (byte) response.sw1; |
| 6261 | return result; |
| 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6264 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6265 | } |
| 6266 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6267 | /** |
| 6268 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6269 | * on a particular subscription |
| 6270 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6271 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6272 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6273 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6274 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6275 | return null; |
| 6276 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6278 | enforceTelephonyFeatureWithException(callingPackage, |
| 6279 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6280 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | final long identity = Binder.clearCallingIdentity(); |
| 6282 | try { |
| 6283 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6284 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6285 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6286 | return null; |
| 6287 | } |
| 6288 | Object response = sendRequest( |
| 6289 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6290 | if (response instanceof String[]) { |
| 6291 | return (String[]) response; |
| 6292 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6293 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6295 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | } finally { |
| 6297 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6298 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6299 | } |
| 6300 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6301 | /** |
| 6302 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6303 | * subscription. |
| 6304 | * |
| 6305 | * @param subId the id of the subscription. |
| 6306 | * @param appType the uicc app type, must be USIM or SIM. |
| 6307 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6308 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6309 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6310 | * @return number of fplmns that is successfully written to the SIM. |
| 6311 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6312 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6313 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6314 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6315 | mApp, subId, "setForbiddenPlmns"); |
| 6316 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6317 | enforceTelephonyFeatureWithException(callingPackage, |
| 6318 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6319 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6320 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6321 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6322 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6323 | } |
| 6324 | if (fplmns == null) { |
| 6325 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6326 | } |
| 6327 | for (String fplmn : fplmns) { |
| 6328 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6329 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6330 | } |
| 6331 | } |
| 6332 | final long identity = Binder.clearCallingIdentity(); |
| 6333 | try { |
| 6334 | Object response = sendRequest( |
| 6335 | CMD_SET_FORBIDDEN_PLMNS, |
| 6336 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6337 | subId); |
| 6338 | return (int) response; |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
| 6342 | } |
| 6343 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6344 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6345 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6347 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6348 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6349 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6350 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6351 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
| 6354 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6355 | if (response.payload == null) { |
| 6356 | return ""; |
| 6357 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6358 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | // Append the returned status code to the end of the response payload. |
| 6360 | String s = Integer.toHexString( |
| 6361 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6362 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6363 | return s; |
| 6364 | } finally { |
| 6365 | Binder.restoreCallingIdentity(identity); |
| 6366 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6367 | } |
| 6368 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6369 | /** |
| 6370 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6371 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6372 | * |
| 6373 | * @param itemID the ID of the item to read |
| 6374 | * @return the NV item as a String, or null on error. |
| 6375 | */ |
| 6376 | @Override |
| 6377 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6378 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6380 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6381 | |
| 6382 | final long identity = Binder.clearCallingIdentity(); |
| 6383 | try { |
| 6384 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6385 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6387 | return value; |
| 6388 | } finally { |
| 6389 | Binder.restoreCallingIdentity(identity); |
| 6390 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | /** |
| 6394 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6395 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6396 | * |
| 6397 | * @param itemID the ID of the item to read |
| 6398 | * @param itemValue the value to write, as a String |
| 6399 | * @return true on success; false on any failure |
| 6400 | */ |
| 6401 | @Override |
| 6402 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6403 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6405 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | |
| 6407 | final long identity = Binder.clearCallingIdentity(); |
| 6408 | try { |
| 6409 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6410 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6411 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6413 | return success; |
| 6414 | } finally { |
| 6415 | Binder.restoreCallingIdentity(identity); |
| 6416 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | /** |
| 6420 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6421 | * Used for device configuration by some CDMA operators. |
| 6422 | * |
| 6423 | * @param preferredRoamingList byte array containing the new PRL |
| 6424 | * @return true on success; false on any failure |
| 6425 | */ |
| 6426 | @Override |
| 6427 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6429 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6430 | |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
| 6433 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6434 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6435 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6436 | return success; |
| 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
| 6439 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6443 | * 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] | 6444 | * Used for device configuration by some CDMA operators. |
| 6445 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6446 | * @param slotIndex - device slot. |
| 6447 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6448 | * @return true on success; false on any failure |
| 6449 | */ |
| 6450 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6451 | public boolean resetModemConfig(int slotIndex) { |
| 6452 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6453 | if (phone != null) { |
| 6454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6455 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6456 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6457 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6458 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6459 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
| 6462 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6463 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6464 | return success; |
| 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
| 6467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6469 | return false; |
| 6470 | } |
| 6471 | |
| 6472 | /** |
| 6473 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6474 | * |
| 6475 | * @param slotIndex - device slot. |
| 6476 | * |
| 6477 | * @return true on success; false on any failure |
| 6478 | */ |
| 6479 | @Override |
| 6480 | public boolean rebootModem(int slotIndex) { |
| 6481 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6482 | if (phone != null) { |
| 6483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6484 | mApp, phone.getSubId(), "rebootModem"); |
| 6485 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6486 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6487 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6488 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6489 | final long identity = Binder.clearCallingIdentity(); |
| 6490 | try { |
| 6491 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6492 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6493 | return success; |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
| 6496 | } |
| 6497 | } |
| 6498 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6499 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6500 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6501 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6502 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6503 | * {@link #disableIms(int)}. |
| 6504 | * @param slotIndex device slot. |
| 6505 | */ |
| 6506 | public void resetIms(int slotIndex) { |
| 6507 | enforceModifyPermission(); |
| 6508 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6509 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6510 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6511 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6512 | final long identity = Binder.clearCallingIdentity(); |
| 6513 | try { |
| 6514 | if (mImsResolver == null) { |
| 6515 | // may happen if the does not support IMS. |
| 6516 | return; |
| 6517 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6518 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6525 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6526 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6527 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6528 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6529 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | |
| 6531 | final long identity = Binder.clearCallingIdentity(); |
| 6532 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6533 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6534 | // may happen if the device does not support IMS. |
| 6535 | return; |
| 6536 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6537 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
| 6540 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6544 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6545 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6546 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6547 | public void disableIms(int slotId) { |
| 6548 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | |
| 6550 | final long identity = Binder.clearCallingIdentity(); |
| 6551 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6552 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6553 | // may happen if the device does not support IMS. |
| 6554 | return; |
| 6555 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
| 6559 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
| 6562 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6563 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6564 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6565 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6566 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6567 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6568 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6569 | |
| 6570 | final long identity = Binder.clearCallingIdentity(); |
| 6571 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6572 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6573 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6574 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6575 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6576 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | } finally { |
| 6578 | Binder.restoreCallingIdentity(identity); |
| 6579 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6580 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6581 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6582 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6583 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6584 | @Override |
| 6585 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6586 | enforceModifyPermission(); |
| 6587 | |
| 6588 | final long identity = Binder.clearCallingIdentity(); |
| 6589 | try { |
| 6590 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6591 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6592 | } finally { |
| 6593 | Binder.restoreCallingIdentity(identity); |
| 6594 | } |
| 6595 | } |
| 6596 | |
| 6597 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6598 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6599 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6600 | */ |
| 6601 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6602 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6603 | |
| 6604 | final long identity = Binder.clearCallingIdentity(); |
| 6605 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6606 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6607 | // may happen if the device does not support IMS. |
| 6608 | return null; |
| 6609 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6610 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | } finally { |
| 6612 | Binder.restoreCallingIdentity(identity); |
| 6613 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6614 | } |
| 6615 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6616 | /** |
| 6617 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6618 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6619 | */ |
| 6620 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6621 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6622 | |
| 6623 | final long identity = Binder.clearCallingIdentity(); |
| 6624 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6625 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6626 | // may happen if the device does not support IMS. |
| 6627 | return null; |
| 6628 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6629 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(identity); |
| 6632 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6633 | } |
| 6634 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6635 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6636 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6637 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6638 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6639 | * @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] | 6640 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6641 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6642 | * @param packageName The name of the package that the current configuration will be replaced |
| 6643 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6644 | * @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] | 6645 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6646 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6647 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6648 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6649 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6650 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6651 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6652 | final long identity = Binder.clearCallingIdentity(); |
| 6653 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6655 | // may happen if the device does not support IMS. |
| 6656 | return false; |
| 6657 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6658 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6659 | for (int featureType : featureTypes) { |
| 6660 | featureConfig.put(featureType, packageName); |
| 6661 | } |
| 6662 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6663 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6664 | } finally { |
| 6665 | Binder.restoreCallingIdentity(identity); |
| 6666 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6670 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6671 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6672 | * |
| 6673 | * This should only be used for testing. |
| 6674 | * |
| 6675 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6676 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6677 | */ |
| 6678 | @Override |
| 6679 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6680 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6681 | "clearCarrierImsServiceOverride"); |
| 6682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6683 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6684 | |
| 6685 | final long identity = Binder.clearCallingIdentity(); |
| 6686 | try { |
| 6687 | if (mImsResolver == null) { |
| 6688 | // may happen if the device does not support IMS. |
| 6689 | return false; |
| 6690 | } |
| 6691 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
| 6694 | } |
| 6695 | } |
| 6696 | |
| 6697 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6698 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6699 | * |
| 6700 | * @param slotId The slot that the ImsService is associated with. |
| 6701 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6702 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6703 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6704 | * @return the package name of the ImsService configuration. |
| 6705 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6706 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6707 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6708 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6709 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6710 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6712 | final long identity = Binder.clearCallingIdentity(); |
| 6713 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6714 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6715 | // may happen if the device does not support IMS. |
| 6716 | return ""; |
| 6717 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6718 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6719 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6720 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
| 6723 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6724 | } |
| 6725 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6726 | /** |
| 6727 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6728 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6729 | * @param callback A callback with an integer containing the |
| 6730 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6731 | */ |
| 6732 | @Override |
| 6733 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6734 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6735 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6737 | "IMS not available on device."); |
| 6738 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6739 | final long token = Binder.clearCallingIdentity(); |
| 6740 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6741 | int slotId = getSlotIndex(subId); |
| 6742 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6743 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6744 | + subId + "'"); |
| 6745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6746 | } |
| 6747 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6748 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6749 | try { |
| 6750 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6751 | } catch (RemoteException e) { |
| 6752 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6753 | + "Ignore"); |
| 6754 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6755 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6756 | } catch (ImsException e) { |
| 6757 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6758 | } finally { |
| 6759 | Binder.restoreCallingIdentity(token); |
| 6760 | } |
| 6761 | } |
| 6762 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6763 | /** |
| 6764 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6765 | */ |
| 6766 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6767 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6768 | |
| 6769 | final long identity = Binder.clearCallingIdentity(); |
| 6770 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6771 | // NOTE: Before S, this method only set the default phone. |
| 6772 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6773 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6774 | phone.setImsRegistrationState(registered); |
| 6775 | } |
| 6776 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 | } finally { |
| 6778 | Binder.restoreCallingIdentity(identity); |
| 6779 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6783 | * Set the network selection mode to automatic. |
| 6784 | * |
| 6785 | */ |
| 6786 | @Override |
| 6787 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6789 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6791 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6792 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6793 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6794 | final long identity = Binder.clearCallingIdentity(); |
| 6795 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6796 | if (!isActiveSubscription(subId)) { |
| 6797 | return; |
| 6798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6799 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6800 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6801 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | } finally { |
| 6803 | Binder.restoreCallingIdentity(identity); |
| 6804 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6805 | } |
| 6806 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6807 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6808 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6809 | * |
| 6810 | * @param subId the id of the subscription. |
| 6811 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6812 | * the operator to attach to. |
| 6813 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6814 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6815 | * normal network selection next time. |
| 6816 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6817 | */ |
| 6818 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6819 | public boolean setNetworkSelectionModeManual( |
| 6820 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6822 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6823 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6824 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6825 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6826 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6827 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6828 | if (!isActiveSubscription(subId)) { |
| 6829 | return false; |
| 6830 | } |
| 6831 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6833 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6835 | if (DBG) { |
| 6836 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6837 | + " operator: " + operatorInfo); |
| 6838 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6843 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6844 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6845 | * Get the manual network selection |
| 6846 | * |
| 6847 | * @param subId the id of the subscription. |
| 6848 | * |
| 6849 | * @return the previously saved user selected PLMN |
| 6850 | */ |
| 6851 | @Override |
| 6852 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6853 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6854 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6855 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6856 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6857 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6858 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6859 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6860 | final long identity = Binder.clearCallingIdentity(); |
| 6861 | try { |
| 6862 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6863 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | final Phone phone = getPhone(subId); |
| 6867 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6868 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6869 | } |
| 6870 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6871 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6872 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6873 | } finally { |
| 6874 | Binder.restoreCallingIdentity(identity); |
| 6875 | } |
| 6876 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6877 | |
| 6878 | /** |
| 6879 | * Scans for available networks. |
| 6880 | */ |
| 6881 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6882 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6883 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6885 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6886 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6887 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6888 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6889 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6890 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6891 | .setCallingPid(Binder.getCallingPid()) |
| 6892 | .setCallingUid(Binder.getCallingUid()) |
| 6893 | .setMethod("getCellNetworkScanResults") |
| 6894 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6895 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6896 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6897 | .build()); |
| 6898 | switch (locationResult) { |
| 6899 | case DENIED_HARD: |
| 6900 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6901 | case DENIED_SOFT: |
| 6902 | return null; |
| 6903 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6905 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | try { |
| 6907 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6908 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6909 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | } finally { |
| 6911 | Binder.restoreCallingIdentity(identity); |
| 6912 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6916 | * Get the call forwarding info, given the call forwarding reason. |
| 6917 | */ |
| 6918 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6919 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6920 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6921 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6922 | |
| 6923 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6924 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6925 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6926 | long identity = Binder.clearCallingIdentity(); |
| 6927 | try { |
| 6928 | if (DBG) { |
| 6929 | log("getCallForwarding: subId " + subId |
| 6930 | + " callForwardingReason" + callForwardingReason); |
| 6931 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6932 | |
| 6933 | Phone phone = getPhone(subId); |
| 6934 | if (phone == null) { |
| 6935 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6936 | callback.onError( |
| 6937 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6938 | } catch (RemoteException e) { |
| 6939 | // ignore |
| 6940 | } |
| 6941 | return; |
| 6942 | } |
| 6943 | |
| 6944 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6945 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6946 | @Override |
| 6947 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6948 | try { |
| 6949 | callback.onCallForwardingInfoAvailable(info); |
| 6950 | } catch (RemoteException e) { |
| 6951 | // ignore |
| 6952 | } |
| 6953 | } |
| 6954 | |
| 6955 | @Override |
| 6956 | public void onError(int error) { |
| 6957 | try { |
| 6958 | callback.onError(error); |
| 6959 | } catch (RemoteException e) { |
| 6960 | // ignore |
| 6961 | } |
| 6962 | } |
| 6963 | }); |
| 6964 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6965 | } finally { |
| 6966 | Binder.restoreCallingIdentity(identity); |
| 6967 | } |
| 6968 | } |
| 6969 | |
| 6970 | /** |
| 6971 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6972 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6973 | */ |
| 6974 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6975 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6976 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6977 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6978 | |
| 6979 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6980 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6981 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6982 | long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
| 6984 | if (DBG) { |
| 6985 | log("setCallForwarding: subId " + subId |
| 6986 | + " callForwardingInfo" + callForwardingInfo); |
| 6987 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6988 | |
| 6989 | Phone phone = getPhone(subId); |
| 6990 | if (phone == null) { |
| 6991 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6992 | callback.accept( |
| 6993 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6994 | } catch (RemoteException e) { |
| 6995 | // ignore |
| 6996 | } |
| 6997 | return; |
| 6998 | } |
| 6999 | |
| 7000 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7001 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7002 | |
| 7003 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7004 | } finally { |
| 7005 | Binder.restoreCallingIdentity(identity); |
| 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7010 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7011 | */ |
| 7012 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7013 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7014 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7015 | |
| 7016 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7017 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7018 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7019 | long identity = Binder.clearCallingIdentity(); |
| 7020 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7021 | Phone phone = getPhone(subId); |
| 7022 | if (phone == null) { |
| 7023 | try { |
| 7024 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7025 | } catch (RemoteException e) { |
| 7026 | // ignore |
| 7027 | } |
| 7028 | return; |
| 7029 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7030 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7031 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7032 | boolean requireUssd = c.getBoolean( |
| 7033 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7034 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7035 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7036 | if (requireUssd) { |
| 7037 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7038 | getSubscriptionCarrierId(subId)); |
| 7039 | String newUssdCommand = ""; |
| 7040 | try { |
| 7041 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7042 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7043 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7044 | } catch (NullPointerException e) { |
| 7045 | loge("Failed to generate USSD number" + e); |
| 7046 | } |
| 7047 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7048 | mMainThreadHandler, callback, carrierXmlParser, |
| 7049 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7050 | final String ussdCommand = newUssdCommand; |
| 7051 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7052 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7053 | }); |
| 7054 | } else { |
| 7055 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7056 | callback::accept); |
| 7057 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7058 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
| 7062 | } |
| 7063 | |
| 7064 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7065 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7066 | */ |
| 7067 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7068 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7069 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7070 | |
| 7071 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7072 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7073 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7074 | long identity = Binder.clearCallingIdentity(); |
| 7075 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7076 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7077 | |
| 7078 | Phone phone = getPhone(subId); |
| 7079 | if (phone == null) { |
| 7080 | try { |
| 7081 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7082 | } catch (RemoteException e) { |
| 7083 | // ignore |
| 7084 | } |
| 7085 | return; |
| 7086 | } |
| 7087 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7088 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7089 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7090 | boolean requireUssd = c.getBoolean( |
| 7091 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7092 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7093 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7094 | if (requireUssd) { |
| 7095 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7096 | getSubscriptionCarrierId(subId)); |
| 7097 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7098 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7099 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7100 | String newUssdCommand = ""; |
| 7101 | try { |
| 7102 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7103 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7104 | .makeCommand(ssAction, null); |
| 7105 | } catch (NullPointerException e) { |
| 7106 | loge("Failed to generate USSD number" + e); |
| 7107 | } |
| 7108 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7109 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7110 | final String ussdCommand = newUssdCommand; |
| 7111 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7112 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7113 | }); |
| 7114 | } else { |
| 7115 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7116 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7117 | |
| 7118 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7119 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
| 7123 | } |
| 7124 | |
| 7125 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7126 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7127 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7128 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7129 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7130 | * location related information which will be sent if the caller already possess |
| 7131 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7132 | * @param request contains the radio access networks with bands/channels to scan |
| 7133 | * @param messenger callback messenger for scan results or errors |
| 7134 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7135 | * @return the id of the requested scan which can be used to stop the scan. |
| 7136 | */ |
| 7137 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7138 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7139 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7140 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7142 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7143 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7144 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7145 | if (!renounceFineLocationAccess) { |
| 7146 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7147 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7148 | .setCallingPackage(callingPackage) |
| 7149 | .setCallingFeatureId(callingFeatureId) |
| 7150 | .setCallingPid(Binder.getCallingPid()) |
| 7151 | .setCallingUid(Binder.getCallingUid()) |
| 7152 | .setMethod("requestNetworkScan") |
| 7153 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7154 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7155 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7156 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7157 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7158 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7159 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7160 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7161 | if (e != null) { |
| 7162 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7163 | throw e; |
| 7164 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7165 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7166 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7167 | } |
| 7168 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7169 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7170 | |
| 7171 | enforceTelephonyFeatureWithException(callingPackage, |
| 7172 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7173 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7174 | int callingUid = Binder.getCallingUid(); |
| 7175 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7176 | final long identity = Binder.clearCallingIdentity(); |
| 7177 | try { |
| 7178 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7179 | renounceFineLocationAccess, request, messenger, binder, |
| 7180 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7181 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7182 | } finally { |
| 7183 | Binder.restoreCallingIdentity(identity); |
| 7184 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7185 | } |
| 7186 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7187 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7188 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7189 | boolean hasCarrierPriv; |
| 7190 | final long identity = Binder.clearCallingIdentity(); |
| 7191 | try { |
| 7192 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7193 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7194 | } finally { |
| 7195 | Binder.restoreCallingIdentity(identity); |
| 7196 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7197 | boolean hasNetworkScanPermission = |
| 7198 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7199 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7200 | |
| 7201 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7202 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7203 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7207 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7208 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7209 | return new SecurityException("Specific channels must not be" |
| 7210 | + " scanned without location access."); |
| 7211 | } |
| 7212 | } |
| 7213 | } |
| 7214 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7215 | return null; |
| 7216 | } |
| 7217 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7218 | /** |
| 7219 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7220 | * |
| 7221 | * @param subId id of the subscription |
| 7222 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7223 | */ |
| 7224 | @Override |
| 7225 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7226 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7227 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7229 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | final long identity = Binder.clearCallingIdentity(); |
| 7231 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7232 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | } finally { |
| 7234 | Binder.restoreCallingIdentity(identity); |
| 7235 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7239 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7240 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7241 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7242 | */ |
| 7243 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7244 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7245 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7246 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7247 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7248 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7249 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7250 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | final long identity = Binder.clearCallingIdentity(); |
| 7253 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7254 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7255 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7256 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7257 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7258 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7265 | * Get the allowed network types for certain reason. |
| 7266 | * |
| 7267 | * @param subId the id of the subscription. |
| 7268 | * @param reason the reason the allowed network type change is taking place |
| 7269 | * @return the allowed network types. |
| 7270 | */ |
| 7271 | @Override |
| 7272 | public long getAllowedNetworkTypesForReason(int subId, |
| 7273 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7274 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7275 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7276 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7277 | if (!mApp.getResources().getBoolean( |
| 7278 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7279 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7280 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7281 | "getAllowedNetworkTypesForReason"); |
| 7282 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7283 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7284 | final long identity = Binder.clearCallingIdentity(); |
| 7285 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7286 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
| 7289 | } |
| 7290 | } |
| 7291 | |
| 7292 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7293 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7294 | * @param subId subscription id of the sim card |
| 7295 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7296 | * This can be passed following states |
| 7297 | * <ol> |
| 7298 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7299 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7300 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7301 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7302 | * </ol> |
| 7303 | * @return operation result. |
| 7304 | */ |
| 7305 | @Override |
| 7306 | public int setNrDualConnectivityState(int subId, |
| 7307 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7309 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7310 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7311 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7312 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7313 | } |
| 7314 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7315 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7316 | final long identity = Binder.clearCallingIdentity(); |
| 7317 | try { |
| 7318 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7319 | nrDualConnectivityState, subId, |
| 7320 | workSource); |
| 7321 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7322 | return result; |
| 7323 | } finally { |
| 7324 | Binder.restoreCallingIdentity(identity); |
| 7325 | } |
| 7326 | } |
| 7327 | |
| 7328 | /** |
| 7329 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7330 | * @return true if dual connectivity is enabled else false |
| 7331 | */ |
| 7332 | @Override |
| 7333 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7334 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7335 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7336 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7337 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7338 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7339 | return false; |
| 7340 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7341 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7342 | final long identity = Binder.clearCallingIdentity(); |
| 7343 | try { |
| 7344 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7345 | null, subId, workSource); |
| 7346 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7347 | return isEnabled; |
| 7348 | } finally { |
| 7349 | Binder.restoreCallingIdentity(identity); |
| 7350 | } |
| 7351 | } |
| 7352 | |
| 7353 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7354 | * Set the allowed network types of the device and |
| 7355 | * provide the reason triggering the allowed network change. |
| 7356 | * |
| 7357 | * @param subId the id of the subscription. |
| 7358 | * @param reason the reason the allowed network type change is taking place |
| 7359 | * @param allowedNetworkTypes the allowed network types. |
| 7360 | * @return true on success; false on any failure. |
| 7361 | */ |
| 7362 | @Override |
| 7363 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7364 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7365 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7367 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7368 | // If the caller only has carrier privileges, then they should not be able to override |
| 7369 | // any network types which were set for security reasons. |
| 7370 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7371 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7372 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7373 | throw new SecurityException( |
| 7374 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7375 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7376 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7377 | |
| 7378 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7379 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7380 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7381 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7382 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7383 | return false; |
| 7384 | } |
| 7385 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7386 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7387 | return false; |
| 7388 | } |
| 7389 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7390 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7391 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7392 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7393 | Phone phone = getPhone(subId); |
| 7394 | if (phone == null) { |
| 7395 | return false; |
| 7396 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7397 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7398 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7399 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7400 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7401 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7402 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7403 | final long identity = Binder.clearCallingIdentity(); |
| 7404 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7405 | Boolean success = (Boolean) sendRequest( |
| 7406 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7407 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7408 | |
| 7409 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7410 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7411 | } finally { |
| 7412 | Binder.restoreCallingIdentity(identity); |
| 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7417 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7418 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7419 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7420 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7421 | * @hide |
| 7422 | */ |
| 7423 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7424 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7425 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7426 | |
| 7427 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7428 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7429 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7430 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7431 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7433 | if (phone != null) { |
| 7434 | return phone.hasMatchedTetherApnSetting(); |
| 7435 | } else { |
| 7436 | return false; |
| 7437 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | } finally { |
| 7439 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7440 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7441 | } |
| 7442 | |
| 7443 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7444 | * Get the user enabled state of Mobile Data. |
| 7445 | * |
| 7446 | * TODO: remove and use isUserDataEnabled. |
| 7447 | * This can't be removed now because some vendor codes |
| 7448 | * calls through ITelephony directly while they should |
| 7449 | * use TelephonyManager. |
| 7450 | * |
| 7451 | * @return true on enabled |
| 7452 | */ |
| 7453 | @Override |
| 7454 | public boolean getDataEnabled(int subId) { |
| 7455 | return isUserDataEnabled(subId); |
| 7456 | } |
| 7457 | |
| 7458 | /** |
| 7459 | * Get whether mobile data is enabled per user setting. |
| 7460 | * |
| 7461 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7462 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7463 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7464 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7465 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7466 | * |
| 7467 | * @return {@code true} if data is enabled else {@code false} |
| 7468 | */ |
| 7469 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7470 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7471 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7472 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7473 | try { |
| 7474 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7475 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7476 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7477 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7478 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7479 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7480 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7481 | mApp, subId, functionName); |
| 7482 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7483 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | |
| 7485 | final long identity = Binder.clearCallingIdentity(); |
| 7486 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7487 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7489 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7490 | if (phone != null) { |
| 7491 | boolean retVal = phone.isUserDataEnabled(); |
| 7492 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7493 | return retVal; |
| 7494 | } else { |
| 7495 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7496 | return false; |
| 7497 | } |
| 7498 | } finally { |
| 7499 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7500 | } |
| 7501 | } |
| 7502 | |
| 7503 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7504 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7505 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7506 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7507 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7508 | * @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] | 7509 | */ |
| 7510 | @Override |
| 7511 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7512 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7513 | try { |
| 7514 | try { |
| 7515 | mApp.enforceCallingOrSelfPermission( |
| 7516 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7517 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7518 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7519 | try { |
| 7520 | mApp.enforceCallingOrSelfPermission( |
| 7521 | android.Manifest.permission.READ_PHONE_STATE, |
| 7522 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7523 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7524 | mApp.enforceCallingOrSelfPermission( |
| 7525 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7526 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7527 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7528 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7529 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7530 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7532 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7533 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7537 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7539 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7540 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7541 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | return retVal; |
| 7543 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7544 | if (DBG) { |
| 7545 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7546 | + subId + " retVal=false"); |
| 7547 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | return false; |
| 7549 | } |
| 7550 | } finally { |
| 7551 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7552 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7553 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7554 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7555 | /** |
| 7556 | * Check if data is enabled for a specific reason |
| 7557 | * @param subId Subscription index |
| 7558 | * @param reason the reason the data enable change is taking place |
| 7559 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7560 | */ |
| 7561 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7562 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7563 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7564 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7565 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7566 | try { |
| 7567 | mApp.enforceCallingOrSelfPermission( |
| 7568 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7569 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7570 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7571 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7572 | functionName); |
| 7573 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7574 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7575 | try { |
| 7576 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7577 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7578 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7580 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7581 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7582 | } |
| 7583 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame^] | 7584 | if (!mApp.getResources().getBoolean( |
| 7585 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7586 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7587 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7588 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7589 | |
| 7590 | final long identity = Binder.clearCallingIdentity(); |
| 7591 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7592 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7593 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7594 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7595 | + " reason=" + reason); |
| 7596 | } |
| 7597 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7598 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7599 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7600 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7601 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7602 | return retVal; |
| 7603 | } else { |
| 7604 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7605 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7606 | + subId + " retVal=false"); |
| 7607 | } |
| 7608 | return false; |
| 7609 | } |
| 7610 | } finally { |
| 7611 | Binder.restoreCallingIdentity(identity); |
| 7612 | } |
| 7613 | } |
| 7614 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7615 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7616 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7617 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7618 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7619 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7620 | // No permission needed; this only lets the caller inspect their own status. |
| 7621 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7622 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7623 | |
| 7624 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7625 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7626 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7627 | |
| 7628 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7629 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7630 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7631 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7632 | } |
| 7633 | |
| 7634 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7635 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7636 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7637 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7638 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7639 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7640 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7641 | if (cpt == null) { |
| 7642 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7643 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7644 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7645 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7649 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7650 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7651 | |
| 7652 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7653 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7654 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7655 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7656 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7657 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7658 | Phone phone = getPhone(subId); |
| 7659 | if (phone == null) { |
| 7660 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7661 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7662 | } |
| 7663 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7664 | if (cpt == null) { |
| 7665 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7666 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7667 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7668 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7669 | } |
| 7670 | |
| 7671 | @Override |
| 7672 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7673 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7674 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame^] | 7675 | if (!mApp.getResources().getBoolean( |
| 7676 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7677 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7678 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7679 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7680 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7681 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7682 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7683 | } |
| 7684 | |
| 7685 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7686 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7687 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7688 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7689 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7690 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7691 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7692 | if (phone == null) { |
| 7693 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7694 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7695 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7696 | if (cpt == null) { |
| 7697 | continue; |
| 7698 | } |
| 7699 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7700 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7701 | break; |
| 7702 | } |
| 7703 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7704 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7705 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7706 | |
| 7707 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7708 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7709 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7710 | |
| 7711 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7712 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7713 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7714 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7715 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7716 | if (phone == null) { |
| 7717 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7718 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7719 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7720 | if (cpt == null) { |
| 7721 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7722 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7723 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7724 | } |
| 7725 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7726 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7727 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7728 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7729 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7730 | if (phone == null) { |
| 7731 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7732 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7733 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7734 | if (cpt == null) { |
| 7735 | return Collections.emptyList(); |
| 7736 | } |
| 7737 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7738 | } |
| 7739 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7740 | @Override |
| 7741 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7742 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7743 | |
| 7744 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7745 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7746 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7747 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7748 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7749 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7750 | try { |
| 7751 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7752 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7753 | } |
| 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7756 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7757 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7758 | } |
| 7759 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7760 | @Override |
| 7761 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7762 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7763 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7764 | if (!mApp.getResources().getBoolean( |
| 7765 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7766 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7767 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7768 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7769 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7770 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7771 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7772 | if (phone == null) { |
| 7773 | return null; |
| 7774 | } |
| 7775 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7776 | if (cpt == null) { |
| 7777 | return null; |
| 7778 | } |
| 7779 | return cpt.getCarrierServicePackageName(); |
| 7780 | } |
| 7781 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7782 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7783 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7784 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7785 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7786 | return null; |
| 7787 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7788 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7789 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7790 | return null; |
| 7791 | } |
| 7792 | return iccId; |
| 7793 | } |
| 7794 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7795 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7796 | public void setCallComposerStatus(int subId, int status) { |
| 7797 | enforceModifyPermission(); |
| 7798 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7799 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7800 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7801 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7802 | final long identity = Binder.clearCallingIdentity(); |
| 7803 | try { |
| 7804 | Phone phone = getPhone(subId); |
| 7805 | if (phone != null) { |
| 7806 | Phone defaultPhone = phone.getImsPhone(); |
| 7807 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7808 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7809 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7810 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7811 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7812 | } |
| 7813 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7814 | } catch (ImsException e) { |
| 7815 | throw new ServiceSpecificException(e.getCode()); |
| 7816 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7817 | Binder.restoreCallingIdentity(identity); |
| 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | @Override |
| 7822 | public int getCallComposerStatus(int subId) { |
| 7823 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7824 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7825 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7826 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7827 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7828 | final long identity = Binder.clearCallingIdentity(); |
| 7829 | try { |
| 7830 | Phone phone = getPhone(subId); |
| 7831 | if (phone != null) { |
| 7832 | Phone defaultPhone = phone.getImsPhone(); |
| 7833 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7834 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7835 | return imsPhone.getCallComposerStatus(); |
| 7836 | } |
| 7837 | } |
| 7838 | } finally { |
| 7839 | Binder.restoreCallingIdentity(identity); |
| 7840 | } |
| 7841 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7842 | } |
| 7843 | |
| 7844 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7845 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7846 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7847 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7848 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7849 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7850 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7851 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7852 | "setLine1NumberForDisplayForSubscriber"); |
| 7853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | final long identity = Binder.clearCallingIdentity(); |
| 7855 | try { |
| 7856 | final String iccId = getIccId(subId); |
| 7857 | final Phone phone = getPhone(subId); |
| 7858 | if (phone == null) { |
| 7859 | return false; |
| 7860 | } |
| 7861 | final String subscriberId = phone.getSubscriberId(); |
| 7862 | |
| 7863 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7864 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | + subscriberId + " to " + number); |
| 7866 | } |
| 7867 | |
| 7868 | if (TextUtils.isEmpty(iccId)) { |
| 7869 | return false; |
| 7870 | } |
| 7871 | |
| 7872 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7873 | |
| 7874 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7875 | if (alphaTag == null) { |
| 7876 | editor.remove(alphaTagPrefKey); |
| 7877 | } else { |
| 7878 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7879 | } |
| 7880 | |
| 7881 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7882 | // track all merged IMSIs based on line number |
| 7883 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7884 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7885 | if (number == null) { |
| 7886 | editor.remove(numberPrefKey); |
| 7887 | editor.remove(subscriberPrefKey); |
| 7888 | } else { |
| 7889 | editor.putString(numberPrefKey, number); |
| 7890 | editor.putString(subscriberPrefKey, subscriberId); |
| 7891 | } |
| 7892 | |
| 7893 | editor.commit(); |
| 7894 | return true; |
| 7895 | } finally { |
| 7896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7897 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7901 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7902 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7903 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7904 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7905 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7906 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7907 | return null; |
| 7908 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7909 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7910 | enforceTelephonyFeatureWithException(callingPackage, |
| 7911 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 | final long identity = Binder.clearCallingIdentity(); |
| 7914 | try { |
| 7915 | String iccId = getIccId(subId); |
| 7916 | if (iccId != null) { |
| 7917 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7918 | if (DBG_MERGE) { |
| 7919 | log("getLine1NumberForDisplay returning " |
| 7920 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7921 | } |
| 7922 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7923 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7924 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7925 | return null; |
| 7926 | } finally { |
| 7927 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7928 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7929 | } |
| 7930 | |
| 7931 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7932 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7933 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7934 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7935 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7936 | return null; |
| 7937 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7938 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7939 | final long identity = Binder.clearCallingIdentity(); |
| 7940 | try { |
| 7941 | String iccId = getIccId(subId); |
| 7942 | if (iccId != null) { |
| 7943 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7944 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7945 | } |
| 7946 | return null; |
| 7947 | } finally { |
| 7948 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7949 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7950 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7951 | |
| 7952 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7953 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7954 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7955 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7956 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7957 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7958 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7959 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7960 | return null; |
| 7961 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7962 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7963 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7964 | // the process, where TelephonyManager was instantiated. |
| 7965 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7966 | final long identity = Binder.clearCallingIdentity(); |
| 7967 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7968 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7969 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7970 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7971 | |
| 7972 | // Figure out what subscribers are currently active |
| 7973 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7974 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7975 | // Only consider subs which match the current subId |
| 7976 | // This logic can be simplified. See b/131189269 for progress. |
| 7977 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7978 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7979 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7980 | |
| 7981 | // First pass, find a number override for an active subscriber |
| 7982 | String mergeNumber = null; |
| 7983 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7984 | for (String key : prefs.keySet()) { |
| 7985 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7986 | final String subscriberId = (String) prefs.get(key); |
| 7987 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7988 | final String iccId = key.substring( |
| 7989 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7990 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7991 | mergeNumber = (String) prefs.get(numberKey); |
| 7992 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7993 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7994 | + " for active subscriber " + subscriberId); |
| 7995 | } |
| 7996 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7997 | break; |
| 7998 | } |
| 7999 | } |
| 8000 | } |
| 8001 | } |
| 8002 | |
| 8003 | // Shortcut when no active merged subscribers |
| 8004 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8005 | return null; |
| 8006 | } |
| 8007 | |
| 8008 | // Second pass, find all subscribers under that line override |
| 8009 | final ArraySet<String> result = new ArraySet<>(); |
| 8010 | for (String key : prefs.keySet()) { |
| 8011 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8012 | final String number = (String) prefs.get(key); |
| 8013 | if (mergeNumber.equals(number)) { |
| 8014 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8015 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8016 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8017 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8018 | result.add(subscriberId); |
| 8019 | } |
| 8020 | } |
| 8021 | } |
| 8022 | } |
| 8023 | |
| 8024 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8025 | Arrays.sort(resultArray); |
| 8026 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8027 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8028 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8029 | } |
| 8030 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8031 | } finally { |
| 8032 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8033 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8037 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8038 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8039 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8040 | enforceTelephonyFeatureWithException(callingPackage, |
| 8041 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8042 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8043 | final long identity = Binder.clearCallingIdentity(); |
| 8044 | try { |
| 8045 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8046 | TelephonyManager.class); |
| 8047 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8048 | if (subscriberId == null) { |
| 8049 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8050 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8051 | + subId); |
| 8052 | } |
| 8053 | return null; |
| 8054 | } |
| 8055 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8056 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8057 | .getSubscriptionInfo(subId); |
| 8058 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8059 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8060 | if (groupUuid == null) { |
| 8061 | return new String[]{subscriberId}; |
| 8062 | } |
| 8063 | |
| 8064 | // Get all subscriberIds from the group. |
| 8065 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8066 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8067 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8068 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8069 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8070 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8071 | if (subscriberId != null) { |
| 8072 | mergedSubscriberIds.add(subscriberId); |
| 8073 | } |
| 8074 | } |
| 8075 | |
| 8076 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8077 | } finally { |
| 8078 | Binder.restoreCallingIdentity(identity); |
| 8079 | |
| 8080 | } |
| 8081 | } |
| 8082 | |
| 8083 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8084 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8085 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8086 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8088 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8089 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | final long identity = Binder.clearCallingIdentity(); |
| 8092 | try { |
| 8093 | final Phone phone = getPhone(subId); |
| 8094 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8095 | } finally { |
| 8096 | Binder.restoreCallingIdentity(identity); |
| 8097 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8098 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8099 | |
| 8100 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8101 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8102 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8103 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8104 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8105 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | |
| 8107 | final long identity = Binder.clearCallingIdentity(); |
| 8108 | try { |
| 8109 | final Phone phone = getPhone(subId); |
| 8110 | if (phone == null) { |
| 8111 | return false; |
| 8112 | } |
| 8113 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8114 | cdmaNonRoamingList); |
| 8115 | } finally { |
| 8116 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8117 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8121 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8122 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8123 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8124 | if (phone == null) { |
| 8125 | return raf; |
| 8126 | } |
| 8127 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8128 | try { |
| 8129 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8130 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8131 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8132 | } catch (SecurityException e) { |
| 8133 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8134 | throw e; |
| 8135 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8136 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8137 | if (!mApp.getResources().getBoolean( |
| 8138 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8139 | enforceTelephonyFeatureWithException(callingPackage, |
| 8140 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8141 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | final long identity = Binder.clearCallingIdentity(); |
| 8144 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8145 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8146 | } finally { |
| 8147 | Binder.restoreCallingIdentity(identity); |
| 8148 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8149 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8150 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8151 | |
| 8152 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8153 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8154 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8155 | if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) { |
| 8156 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8157 | "Invalid package:" + callingPackage); |
| 8158 | } else { |
| 8159 | try { |
| 8160 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8161 | Binder.getCallingUid())) { |
| 8162 | throw new SecurityException("Invalid package:" + callingPackage); |
| 8163 | } |
| 8164 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8165 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8166 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8167 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8168 | |
| 8169 | enforceTelephonyFeatureWithException(callingPackage, |
| 8170 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8171 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8172 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8173 | List<String> dialerRoleHolders; |
| 8174 | if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) { |
| 8175 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8176 | UserHandle.of(ActivityManager.getCurrentUser())); |
| 8177 | } else { |
| 8178 | dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8179 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8180 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8181 | throw new SecurityException("App must be the dialer role holder to" |
| 8182 | + " upload a call composer pic"); |
| 8183 | } |
| 8184 | |
| 8185 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8186 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8187 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8188 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8189 | boolean readUntilEnd = false; |
| 8190 | int totalBytesRead = 0; |
| 8191 | byte[] buffer = new byte[16 * 1024]; |
| 8192 | while (true) { |
| 8193 | int numRead; |
| 8194 | try { |
| 8195 | numRead = input.read(buffer); |
| 8196 | } catch (IOException e) { |
| 8197 | try { |
| 8198 | fd.checkError(); |
| 8199 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8200 | null); |
| 8201 | } catch (IOException e1) { |
| 8202 | // This means that the other side closed explicitly with an error. If this |
| 8203 | // happens, log and ignore. |
| 8204 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8205 | } |
| 8206 | break; |
| 8207 | } |
| 8208 | if (numRead == -1) { |
| 8209 | readUntilEnd = true; |
| 8210 | break; |
| 8211 | } |
| 8212 | totalBytesRead += numRead; |
| 8213 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8214 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8215 | try { |
| 8216 | input.close(); |
| 8217 | } catch (IOException e) { |
| 8218 | // ignore |
| 8219 | } |
| 8220 | break; |
| 8221 | } |
| 8222 | output.write(buffer, 0, numRead); |
| 8223 | } |
| 8224 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8225 | // close is above, where the picture size is too big. |
| 8226 | |
| 8227 | try { |
| 8228 | fd.checkError(); |
| 8229 | } catch (IOException e) { |
| 8230 | loge("Remote end for call composer closed with an error: " + e); |
| 8231 | return; |
| 8232 | } |
| 8233 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8234 | if (!readUntilEnd) { |
| 8235 | loge("Did not finish reading entire image; aborting"); |
| 8236 | return; |
| 8237 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8238 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8239 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8240 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8241 | new CallComposerPictureTransfer.Factory() {}, |
| 8242 | imageData, |
| 8243 | (result) -> { |
| 8244 | if (result.first != null) { |
| 8245 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8246 | Bundle outputResult = new Bundle(); |
| 8247 | outputResult.putParcelable( |
| 8248 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8249 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8250 | outputResult); |
| 8251 | } else { |
| 8252 | callback.send(result.second, null); |
| 8253 | } |
| 8254 | } |
| 8255 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8256 | }); |
| 8257 | } |
| 8258 | |
| 8259 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8260 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8261 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8262 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8263 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8264 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8265 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8266 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | final long identity = Binder.clearCallingIdentity(); |
| 8268 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8269 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8270 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8271 | } finally { |
| 8272 | Binder.restoreCallingIdentity(identity); |
| 8273 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8274 | } |
| 8275 | |
| 8276 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8277 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8278 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8280 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8281 | return false; |
| 8282 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8283 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8284 | enforceTelephonyFeatureWithException(callingPackage, |
| 8285 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8290 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8291 | // In the long run, we may instead need to check if there exists a connection service |
| 8292 | // which can support video calling. |
| 8293 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8294 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8295 | return imsManager.isVtEnabledByPlatform() |
| 8296 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8297 | && imsManager.isVtEnabledByUser(); |
| 8298 | } finally { |
| 8299 | Binder.restoreCallingIdentity(identity); |
| 8300 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8301 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8302 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8303 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8304 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8305 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8307 | mApp, subId, callingPackage, callingFeatureId, |
| 8308 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | return false; |
| 8310 | } |
| 8311 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8312 | enforceTelephonyFeatureWithException(callingPackage, |
| 8313 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8314 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | final long identity = Binder.clearCallingIdentity(); |
| 8316 | try { |
| 8317 | CarrierConfigManager configManager = |
| 8318 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8319 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8320 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8321 | } finally { |
| 8322 | Binder.restoreCallingIdentity(identity); |
| 8323 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8327 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8328 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8329 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | return false; |
| 8331 | } |
| 8332 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8333 | enforceTelephonyFeatureWithException(callingPackage, |
| 8334 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | final long identity = Binder.clearCallingIdentity(); |
| 8337 | try { |
| 8338 | CarrierConfigManager configManager = |
| 8339 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8340 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
| 8344 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8345 | } |
| 8346 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8347 | @Override |
| 8348 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8349 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8350 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8351 | } |
| 8352 | |
| 8353 | @Override |
| 8354 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8355 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8356 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8358 | final long identity = Binder.clearCallingIdentity(); |
| 8359 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8360 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8361 | } finally { |
| 8362 | Binder.restoreCallingIdentity(identity); |
| 8363 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8364 | } |
| 8365 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8366 | /** |
| 8367 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8368 | * support for the feature and device firmware support. |
| 8369 | * |
| 8370 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8371 | */ |
| 8372 | @Override |
| 8373 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8374 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8375 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8376 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8378 | final Phone phone = getPhone(subscriptionId); |
| 8379 | if (phone == null) { |
| 8380 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8381 | return false; |
| 8382 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8384 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8386 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8387 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8388 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | return isCarrierSupported && isDeviceSupported; |
| 8390 | } finally { |
| 8391 | Binder.restoreCallingIdentity(identity); |
| 8392 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8393 | } |
| 8394 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8395 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8396 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8397 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8398 | * 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] | 8399 | */ |
| 8400 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | final long identity = Binder.clearCallingIdentity(); |
| 8402 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8403 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8404 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8405 | return false; |
| 8406 | } |
| 8407 | } |
| 8408 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8409 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8410 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8411 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8412 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8413 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8414 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8415 | } finally { |
| 8416 | Binder.restoreCallingIdentity(identity); |
| 8417 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8418 | } |
| 8419 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8420 | @Deprecated |
| 8421 | @Override |
| 8422 | public String getDeviceId(String callingPackage) { |
| 8423 | return getDeviceIdWithFeature(callingPackage, null); |
| 8424 | } |
| 8425 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8426 | /** |
| 8427 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8428 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8429 | * |
| 8430 | * <p>Requires Permission: |
| 8431 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8432 | */ |
| 8433 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8434 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8435 | try { |
| 8436 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8437 | } catch (SecurityException se) { |
| 8438 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8439 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8440 | + Binder.getCallingUid()); |
| 8441 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8442 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8443 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8444 | return null; |
| 8445 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8446 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8447 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8448 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8449 | return null; |
| 8450 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8451 | |
| 8452 | final long identity = Binder.clearCallingIdentity(); |
| 8453 | try { |
| 8454 | return phone.getDeviceId(); |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
| 8457 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8458 | } |
| 8459 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8460 | /** |
| 8461 | * {@hide} |
| 8462 | * Returns the IMS Registration Status on a particular subid |
| 8463 | * |
| 8464 | * @param subId |
| 8465 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8466 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8467 | Phone phone = getPhone(subId); |
| 8468 | if (phone != null) { |
| 8469 | return phone.isImsRegistered(); |
| 8470 | } else { |
| 8471 | return false; |
| 8472 | } |
| 8473 | } |
| 8474 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8475 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8476 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8477 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8479 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8480 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8481 | } |
| 8482 | final long identity = Binder.clearCallingIdentity(); |
| 8483 | try { |
| 8484 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
| 8487 | } |
| 8488 | } |
| 8489 | |
| 8490 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8491 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8492 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8493 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8494 | mApp, |
| 8495 | subscriptionId, |
| 8496 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8497 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8498 | |
| 8499 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8500 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8501 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8502 | final long identity = Binder.clearCallingIdentity(); |
| 8503 | try { |
| 8504 | Phone phone = getPhone(subscriptionId); |
| 8505 | if (phone == null) { |
| 8506 | return null; |
| 8507 | } |
| 8508 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8509 | } finally { |
| 8510 | Binder.restoreCallingIdentity(identity); |
| 8511 | } |
| 8512 | } |
| 8513 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8514 | /** |
| 8515 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8516 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8517 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8518 | final long identity = Binder.clearCallingIdentity(); |
| 8519 | try { |
| 8520 | Phone phone = getPhone(subId); |
| 8521 | if (phone != null) { |
| 8522 | return phone.isWifiCallingEnabled(); |
| 8523 | } else { |
| 8524 | return false; |
| 8525 | } |
| 8526 | } finally { |
| 8527 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8528 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8529 | } |
| 8530 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8531 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8532 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8533 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8534 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8535 | final long identity = Binder.clearCallingIdentity(); |
| 8536 | try { |
| 8537 | Phone phone = getPhone(subId); |
| 8538 | if (phone != null) { |
| 8539 | return phone.isVideoEnabled(); |
| 8540 | } else { |
| 8541 | return false; |
| 8542 | } |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | /** |
| 8549 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8550 | * defined in {@link ImsRegistrationImplBase}. |
| 8551 | */ |
| 8552 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
| 8555 | Phone phone = getPhone(subId); |
| 8556 | if (phone != null) { |
| 8557 | return phone.getImsRegistrationTech(); |
| 8558 | } else { |
| 8559 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8560 | } |
| 8561 | } finally { |
| 8562 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8563 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8564 | } |
| 8565 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8566 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8567 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8568 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8569 | |
| 8570 | enforceTelephonyFeatureWithException(callingPackage, |
| 8571 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8572 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8573 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8574 | return; |
| 8575 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8576 | Phone defaultPhone = getDefaultPhone(); |
| 8577 | if (defaultPhone != null) { |
| 8578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8579 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8580 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8581 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8582 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8583 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8584 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8585 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8586 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8587 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8588 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8589 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8590 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8591 | setDataRoamingEnabled(subId, phone == null ? false |
| 8592 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8593 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8594 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8595 | // There has been issues when Sms raw table somehow stores orphan |
| 8596 | // fragments. They lead to garbled message when new fragments come |
| 8597 | // in and combined with those stale ones. In case this happens again, |
| 8598 | // user can reset all network settings which will clean up this table. |
| 8599 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8600 | // Clean up IMS settings as well here. |
| 8601 | int slotId = getSlotIndex(subId); |
| 8602 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8603 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8604 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8605 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8606 | if (defaultPhone == null) { |
| 8607 | return; |
| 8608 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8609 | // Erase modem config if erase modem on network setting is enabled. |
| 8610 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8611 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8612 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8613 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8614 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8615 | |
| 8616 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8619 | } |
| 8620 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8621 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8622 | @VisibleForTesting |
| 8623 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8624 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8625 | return; |
| 8626 | } |
| 8627 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8628 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8629 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8630 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8631 | "user=" + defaultNetworkType); |
| 8632 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8633 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8634 | defaultNetworkType, null); |
| 8635 | } |
| 8636 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8637 | private void cleanUpSmsRawTable(Context context) { |
| 8638 | ContentResolver resolver = context.getContentResolver(); |
| 8639 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8640 | resolver.delete(uri, null, null); |
| 8641 | } |
| 8642 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8643 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8644 | public String getSimLocaleForSubscriber(int subId) { |
| 8645 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8646 | |
| 8647 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8648 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8649 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8650 | final Phone phone = getPhone(subId); |
| 8651 | if (phone == null) { |
| 8652 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8653 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8654 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8655 | final long identity = Binder.clearCallingIdentity(); |
| 8656 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8657 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8658 | phone.getContext().getOpPackageName(), |
| 8659 | phone.getContext().getAttributionTag()); |
| 8660 | if (info == null) { |
| 8661 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8662 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8664 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8665 | // preferences (EF-PL and EF-LI)... |
| 8666 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8667 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8668 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8669 | if (localeFromDefaultSim != null) { |
| 8670 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8671 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8672 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8673 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8674 | } else { |
| 8675 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8676 | } |
| 8677 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8679 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8680 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8681 | // the SIM and carrier preferences does not include a country we add the country |
| 8682 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8683 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8684 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8685 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8686 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8687 | } |
| 8688 | |
| 8689 | if (DBG) log("No locale found - returning null"); |
| 8690 | return null; |
| 8691 | } finally { |
| 8692 | Binder.restoreCallingIdentity(identity); |
| 8693 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8694 | } |
| 8695 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8696 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8697 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8698 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8699 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8700 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8701 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8702 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8703 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8704 | return localeTag; |
| 8705 | } |
| 8706 | } |
| 8707 | return inputLocale.toLanguageTag(); |
| 8708 | } |
| 8709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8710 | /** |
| 8711 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8712 | */ |
| 8713 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8714 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8715 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8716 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8717 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8718 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8719 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8720 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8721 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8722 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8723 | * representing the state of the modem. |
| 8724 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8725 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8726 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8727 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8728 | */ |
| 8729 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8730 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8731 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8732 | |
| 8733 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8734 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8735 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8736 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8737 | |
| 8738 | final long identity = Binder.clearCallingIdentity(); |
| 8739 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8740 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8741 | } finally { |
| 8742 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8743 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8744 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8745 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8746 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8747 | // less than total activity duration. |
| 8748 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8749 | if (info == null) { |
| 8750 | return false; |
| 8751 | } |
| 8752 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8753 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8754 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8755 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8756 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8757 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8758 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8759 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8760 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8761 | } |
| 8762 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8763 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8764 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8765 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8766 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8767 | |
| 8768 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8769 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8770 | } |
| 8771 | |
| 8772 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8773 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8774 | rat, |
| 8775 | freq, |
| 8776 | info.getReceiveTimeMillis(rat, freq) |
| 8777 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8778 | } |
| 8779 | |
| 8780 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8781 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8782 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8783 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8784 | |
| 8785 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8786 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8787 | } |
| 8788 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8789 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8790 | rat, |
| 8791 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8792 | } |
| 8793 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8794 | /** |
| 8795 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8796 | * @param info recent ModemActivityInfo |
| 8797 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8798 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8799 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8800 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8801 | boolean matched; |
| 8802 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8803 | matched = false; |
| 8804 | int rat = info.getSpecificInfoRat(i); |
| 8805 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8806 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8807 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8808 | //if it already exists |
| 8809 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8810 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8811 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8812 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8813 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8814 | updateLastModemActivityInfo(info, rat, freq); |
| 8815 | matched = true; |
| 8816 | } |
| 8817 | } else { |
| 8818 | updateLastModemActivityInfo(info, rat); |
| 8819 | matched = true; |
| 8820 | } |
| 8821 | } |
| 8822 | } |
| 8823 | |
| 8824 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8825 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8826 | new ActivityStatsTechSpecificInfo( |
| 8827 | rat, |
| 8828 | freq, |
| 8829 | info.getTransmitTimeMillis(rat, freq), |
| 8830 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8831 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8832 | } |
| 8833 | } |
| 8834 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8835 | mLastModemActivitySpecificInfo = |
| 8836 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8837 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8838 | |
| 8839 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8840 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8841 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8842 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8843 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8844 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8845 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8846 | |
| 8847 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8848 | new ModemActivityInfo( |
| 8849 | mLastModemActivityInfo.getTimestampMillis(), |
| 8850 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8851 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8852 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8853 | } |
| 8854 | |
| 8855 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8856 | ActivityStatsTechSpecificInfo[] info) { |
| 8857 | int infoSize = info.length; |
| 8858 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8859 | for (int i = 0; i < infoSize; i++) { |
| 8860 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8861 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8862 | info[i].getTransmitTimeMillis(), |
| 8863 | (int) info[i].getReceiveTimeMillis()); |
| 8864 | } |
| 8865 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8866 | } |
| 8867 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8868 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8869 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8870 | */ |
| 8871 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8872 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8873 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8874 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8875 | if (phone == null) { |
| 8876 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8877 | return null; |
| 8878 | } |
| 8879 | |
| 8880 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8881 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8882 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8883 | return null; |
| 8884 | } |
| 8885 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8886 | enforceTelephonyFeatureWithException(callingPackage, |
| 8887 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8888 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8889 | boolean hasFinePermission = false; |
| 8890 | boolean hasCoarsePermission = false; |
| 8891 | if (!renounceFineLocationAccess) { |
| 8892 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8893 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8894 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8895 | .setCallingPackage(callingPackage) |
| 8896 | .setCallingFeatureId(callingFeatureId) |
| 8897 | .setCallingPid(Binder.getCallingPid()) |
| 8898 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8899 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8900 | .setLogAsInfo(true) |
| 8901 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8902 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8903 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8904 | .build()); |
| 8905 | hasFinePermission = |
| 8906 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8907 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8908 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8909 | if (!renounceCoarseLocationAccess) { |
| 8910 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8911 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8912 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8913 | .setCallingPackage(callingPackage) |
| 8914 | .setCallingFeatureId(callingFeatureId) |
| 8915 | .setCallingPid(Binder.getCallingPid()) |
| 8916 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8917 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8918 | .setLogAsInfo(true) |
| 8919 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8920 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8921 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8922 | .build()); |
| 8923 | hasCoarsePermission = |
| 8924 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8925 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8926 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8927 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8928 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8929 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8930 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8931 | if (subInfo != null && !subInfo.isActive()) { |
| 8932 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8933 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8934 | } |
| 8935 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8936 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8937 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8938 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8939 | |
| 8940 | // Scrub out the location info in ServiceState depending on what level of access |
| 8941 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8942 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8943 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8944 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | } finally { |
| 8946 | Binder.restoreCallingIdentity(identity); |
| 8947 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8948 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8949 | |
| 8950 | /** |
| 8951 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8952 | * |
| 8953 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8954 | * voicemail ringtone. |
| 8955 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8956 | * PhoneAccount. |
| 8957 | */ |
| 8958 | @Override |
| 8959 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8960 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8961 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8963 | final long identity = Binder.clearCallingIdentity(); |
| 8964 | try { |
| 8965 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8966 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8967 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8968 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8970 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8971 | } finally { |
| 8972 | Binder.restoreCallingIdentity(identity); |
| 8973 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8974 | } |
| 8975 | |
| 8976 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8977 | * Sets the per-account voicemail ringtone. |
| 8978 | * |
| 8979 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8980 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8981 | * |
| 8982 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8983 | * voicemail ringtone. |
| 8984 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8985 | * PhoneAccount. |
| 8986 | */ |
| 8987 | @Override |
| 8988 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8989 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8990 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8991 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8992 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8993 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8995 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8996 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8998 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8999 | enforceTelephonyFeatureWithException(callingPackage, |
| 9000 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9002 | final long identity = Binder.clearCallingIdentity(); |
| 9003 | try { |
| 9004 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9005 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9006 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9007 | } |
| 9008 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9009 | } finally { |
| 9010 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9011 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9012 | } |
| 9013 | |
| 9014 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9015 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9016 | * |
| 9017 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9018 | * voicemail vibration setting. |
| 9019 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9020 | */ |
| 9021 | @Override |
| 9022 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9023 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9024 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9026 | final long identity = Binder.clearCallingIdentity(); |
| 9027 | try { |
| 9028 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9029 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9030 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9031 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9033 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9034 | } finally { |
| 9035 | Binder.restoreCallingIdentity(identity); |
| 9036 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9037 | } |
| 9038 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9039 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9040 | * Sets the per-account voicemail vibration. |
| 9041 | * |
| 9042 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9043 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9044 | * |
| 9045 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9046 | * voicemail vibration setting. |
| 9047 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9048 | * specific PhoneAccount. |
| 9049 | */ |
| 9050 | @Override |
| 9051 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9052 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9053 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9054 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9055 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9056 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9057 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9058 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9059 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9060 | } |
| 9061 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9062 | enforceTelephonyFeatureWithException(callingPackage, |
| 9063 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | final long identity = Binder.clearCallingIdentity(); |
| 9066 | try { |
| 9067 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9068 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9069 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9070 | } |
| 9071 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9072 | } finally { |
| 9073 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9074 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9075 | } |
| 9076 | |
| 9077 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9078 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9079 | * |
| 9080 | * @throws SecurityException if the caller does not have the required permission |
| 9081 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9082 | @VisibleForTesting |
| 9083 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9084 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9085 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9089 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9090 | * permission. |
| 9091 | * |
| 9092 | * @throws SecurityException if the caller does not have the required permission |
| 9093 | */ |
| 9094 | private void enforceSendSmsPermission() { |
| 9095 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9096 | } |
| 9097 | |
| 9098 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9099 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9100 | * users permission. |
| 9101 | * |
| 9102 | * @throws SecurityException if the caller does not have the required permission |
| 9103 | */ |
| 9104 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9105 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9106 | } |
| 9107 | |
| 9108 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9109 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9110 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9111 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9112 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9113 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9114 | final long identity = Binder.clearCallingIdentity(); |
| 9115 | try { |
| 9116 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9117 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9118 | if (componentName == null) { |
| 9119 | throw new SecurityException( |
| 9120 | "Caller not current active visual voicemail package[null]"); |
| 9121 | } |
| 9122 | String vvmPackage = componentName.getPackageName(); |
| 9123 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9124 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9125 | } |
| 9126 | } finally { |
| 9127 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9128 | } |
| 9129 | } |
| 9130 | |
| 9131 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9132 | * Return the application ID for the app type. |
| 9133 | * |
| 9134 | * @param subId the subscription ID that this request applies to. |
| 9135 | * @param appType the uicc app type. |
| 9136 | * @return Application ID for specificied app type, or null if no uicc. |
| 9137 | */ |
| 9138 | @Override |
| 9139 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9140 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9141 | |
| 9142 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9143 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9144 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9145 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9146 | |
| 9147 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9148 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9149 | if (phone == null) { |
| 9150 | return null; |
| 9151 | } |
| 9152 | String aid = null; |
| 9153 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9154 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9155 | .getApplicationByType(appType).getAid(); |
| 9156 | } catch (Exception e) { |
| 9157 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9158 | } |
| 9159 | return aid; |
| 9160 | } finally { |
| 9161 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9162 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9163 | } |
| 9164 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9165 | /** |
| 9166 | * Return the Electronic Serial Number. |
| 9167 | * |
| 9168 | * @param subId the subscription ID that this request applies to. |
| 9169 | * @return ESN or null if error. |
| 9170 | */ |
| 9171 | @Override |
| 9172 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9173 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9174 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9175 | |
| 9176 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9177 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9178 | if (phone == null) { |
| 9179 | return null; |
| 9180 | } |
| 9181 | String esn = null; |
| 9182 | try { |
| 9183 | esn = phone.getEsn(); |
| 9184 | } catch (Exception e) { |
| 9185 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9186 | } |
| 9187 | return esn; |
| 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9190 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9191 | } |
| 9192 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9193 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9194 | * Return the Preferred Roaming List Version. |
| 9195 | * |
| 9196 | * @param subId the subscription ID that this request applies to. |
| 9197 | * @return PRLVersion or null if error. |
| 9198 | */ |
| 9199 | @Override |
| 9200 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9201 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9202 | |
| 9203 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9204 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9205 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9206 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9207 | |
| 9208 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9209 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9210 | if (phone == null) { |
| 9211 | return null; |
| 9212 | } |
| 9213 | String cdmaPrlVersion = null; |
| 9214 | try { |
| 9215 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9216 | } catch (Exception e) { |
| 9217 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9218 | } |
| 9219 | return cdmaPrlVersion; |
| 9220 | } finally { |
| 9221 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9222 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9223 | } |
| 9224 | |
| 9225 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9226 | * Get snapshot of Telephony histograms |
| 9227 | * @return List of Telephony histograms |
| 9228 | * @hide |
| 9229 | */ |
| 9230 | @Override |
| 9231 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9233 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9234 | |
| 9235 | final long identity = Binder.clearCallingIdentity(); |
| 9236 | try { |
| 9237 | return RIL.getTelephonyRILTimingHistograms(); |
| 9238 | } finally { |
| 9239 | Binder.restoreCallingIdentity(identity); |
| 9240 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9241 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9242 | |
| 9243 | /** |
| 9244 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9245 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9246 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9247 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9248 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9249 | * @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] | 9250 | */ |
| 9251 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9252 | @TelephonyManager.SetCarrierRestrictionResult |
| 9253 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9254 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9255 | |
| 9256 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9257 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9258 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9259 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9260 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9261 | if (carrierRestrictionRules == null) { |
| 9262 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9263 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9265 | final long identity = Binder.clearCallingIdentity(); |
| 9266 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9267 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9268 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9269 | } finally { |
| 9270 | Binder.restoreCallingIdentity(identity); |
| 9271 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9272 | } |
| 9273 | |
| 9274 | /** |
| 9275 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9276 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9277 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9278 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9279 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9280 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9281 | */ |
| 9282 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9283 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9284 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9285 | |
| 9286 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9287 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9288 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9289 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9290 | |
| 9291 | final long identity = Binder.clearCallingIdentity(); |
| 9292 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9293 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9294 | if (response instanceof CarrierRestrictionRules) { |
| 9295 | return (CarrierRestrictionRules) response; |
| 9296 | } |
| 9297 | // Response is an Exception of some kind, |
| 9298 | // which is signalled to the user as a NULL retval |
| 9299 | return null; |
| 9300 | } catch (Exception e) { |
| 9301 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9302 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9303 | } finally { |
| 9304 | Binder.restoreCallingIdentity(identity); |
| 9305 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9306 | } |
| 9307 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9308 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9309 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9310 | * through the callback. |
| 9311 | * |
| 9312 | * @param callback The callback that will be used to send the result. |
| 9313 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9314 | * the caller is not allowlisted. |
| 9315 | */ |
| 9316 | @Override |
| 9317 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9318 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9319 | |
| 9320 | enforceTelephonyFeatureWithException(packageName, |
| 9321 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9322 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9323 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9324 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9325 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9326 | throw new SecurityException("Not an authorized caller"); |
| 9327 | } |
| 9328 | final long identity = Binder.clearCallingIdentity(); |
| 9329 | try { |
| 9330 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9331 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9332 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9333 | } finally { |
| 9334 | Binder.restoreCallingIdentity(identity); |
| 9335 | } |
| 9336 | } |
| 9337 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9338 | @Override |
| 9339 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9340 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9341 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9342 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9343 | } |
| 9344 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9345 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9346 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9347 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9348 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9349 | } |
| 9350 | |
| 9351 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9352 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9353 | * @param subId the subscription ID that this action applies to. |
| 9354 | * @param enabled control enable or disable radio. |
| 9355 | * {@hide} |
| 9356 | */ |
| 9357 | @Override |
| 9358 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9359 | enforceModifyPermission(); |
| 9360 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9361 | |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9363 | if (phone == null) { |
| 9364 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9365 | return; |
| 9366 | } |
| 9367 | try { |
| 9368 | phone.carrierActionSetRadioEnabled(enabled); |
| 9369 | } catch (Exception e) { |
| 9370 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9371 | } finally { |
| 9372 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9373 | } |
| 9374 | } |
| 9375 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9376 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9377 | * Enable or disable Voice over NR (VoNR) |
| 9378 | * @param subId the subscription ID that this action applies to. |
| 9379 | * @param enabled enable or disable VoNR. |
| 9380 | * @return operation result. |
| 9381 | */ |
| 9382 | @Override |
| 9383 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9384 | enforceModifyPermission(); |
| 9385 | final Phone phone = getPhone(subId); |
| 9386 | |
| 9387 | final long identity = Binder.clearCallingIdentity(); |
| 9388 | if (phone == null) { |
| 9389 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9390 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9391 | } |
| 9392 | |
| 9393 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9394 | try { |
| 9395 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9396 | workSource); |
| 9397 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9398 | |
| 9399 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9400 | if (DBG) { |
| 9401 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9402 | } |
| 9403 | SubscriptionManager.setSubscriptionProperty( |
| 9404 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9405 | (enabled ? "1" : "0")); |
| 9406 | } |
| 9407 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9408 | return result; |
| 9409 | } finally { |
| 9410 | Binder.restoreCallingIdentity(identity); |
| 9411 | } |
| 9412 | } |
| 9413 | |
| 9414 | /** |
| 9415 | * Is voice over NR enabled |
| 9416 | * @return true if VoNR is enabled else false |
| 9417 | */ |
| 9418 | @Override |
| 9419 | public boolean isVoNrEnabled(int subId) { |
| 9420 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9421 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9422 | final long identity = Binder.clearCallingIdentity(); |
| 9423 | try { |
| 9424 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9425 | null, subId, workSource); |
| 9426 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9427 | return isEnabled; |
| 9428 | } finally { |
| 9429 | Binder.restoreCallingIdentity(identity); |
| 9430 | } |
| 9431 | } |
| 9432 | |
| 9433 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9434 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9435 | * network status based on which carrier apps could apply actions accordingly, |
| 9436 | * enable/disable default url handler for example. |
| 9437 | * |
| 9438 | * @param subId the subscription ID that this action applies to. |
| 9439 | * @param report control start/stop reporting the default network status. |
| 9440 | * {@hide} |
| 9441 | */ |
| 9442 | @Override |
| 9443 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9444 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9445 | |
| 9446 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9447 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9448 | "carrierActionReportDefaultNetworkStatus"); |
| 9449 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9450 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9451 | |
| 9452 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9453 | if (phone == null) { |
| 9454 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9455 | return; |
| 9456 | } |
| 9457 | try { |
| 9458 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9459 | } catch (Exception e) { |
| 9460 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9463 | } |
| 9464 | } |
| 9465 | |
| 9466 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9467 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9468 | * @param subId the subscription ID that this action applies to. |
| 9469 | * {@hide} |
| 9470 | */ |
| 9471 | @Override |
| 9472 | public void carrierActionResetAll(int subId) { |
| 9473 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9474 | |
| 9475 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9476 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9477 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9478 | final Phone phone = getPhone(subId); |
| 9479 | if (phone == null) { |
| 9480 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9481 | return; |
| 9482 | } |
| 9483 | try { |
| 9484 | phone.carrierActionResetAll(); |
| 9485 | } catch (Exception e) { |
| 9486 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9487 | } |
| 9488 | } |
| 9489 | |
| 9490 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9491 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9492 | * bug report is being generated. |
| 9493 | */ |
| 9494 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9495 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9496 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9497 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9498 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9499 | + Binder.getCallingPid() |
| 9500 | + ", uid=" + Binder.getCallingUid() |
| 9501 | + "without permission " |
| 9502 | + android.Manifest.permission.DUMP); |
| 9503 | return; |
| 9504 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9505 | try { |
| 9506 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9507 | } catch (Exception e) { |
| 9508 | writer.println("Failed to dump phone information: " + e); |
| 9509 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9510 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9511 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9512 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9513 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9514 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9515 | @NonNull String[] args) { |
| 9516 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9517 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9518 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9519 | } |
| 9520 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9521 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9522 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9523 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9524 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9525 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9526 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9527 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9528 | */ |
| 9529 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9530 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9531 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9532 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9533 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9534 | try { |
| 9535 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9536 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9537 | } catch (SecurityException se) { |
| 9538 | enforceModifyPermission(); |
| 9539 | } |
| 9540 | } else { |
| 9541 | enforceModifyPermission(); |
| 9542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9543 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9544 | enforceTelephonyFeatureWithException(callingPackage, |
| 9545 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9546 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9547 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9548 | final long identity = Binder.clearCallingIdentity(); |
| 9549 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9550 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9551 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9552 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9553 | callingUid, callingPackage, null, null); |
| 9554 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9555 | Phone phone = getPhone(subId); |
| 9556 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9557 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9558 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9559 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9560 | phone.getDataSettingsManager().setDataEnabled( |
| 9561 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9563 | } |
| 9564 | } finally { |
| 9565 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9566 | } |
| 9567 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9568 | |
| 9569 | /** |
| 9570 | * Get Client request stats |
| 9571 | * @return List of Client Request Stats |
| 9572 | * @hide |
| 9573 | */ |
| 9574 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9575 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9576 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9577 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9578 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9579 | return null; |
| 9580 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9581 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9582 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9583 | final long identity = Binder.clearCallingIdentity(); |
| 9584 | try { |
| 9585 | if (phone != null) { |
| 9586 | return phone.getClientRequestStats(); |
| 9587 | } |
| 9588 | |
| 9589 | return null; |
| 9590 | } finally { |
| 9591 | Binder.restoreCallingIdentity(identity); |
| 9592 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9593 | } |
| 9594 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9595 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9596 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9597 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9598 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9599 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9600 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9601 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9602 | // commands that plumb through the RIL as root, like so: |
| 9603 | // $ adb root |
| 9604 | // $ adb shell cmd phone ... |
| 9605 | packageName = "root"; |
| 9606 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9607 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9608 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9609 | |
| 9610 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9611 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9612 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9613 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9614 | * @param state State of SIM (power down, power up, pass through) |
| 9615 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9616 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9617 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9618 | * |
| 9619 | **/ |
| 9620 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9621 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9622 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9623 | |
| 9624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9625 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9626 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9627 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9628 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9629 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9630 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9631 | final long identity = Binder.clearCallingIdentity(); |
| 9632 | try { |
| 9633 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9634 | phone.setSimPowerState(state, null, workSource); |
| 9635 | } |
| 9636 | } finally { |
| 9637 | Binder.restoreCallingIdentity(identity); |
| 9638 | } |
| 9639 | } |
| 9640 | |
| 9641 | /** |
| 9642 | * Set SIM card power state. |
| 9643 | * |
| 9644 | * @param slotIndex SIM slot id. |
| 9645 | * @param state State of SIM (power down, power up, pass through) |
| 9646 | * @param callback callback to trigger after success or failure |
| 9647 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9648 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9649 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9650 | * |
| 9651 | **/ |
| 9652 | @Override |
| 9653 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9654 | IIntegerConsumer callback) { |
| 9655 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9656 | |
| 9657 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9658 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9659 | "setSimPowerStateForSlotWithCallback"); |
| 9660 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9661 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9662 | |
| 9663 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9664 | |
| 9665 | final long identity = Binder.clearCallingIdentity(); |
| 9666 | try { |
| 9667 | if (phone != null) { |
| 9668 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9669 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9670 | } |
| 9671 | } finally { |
| 9672 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9673 | } |
| 9674 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9675 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9676 | private boolean isUssdApiAllowed(int subId) { |
| 9677 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9678 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9679 | if (configManager == null) { |
| 9680 | return false; |
| 9681 | } |
| 9682 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9683 | if (pb == null) { |
| 9684 | return false; |
| 9685 | } |
| 9686 | return pb.getBoolean( |
| 9687 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9688 | } |
| 9689 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9690 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9691 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9692 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9693 | * @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] | 9694 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9695 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9696 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9697 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9698 | |
| 9699 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9700 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9702 | final long identity = Binder.clearCallingIdentity(); |
| 9703 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9704 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9705 | } finally { |
| 9706 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9707 | } |
| 9708 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9709 | |
| 9710 | /** |
| 9711 | * Get the current signal strength information for the given subscription. |
| 9712 | * Because this information is not updated when the device is in a low power state |
| 9713 | * it should not be relied-upon to be current. |
| 9714 | * @param subId Subscription index |
| 9715 | * @return the most recent cached signal strength info from the modem |
| 9716 | */ |
| 9717 | @Override |
| 9718 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9719 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9720 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9721 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9722 | final long identity = Binder.clearCallingIdentity(); |
| 9723 | try { |
| 9724 | Phone p = getPhone(subId); |
| 9725 | if (p == null) { |
| 9726 | return null; |
| 9727 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9729 | return p.getSignalStrength(); |
| 9730 | } finally { |
| 9731 | Binder.restoreCallingIdentity(identity); |
| 9732 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9733 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9734 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9735 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9736 | * Get the current modem radio state for the given slot. |
| 9737 | * @param slotIndex slot index. |
| 9738 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9739 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9740 | * @return the current radio power state from the modem |
| 9741 | */ |
| 9742 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9743 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9744 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9745 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9746 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9747 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9748 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9749 | } |
| 9750 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9751 | enforceTelephonyFeatureWithException(callingPackage, |
| 9752 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9753 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9754 | final long identity = Binder.clearCallingIdentity(); |
| 9755 | try { |
| 9756 | return phone.getRadioPowerState(); |
| 9757 | } finally { |
| 9758 | Binder.restoreCallingIdentity(identity); |
| 9759 | } |
| 9760 | } |
| 9761 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9762 | } |
| 9763 | |
| 9764 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9765 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9766 | * |
| 9767 | * <p>Requires one of the following permissions: |
| 9768 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9769 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9770 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9771 | * privileges. |
| 9772 | * |
| 9773 | * @param subId subscription id |
| 9774 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9775 | * {@code false}. |
| 9776 | */ |
| 9777 | @Override |
| 9778 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9779 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9780 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9781 | try { |
| 9782 | mApp.enforceCallingOrSelfPermission( |
| 9783 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9784 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9785 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9786 | mApp.enforceCallingOrSelfPermission( |
| 9787 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9788 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9789 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9790 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9791 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9792 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9793 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9794 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9795 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9796 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9797 | boolean isEnabled = false; |
| 9798 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9799 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9800 | Phone phone = getPhone(subId); |
| 9801 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9802 | } finally { |
| 9803 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9804 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9805 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9806 | } |
| 9807 | |
| 9808 | |
| 9809 | /** |
| 9810 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9811 | * |
| 9812 | * <p> Requires permission: |
| 9813 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9814 | * privileges. |
| 9815 | * |
| 9816 | * @param subId subscription id |
| 9817 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9818 | */ |
| 9819 | @Override |
| 9820 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9822 | mApp, subId, "setDataRoamingEnabled"); |
| 9823 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9824 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9825 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9826 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9827 | final long identity = Binder.clearCallingIdentity(); |
| 9828 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9829 | Phone phone = getPhone(subId); |
| 9830 | if (phone != null) { |
| 9831 | phone.setDataRoamingEnabled(isEnabled); |
| 9832 | } |
| 9833 | } finally { |
| 9834 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9835 | } |
| 9836 | } |
| 9837 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9838 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9839 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9840 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9841 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9842 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9843 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9844 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9845 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9846 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9847 | boolean isAllowed = true; |
| 9848 | final long identity = Binder.clearCallingIdentity(); |
| 9849 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9850 | Phone phone = getPhone(subId); |
| 9851 | if (phone != null) { |
| 9852 | isAllowed = phone.isCspPlmnEnabled(); |
| 9853 | } |
| 9854 | } finally { |
| 9855 | Binder.restoreCallingIdentity(identity); |
| 9856 | } |
| 9857 | return isAllowed; |
| 9858 | } |
| 9859 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9860 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9861 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9862 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9863 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9864 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9865 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9866 | if (phone == null) { |
| 9867 | return false; |
| 9868 | } |
| 9869 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9870 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9871 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9872 | } |
| 9873 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9874 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9875 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9876 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9877 | mApp.getSystemService(AppOpsManager.class) |
| 9878 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9879 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9880 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9881 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9882 | try { |
| 9883 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9884 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9885 | } catch (SecurityException e) { |
| 9886 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9887 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9888 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9889 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9890 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9891 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9892 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9893 | |
| 9894 | enforceTelephonyFeatureWithException(callingPackage, |
| 9895 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9896 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9897 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9898 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9899 | Binder.getCallingUid())) { |
| 9900 | isIccIdAccessRestricted = true; |
| 9901 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9902 | final long identity = Binder.clearCallingIdentity(); |
| 9903 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9904 | UiccController uiccController = UiccController.getInstance(); |
| 9905 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9906 | if (hasReadPermission) { |
| 9907 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9908 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9909 | |
| 9910 | // Remove private info if the caller doesn't have access |
| 9911 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9912 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9913 | //setting the value after compatibility check |
| 9914 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9915 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9916 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9917 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9918 | if (card == null) { |
| 9919 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9920 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9921 | continue; |
| 9922 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9923 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9924 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9925 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9926 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9927 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9928 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9929 | for (UiccPortInfo portInfo : portInfos) { |
| 9930 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9931 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9932 | if (port == null) { |
| 9933 | // assume no access if port is null |
| 9934 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9935 | continue; |
| 9936 | } |
| 9937 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9938 | uiccPortInfos.add(portInfo); |
| 9939 | } else { |
| 9940 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9941 | } |
| 9942 | } |
| 9943 | filteredInfos.add(new UiccCardInfo( |
| 9944 | cardInfo.isEuicc(), |
| 9945 | cardInfo.getCardId(), |
| 9946 | null, |
| 9947 | cardInfo.getPhysicalSlotIndex(), |
| 9948 | cardInfo.isRemovable(), |
| 9949 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9950 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9951 | } |
| 9952 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9953 | } finally { |
| 9954 | Binder.restoreCallingIdentity(identity); |
| 9955 | } |
| 9956 | } |
| 9957 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9958 | /** |
| 9959 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9960 | * generally private and require carrier privileges to view. |
| 9961 | * |
| 9962 | * @hide |
| 9963 | */ |
| 9964 | @NonNull |
| 9965 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9966 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9967 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9968 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9969 | } |
| 9970 | return new UiccCardInfo( |
| 9971 | cardInfo.isEuicc(), |
| 9972 | cardInfo.getCardId(), |
| 9973 | null, |
| 9974 | cardInfo.getPhysicalSlotIndex(), |
| 9975 | cardInfo.isRemovable(), |
| 9976 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9977 | portinfo |
| 9978 | ); |
| 9979 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9980 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9981 | /** |
| 9982 | * @hide |
| 9983 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9984 | * These values are generally private and require carrier privileges to view. |
| 9985 | */ |
| 9986 | @NonNull |
| 9987 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9988 | return new UiccPortInfo( |
| 9989 | UiccPortInfo.ICCID_REDACTED, |
| 9990 | portInfo.getPortIndex(), |
| 9991 | portInfo.getLogicalSlotIndex(), |
| 9992 | portInfo.isActive() |
| 9993 | ); |
| 9994 | } |
| 9995 | @Override |
| 9996 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9997 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9998 | mApp.getSystemService(AppOpsManager.class) |
| 9999 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10000 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10001 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10002 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10003 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10004 | // we are reading iccId which is PII data. |
| 10005 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10006 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10007 | enforceTelephonyFeatureWithException(callingPackage, |
| 10008 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10009 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10010 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10011 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10012 | Binder.getCallingUid())) { |
| 10013 | isLogicalSlotAccessRestricted = true; |
| 10014 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10015 | final long identity = Binder.clearCallingIdentity(); |
| 10016 | try { |
| 10017 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10018 | if (slots == null || slots.length == 0) { |
| 10019 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10020 | return null; |
| 10021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10022 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10023 | for (int i = 0; i < slots.length; i++) { |
| 10024 | UiccSlot slot = slots[i]; |
| 10025 | if (slot == null) { |
| 10026 | continue; |
| 10027 | } |
| 10028 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10029 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10030 | UiccCard card = slot.getUiccCard(); |
| 10031 | if (card != null) { |
| 10032 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10033 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10034 | cardId = slot.getEid(); |
| 10035 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10036 | // If cardId is null, use iccId of default port as cardId. |
| 10037 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10038 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10039 | } |
| 10040 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10041 | if (cardId != null) { |
| 10042 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10043 | // if cardId is an EID, it's all digits so this is fine |
| 10044 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10045 | } |
| 10046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10047 | int cardState = 0; |
| 10048 | switch (slot.getCardState()) { |
| 10049 | case CARDSTATE_ABSENT: |
| 10050 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10051 | break; |
| 10052 | case CARDSTATE_PRESENT: |
| 10053 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10054 | break; |
| 10055 | case CARDSTATE_ERROR: |
| 10056 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10057 | break; |
| 10058 | case CARDSTATE_RESTRICTED: |
| 10059 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10060 | break; |
| 10061 | default: |
| 10062 | break; |
| 10063 | |
| 10064 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10065 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10066 | int[] portIndexes = slot.getPortList(); |
| 10067 | for (int portIdx : portIndexes) { |
| 10068 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10069 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10070 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10071 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10073 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10074 | slot.isEuicc(), |
| 10075 | cardId, |
| 10076 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10077 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10078 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10079 | //setting the value after compatibility check |
| 10080 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10081 | } |
| 10082 | return infos; |
| 10083 | } finally { |
| 10084 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10085 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10086 | } |
| 10087 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10088 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10089 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10090 | boolean hasReadPermission) { |
| 10091 | String iccId = slot.getIccId(portIndex); |
| 10092 | if (hasReadPermission) { // if has read permission |
| 10093 | return iccId; |
| 10094 | } else { |
| 10095 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10096 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10097 | // if no read permission, checking carrier privilege access |
| 10098 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10099 | return iccId; |
| 10100 | } |
| 10101 | } |
| 10102 | } |
| 10103 | // No read permission or carrier privilege access. |
| 10104 | return UiccPortInfo.ICCID_REDACTED; |
| 10105 | } |
| 10106 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10107 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10108 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10109 | public boolean switchSlots(int[] physicalSlots) { |
| 10110 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10111 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10112 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10113 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10115 | final long identity = Binder.clearCallingIdentity(); |
| 10116 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10117 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10118 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10119 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10120 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10121 | physicalSlots[i], i)); |
| 10122 | } |
| 10123 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10124 | } finally { |
| 10125 | Binder.restoreCallingIdentity(identity); |
| 10126 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10127 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10128 | |
| 10129 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10130 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10131 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10132 | enforceModifyPermission(); |
| 10133 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10134 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10135 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10136 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10137 | final long identity = Binder.clearCallingIdentity(); |
| 10138 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10139 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10140 | } finally { |
| 10141 | Binder.restoreCallingIdentity(identity); |
| 10142 | } |
| 10143 | } |
| 10144 | |
| 10145 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10146 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10147 | enforceTelephonyFeatureWithException(callingPackage, |
| 10148 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10149 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10150 | final long identity = Binder.clearCallingIdentity(); |
| 10151 | try { |
| 10152 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10153 | } finally { |
| 10154 | Binder.restoreCallingIdentity(identity); |
| 10155 | } |
| 10156 | } |
| 10157 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10158 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10159 | * A test API to reload the UICC profile. |
| 10160 | * |
| 10161 | * <p>Requires that the calling app has permission |
| 10162 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10163 | * @hide |
| 10164 | */ |
| 10165 | @Override |
| 10166 | public void refreshUiccProfile(int subId) { |
| 10167 | enforceModifyPermission(); |
| 10168 | |
| 10169 | final long identity = Binder.clearCallingIdentity(); |
| 10170 | try { |
| 10171 | Phone phone = getPhone(subId); |
| 10172 | if (phone == null) { |
| 10173 | return; |
| 10174 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10175 | UiccPort uiccPort = phone.getUiccPort(); |
| 10176 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10177 | return; |
| 10178 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10179 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10180 | if (uiccProfile == null) { |
| 10181 | return; |
| 10182 | } |
| 10183 | uiccProfile.refresh(); |
| 10184 | } finally { |
| 10185 | Binder.restoreCallingIdentity(identity); |
| 10186 | } |
| 10187 | } |
| 10188 | |
| 10189 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10190 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10191 | */ |
| 10192 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10193 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10194 | } |
| 10195 | |
| 10196 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10197 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10198 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10199 | */ |
| 10200 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10201 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10202 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10203 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10204 | return list.get(phoneId); |
| 10205 | } |
| 10206 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10207 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10208 | |
| 10209 | @Override |
| 10210 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10211 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10212 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10213 | |
| 10214 | final long identity = Binder.clearCallingIdentity(); |
| 10215 | try { |
| 10216 | final Phone phone = getPhone(subId); |
| 10217 | if (phone == null) { |
| 10218 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10219 | return; |
| 10220 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10221 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10222 | if (cpt != null) { |
| 10223 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10224 | } |
| 10225 | // 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] | 10226 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10227 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10228 | if (carrierPrivilegeRules == null) { |
| 10229 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10230 | } else { |
| 10231 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10233 | } finally { |
| 10234 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10235 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10236 | } |
| 10237 | |
| 10238 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10239 | public void setCarrierServicePackageOverride( |
| 10240 | int subId, String carrierServicePackage, String callingPackage) { |
| 10241 | TelephonyPermissions.enforceShellOnly( |
| 10242 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10243 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10244 | final long identity = Binder.clearCallingIdentity(); |
| 10245 | try { |
| 10246 | final Phone phone = getPhone(subId); |
| 10247 | if (phone == null || phone.getSubId() != subId) { |
| 10248 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10249 | throw new IllegalArgumentException("No phone for subid"); |
| 10250 | } |
| 10251 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10252 | if (cpt == null) { |
| 10253 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10254 | throw new IllegalStateException("No CPT for phone"); |
| 10255 | } |
| 10256 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10257 | } finally { |
| 10258 | Binder.restoreCallingIdentity(identity); |
| 10259 | } |
| 10260 | } |
| 10261 | |
| 10262 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10263 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10264 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10265 | |
| 10266 | final long identity = Binder.clearCallingIdentity(); |
| 10267 | try { |
| 10268 | final Phone phone = getPhone(subId); |
| 10269 | if (phone == null) { |
| 10270 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10271 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10272 | } |
| 10273 | return phone.getCarrierIdListVersion(); |
| 10274 | } finally { |
| 10275 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10276 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10277 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10278 | |
| 10279 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10280 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10281 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10283 | mApp, subId, callingPackage, callingFeatureId, |
| 10284 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10285 | return -1; |
| 10286 | } |
| 10287 | |
| 10288 | final long identity = Binder.clearCallingIdentity(); |
| 10289 | try { |
| 10290 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10291 | } finally { |
| 10292 | Binder.restoreCallingIdentity(identity); |
| 10293 | } |
| 10294 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10295 | |
| 10296 | @Override |
| 10297 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10298 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10299 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10300 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10301 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10302 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10303 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10304 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10305 | final long identity = Binder.clearCallingIdentity(); |
| 10306 | try { |
| 10307 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10308 | } finally { |
| 10309 | Binder.restoreCallingIdentity(identity); |
| 10310 | } |
| 10311 | } |
| 10312 | |
| 10313 | @Override |
| 10314 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10316 | mApp, subId, "setCdmaRoamingMode"); |
| 10317 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10318 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10319 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10320 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10321 | final long identity = Binder.clearCallingIdentity(); |
| 10322 | try { |
| 10323 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10324 | } finally { |
| 10325 | Binder.restoreCallingIdentity(identity); |
| 10326 | } |
| 10327 | } |
| 10328 | |
| 10329 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10330 | public int getCdmaSubscriptionMode(int subId) { |
| 10331 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10332 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10333 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10334 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10335 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10336 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10337 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10338 | final long identity = Binder.clearCallingIdentity(); |
| 10339 | try { |
| 10340 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10341 | } finally { |
| 10342 | Binder.restoreCallingIdentity(identity); |
| 10343 | } |
| 10344 | } |
| 10345 | |
| 10346 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10347 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10349 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10350 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10351 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10352 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10353 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10354 | final long identity = Binder.clearCallingIdentity(); |
| 10355 | try { |
| 10356 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10357 | } finally { |
| 10358 | Binder.restoreCallingIdentity(identity); |
| 10359 | } |
| 10360 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10361 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10362 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10363 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10364 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10365 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10366 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10367 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10368 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10369 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10370 | |
| 10371 | enforceTelephonyFeatureWithException(callingPackage, |
| 10372 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10373 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10374 | final long identity = Binder.clearCallingIdentity(); |
| 10375 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10376 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10377 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10378 | if (phone.getEmergencyNumberTracker() != null |
| 10379 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10380 | emergencyNumberListInternal.put( |
| 10381 | phone.getSubId(), |
| 10382 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10383 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10384 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10385 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10386 | } finally { |
| 10387 | Binder.restoreCallingIdentity(identity); |
| 10388 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10389 | } |
| 10390 | |
| 10391 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10392 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10393 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10394 | if (!exactMatch) { |
| 10395 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10396 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10397 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10398 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10399 | |
| 10400 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10401 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10402 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10403 | final long identity = Binder.clearCallingIdentity(); |
| 10404 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10405 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10406 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10407 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10408 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10409 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10410 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10411 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10412 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10413 | } |
| 10414 | return false; |
| 10415 | } finally { |
| 10416 | Binder.restoreCallingIdentity(identity); |
| 10417 | } |
| 10418 | } |
| 10419 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10420 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10421 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10422 | */ |
| 10423 | @Override |
| 10424 | public void startEmergencyCallbackMode() { |
| 10425 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10426 | "startEmergencyCallbackMode"); |
| 10427 | enforceModifyPermission(); |
| 10428 | final long identity = Binder.clearCallingIdentity(); |
| 10429 | try { |
| 10430 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10431 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10432 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10433 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10434 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10435 | gsmCdmaPhone.obtainMessage( |
| 10436 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10437 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10438 | } |
| 10439 | } |
| 10440 | } finally { |
| 10441 | Binder.restoreCallingIdentity(identity); |
| 10442 | } |
| 10443 | } |
| 10444 | |
| 10445 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10446 | * Update emergency number list for test mode. |
| 10447 | */ |
| 10448 | @Override |
| 10449 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10450 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10451 | "updateEmergencyNumberListTestMode"); |
| 10452 | |
| 10453 | final long identity = Binder.clearCallingIdentity(); |
| 10454 | try { |
| 10455 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10456 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10457 | if (tracker != null) { |
| 10458 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10459 | } |
| 10460 | } |
| 10461 | } finally { |
| 10462 | Binder.restoreCallingIdentity(identity); |
| 10463 | } |
| 10464 | } |
| 10465 | |
| 10466 | /** |
| 10467 | * Get the full emergency number list for test mode. |
| 10468 | */ |
| 10469 | @Override |
| 10470 | public List<String> getEmergencyNumberListTestMode() { |
| 10471 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10472 | "getEmergencyNumberListTestMode"); |
| 10473 | |
| 10474 | final long identity = Binder.clearCallingIdentity(); |
| 10475 | try { |
| 10476 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10477 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10478 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10479 | if (tracker != null) { |
| 10480 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10481 | emergencyNumbers.add(num.getNumber()); |
| 10482 | } |
| 10483 | } |
| 10484 | } |
| 10485 | return new ArrayList<>(emergencyNumbers); |
| 10486 | } finally { |
| 10487 | Binder.restoreCallingIdentity(identity); |
| 10488 | } |
| 10489 | } |
| 10490 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10491 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10492 | public int getEmergencyNumberDbVersion(int subId) { |
| 10493 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10494 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10495 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10496 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10497 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10498 | final long identity = Binder.clearCallingIdentity(); |
| 10499 | try { |
| 10500 | final Phone phone = getPhone(subId); |
| 10501 | if (phone == null) { |
| 10502 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10503 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10504 | } |
| 10505 | return phone.getEmergencyNumberDbVersion(); |
| 10506 | } finally { |
| 10507 | Binder.restoreCallingIdentity(identity); |
| 10508 | } |
| 10509 | } |
| 10510 | |
| 10511 | @Override |
| 10512 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10513 | enforceModifyPermission(); |
| 10514 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10515 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10516 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10517 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10518 | final long identity = Binder.clearCallingIdentity(); |
| 10519 | try { |
| 10520 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10521 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10522 | if (tracker != null) { |
| 10523 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10524 | } |
| 10525 | } |
| 10526 | } finally { |
| 10527 | Binder.restoreCallingIdentity(identity); |
| 10528 | } |
| 10529 | } |
| 10530 | |
| 10531 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10532 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10533 | enforceActiveEmergencySessionPermission(); |
| 10534 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10535 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10536 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10537 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10538 | final long identity = Binder.clearCallingIdentity(); |
| 10539 | try { |
| 10540 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10541 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10542 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10543 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10544 | } |
| 10545 | } |
| 10546 | } finally { |
| 10547 | Binder.restoreCallingIdentity(identity); |
| 10548 | } |
| 10549 | } |
| 10550 | |
| 10551 | @Override |
| 10552 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10553 | enforceActiveEmergencySessionPermission(); |
| 10554 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10555 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10556 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10557 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10558 | final long identity = Binder.clearCallingIdentity(); |
| 10559 | try { |
| 10560 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10561 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10562 | if (tracker != null) { |
| 10563 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10564 | } |
| 10565 | } |
| 10566 | } finally { |
| 10567 | Binder.restoreCallingIdentity(identity); |
| 10568 | } |
| 10569 | } |
| 10570 | |
| 10571 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10572 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10573 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10574 | Phone phone = getPhone(subId); |
| 10575 | if (phone == null) { |
| 10576 | return null; |
| 10577 | } |
| 10578 | final long identity = Binder.clearCallingIdentity(); |
| 10579 | try { |
| 10580 | UiccProfile profile = UiccController.getInstance() |
| 10581 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10582 | if (profile != null) { |
| 10583 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10584 | } |
| 10585 | } finally { |
| 10586 | Binder.restoreCallingIdentity(identity); |
| 10587 | } |
| 10588 | return null; |
| 10589 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10590 | |
| 10591 | /** |
| 10592 | * Enable or disable a modem stack. |
| 10593 | */ |
| 10594 | @Override |
| 10595 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10596 | enforceModifyPermission(); |
| 10597 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10598 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10599 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10600 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10601 | final long identity = Binder.clearCallingIdentity(); |
| 10602 | try { |
| 10603 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10604 | if (phone == null) { |
| 10605 | return false; |
| 10606 | } else { |
| 10607 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10608 | } |
| 10609 | } finally { |
| 10610 | Binder.restoreCallingIdentity(identity); |
| 10611 | } |
| 10612 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10613 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10614 | /** |
| 10615 | * Whether a modem stack is enabled or not. |
| 10616 | */ |
| 10617 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10618 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10619 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10620 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10621 | if (phone == null) return false; |
| 10622 | |
| 10623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10624 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10625 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10626 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10627 | } |
| 10628 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10629 | enforceTelephonyFeatureWithException(callingPackage, |
| 10630 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10631 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10632 | final long identity = Binder.clearCallingIdentity(); |
| 10633 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10634 | try { |
| 10635 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10636 | } catch (NoSuchElementException ex) { |
| 10637 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10638 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10639 | } finally { |
| 10640 | Binder.restoreCallingIdentity(identity); |
| 10641 | } |
| 10642 | } |
| 10643 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10644 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10645 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10646 | enforceModifyPermission(); |
| 10647 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10648 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10649 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10650 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10651 | final long identity = Binder.clearCallingIdentity(); |
| 10652 | try { |
| 10653 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10654 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10655 | .commit(); |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
| 10661 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10662 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10663 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10664 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10665 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10666 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10667 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10668 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10669 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10670 | enforceTelephonyFeatureWithException(callingPackage, |
| 10671 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10672 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10673 | final long identity = Binder.clearCallingIdentity(); |
| 10674 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10675 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10676 | } finally { |
| 10677 | Binder.restoreCallingIdentity(identity); |
| 10678 | } |
| 10679 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10680 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10681 | @TelephonyManager.IsMultiSimSupportedResult |
| 10682 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10683 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10684 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10685 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10686 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10687 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10688 | } |
| 10689 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10690 | // supported by the modem, indicate that it is restricted. |
| 10691 | PhoneCapability staticCapability = |
| 10692 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10693 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10694 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10695 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10696 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10697 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10698 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10699 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10700 | } |
| 10701 | // Check if support of multiple SIMs is restricted by carrier |
| 10702 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10703 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10704 | } |
| 10705 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10706 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10707 | } |
| 10708 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10709 | /** |
| 10710 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10711 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10712 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10713 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10714 | * @param numOfSims number of active sims we want to switch to |
| 10715 | */ |
| 10716 | @Override |
| 10717 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10718 | if (numOfSims == 1) { |
| 10719 | enforceModifyPermission(); |
| 10720 | } else { |
| 10721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10722 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10723 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10724 | |
| 10725 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10726 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10727 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10728 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10729 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10730 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10731 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10732 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10733 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10734 | return; |
| 10735 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10736 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10737 | } finally { |
| 10738 | Binder.restoreCallingIdentity(identity); |
| 10739 | } |
| 10740 | } |
| 10741 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10742 | @Override |
| 10743 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10744 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10745 | |
| 10746 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10747 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10748 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10749 | Phone phone = getPhone(subId); |
| 10750 | if (phone == null) { |
| 10751 | return false; |
| 10752 | } |
| 10753 | final long identity = Binder.clearCallingIdentity(); |
| 10754 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10755 | UiccPort uiccPort = phone.getUiccPort(); |
| 10756 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10757 | return false; |
| 10758 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10759 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10760 | if (uiccProfile == null) { |
| 10761 | return false; |
| 10762 | } |
| 10763 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10764 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10765 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10766 | } |
| 10767 | return false; |
| 10768 | } finally { |
| 10769 | Binder.restoreCallingIdentity(identity); |
| 10770 | } |
| 10771 | } |
| 10772 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10773 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10774 | * Get whether making changes to modem configurations will trigger reboot. |
| 10775 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10776 | */ |
| 10777 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10778 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10779 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10781 | mApp, subId, callingPackage, callingFeatureId, |
| 10782 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10783 | return false; |
| 10784 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10785 | |
| 10786 | enforceTelephonyFeatureWithException(callingPackage, |
| 10787 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10788 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10789 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10790 | final long identity = Binder.clearCallingIdentity(); |
| 10791 | try { |
| 10792 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10793 | } finally { |
| 10794 | Binder.restoreCallingIdentity(identity); |
| 10795 | } |
| 10796 | } |
| 10797 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10798 | private void updateModemStateMetrics() { |
| 10799 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10800 | // TODO: check the state for each modem if the api is ready. |
| 10801 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10802 | } |
| 10803 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10804 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10805 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10806 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10807 | // Verify that the callingPackage belongs to the calling UID |
| 10808 | mApp.getSystemService(AppOpsManager.class) |
| 10809 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10810 | |
| 10811 | enforceTelephonyFeatureWithException(callingPackage, |
| 10812 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10813 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10814 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10815 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10816 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10817 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10818 | if (slotInfos != null) { |
| 10819 | for (int i = 0; i < slotInfos.length; i++) { |
| 10820 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10821 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10822 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10823 | portInfo.getLogicalSlotIndex())); |
| 10824 | } |
| 10825 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10826 | } |
| 10827 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10828 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10829 | } finally { |
| 10830 | Binder.restoreCallingIdentity(identity); |
| 10831 | } |
| 10832 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10833 | |
| 10834 | /** |
| 10835 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10836 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10837 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10838 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10839 | @Override |
| 10840 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10841 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10842 | } |
| 10843 | |
| 10844 | /** |
| 10845 | * Get the HAL Version of a specific service |
| 10846 | */ |
| 10847 | @Override |
| 10848 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10849 | Phone phone = getDefaultPhone(); |
| 10850 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10851 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10852 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10853 | return hv.major * 100 + hv.minor; |
| 10854 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10855 | |
| 10856 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10857 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10858 | * |
| 10859 | * @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] | 10860 | */ |
| 10861 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10862 | public @Nullable String getCurrentPackageName() { |
| 10863 | PackageManager pm = mApp.getPackageManager(); |
| 10864 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10865 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10866 | } |
| 10867 | |
| 10868 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10869 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10870 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10871 | * actually always the caller. |
| 10872 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10873 | */ |
| 10874 | private String getCurrentPackageNameOrPhone() { |
| 10875 | PackageManager pm = mApp.getPackageManager(); |
| 10876 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10877 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10878 | return getCurrentPackageName(); |
| 10879 | } |
| 10880 | |
| 10881 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10882 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10883 | * corresponding network requests on a subId. |
| 10884 | * |
| 10885 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10886 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10887 | * 2) APN is un-metered for this subscription, or |
| 10888 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10889 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10890 | * |
| 10891 | * @return whether data is allowed for a apn type. |
| 10892 | * |
| 10893 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10894 | */ |
| 10895 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10896 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10897 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10898 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10899 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10900 | enforceTelephonyFeatureWithException(callingPackage, |
| 10901 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10902 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10903 | // Now that all security checks passes, perform the operation as ourselves. |
| 10904 | final long identity = Binder.clearCallingIdentity(); |
| 10905 | try { |
| 10906 | Phone phone = getPhone(subId); |
| 10907 | if (phone == null) return false; |
| 10908 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10909 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10910 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10911 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10912 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10913 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10914 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10915 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10916 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10917 | } finally { |
| 10918 | Binder.restoreCallingIdentity(identity); |
| 10919 | } |
| 10920 | } |
| 10921 | |
| 10922 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10923 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10924 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10925 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10926 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10927 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10928 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10929 | // Now that all security checks passes, perform the operation as ourselves. |
| 10930 | final long identity = Binder.clearCallingIdentity(); |
| 10931 | try { |
| 10932 | Phone phone = getPhone(subId); |
| 10933 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10934 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10935 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10936 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10937 | } finally { |
| 10938 | Binder.restoreCallingIdentity(identity); |
| 10939 | } |
| 10940 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10941 | |
| 10942 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10943 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10944 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10945 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10946 | |
| 10947 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10948 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10949 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10950 | long token = Binder.clearCallingIdentity(); |
| 10951 | try { |
| 10952 | Phone phone = getPhone(subscriptionId); |
| 10953 | if (phone == null) { |
| 10954 | try { |
| 10955 | if (resultCallback != null) { |
| 10956 | resultCallback.accept(false); |
| 10957 | } |
| 10958 | } catch (RemoteException e) { |
| 10959 | // ignore |
| 10960 | } |
| 10961 | return; |
| 10962 | } |
| 10963 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10964 | Pair.create(specifiers, (x) -> { |
| 10965 | try { |
| 10966 | if (resultCallback != null) { |
| 10967 | resultCallback.accept(x); |
| 10968 | } |
| 10969 | } catch (RemoteException e) { |
| 10970 | // ignore |
| 10971 | } |
| 10972 | }); |
| 10973 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10974 | } finally { |
| 10975 | Binder.restoreCallingIdentity(token); |
| 10976 | } |
| 10977 | } |
| 10978 | |
| 10979 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10980 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10981 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10982 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10983 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10984 | |
| 10985 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10986 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10987 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10988 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10989 | final long identity = Binder.clearCallingIdentity(); |
| 10990 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10991 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10992 | if (result instanceof IllegalStateException) { |
| 10993 | throw (IllegalStateException) result; |
| 10994 | } |
| 10995 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10996 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10997 | return specifiers; |
| 10998 | } finally { |
| 10999 | Binder.restoreCallingIdentity(identity); |
| 11000 | } |
| 11001 | } |
| 11002 | |
| 11003 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11004 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11005 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11006 | |
| 11007 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11008 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11009 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11010 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11011 | } |
| 11012 | |
| 11013 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11014 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11015 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11016 | if (callingPackage == null) { |
| 11017 | callingPackage = getCurrentPackageName(); |
| 11018 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11019 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11020 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11021 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11022 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11023 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11024 | } |
| 11025 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11026 | Intent intent = new Intent(); |
| 11027 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11028 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11029 | // Bring up choose default SMS subscription dialog right now |
| 11030 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11031 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 11032 | mApp.startActivity(intent); |
| 11033 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11034 | |
| 11035 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11036 | public void showSwitchToManagedProfileDialog() { |
| 11037 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11038 | try { |
| 11039 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11040 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11041 | // for work telephony. |
| 11042 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11043 | intent.setData(Uri.parse("smsto:")); |
| 11044 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11045 | mApp.startActivity(intent); |
| 11046 | } catch (ActivityNotFoundException e) { |
| 11047 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11048 | Intent intent = new Intent(); |
| 11049 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11050 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11051 | mApp.startActivity(intent); |
| 11052 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11053 | } |
| 11054 | |
| 11055 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11056 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11057 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11058 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11059 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11060 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11061 | final long identity = Binder.clearCallingIdentity(); |
| 11062 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11063 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11064 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11065 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11066 | return carrierUAProfUrl; |
| 11067 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11068 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11069 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11070 | } finally { |
| 11071 | Binder.restoreCallingIdentity(identity); |
| 11072 | } |
| 11073 | } |
| 11074 | |
| 11075 | @Override |
| 11076 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11078 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11079 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11080 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11081 | final long identity = Binder.clearCallingIdentity(); |
| 11082 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11083 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11084 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11085 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11086 | return carrierUserAgent; |
| 11087 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11088 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11089 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11090 | } finally { |
| 11091 | Binder.restoreCallingIdentity(identity); |
| 11092 | } |
| 11093 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11094 | |
| 11095 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11096 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11097 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11098 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11099 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11100 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11101 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11102 | final long identity = Binder.clearCallingIdentity(); |
| 11103 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11104 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11105 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11106 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11107 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11108 | } finally { |
| 11109 | Binder.restoreCallingIdentity(identity); |
| 11110 | } |
| 11111 | } |
| 11112 | |
| 11113 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11114 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11115 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11116 | enforceModifyPermission(); |
| 11117 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11118 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11119 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11120 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11121 | final long identity = Binder.clearCallingIdentity(); |
| 11122 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11123 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11124 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11125 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11126 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11127 | } finally { |
| 11128 | Binder.restoreCallingIdentity(identity); |
| 11129 | } |
| 11130 | } |
| 11131 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11132 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11133 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11134 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11135 | * otherwise. |
| 11136 | */ |
| 11137 | @Override |
| 11138 | public void setCepEnabled(boolean isCepEnabled) { |
| 11139 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11140 | |
| 11141 | final long identity = Binder.clearCallingIdentity(); |
| 11142 | try { |
| 11143 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11144 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11145 | Phone defaultPhone = phone.getImsPhone(); |
| 11146 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11147 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11148 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11149 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11150 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11151 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11152 | + imsPhone.getMsisdn()); |
| 11153 | } |
| 11154 | } |
| 11155 | } finally { |
| 11156 | Binder.restoreCallingIdentity(identity); |
| 11157 | } |
| 11158 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11159 | |
| 11160 | /** |
| 11161 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11162 | * |
| 11163 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11164 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11165 | * before being read. |
| 11166 | */ |
| 11167 | @Override |
| 11168 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11169 | isCompressed) { |
| 11170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11171 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11172 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11173 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11174 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11175 | |
| 11176 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11177 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11178 | Binder.getCallingUserHandle())) { |
| 11179 | if (!isImsAvailableOnDevice()) { |
| 11180 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11181 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11182 | throw new IllegalStateException("IMS not available on device."); |
| 11183 | } |
| 11184 | } else { |
| 11185 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11186 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11187 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11188 | } |
| 11189 | |
| 11190 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11191 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11192 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11193 | } finally { |
| 11194 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11195 | } |
| 11196 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11197 | |
| 11198 | @Override |
| 11199 | public boolean isIccLockEnabled(int subId) { |
| 11200 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11201 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11202 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11203 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11204 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11205 | // Now that all security checks passes, perform the operation as ourselves. |
| 11206 | final long identity = Binder.clearCallingIdentity(); |
| 11207 | try { |
| 11208 | Phone phone = getPhone(subId); |
| 11209 | if (phone != null && phone.getIccCard() != null) { |
| 11210 | return phone.getIccCard().getIccLockEnabled(); |
| 11211 | } else { |
| 11212 | return false; |
| 11213 | } |
| 11214 | } finally { |
| 11215 | Binder.restoreCallingIdentity(identity); |
| 11216 | } |
| 11217 | } |
| 11218 | |
| 11219 | /** |
| 11220 | * Set the ICC pin lock enabled or disabled. |
| 11221 | * |
| 11222 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11223 | * three cases: |
| 11224 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11225 | * successfully. |
| 11226 | * - Positive number and zero for remaining password attempts. |
| 11227 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11228 | * |
| 11229 | */ |
| 11230 | @Override |
| 11231 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11232 | enforceModifyPermission(); |
| 11233 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11234 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11235 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11236 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11237 | Phone phone = getPhone(subId); |
| 11238 | if (phone == null) { |
| 11239 | return 0; |
| 11240 | } |
| 11241 | // Now that all security checks passes, perform the operation as ourselves. |
| 11242 | final long identity = Binder.clearCallingIdentity(); |
| 11243 | try { |
| 11244 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11245 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11246 | return attemptsRemaining; |
| 11247 | |
| 11248 | } catch (Exception e) { |
| 11249 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11250 | } finally { |
| 11251 | Binder.restoreCallingIdentity(identity); |
| 11252 | } |
| 11253 | return 0; |
| 11254 | } |
| 11255 | |
| 11256 | /** |
| 11257 | * Change the ICC password used in ICC pin lock. |
| 11258 | * |
| 11259 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11260 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11261 | * - Positive number and zero for remaining password attempts. |
| 11262 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11263 | * |
| 11264 | */ |
| 11265 | @Override |
| 11266 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11267 | enforceModifyPermission(); |
| 11268 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11269 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11270 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11271 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11272 | Phone phone = getPhone(subId); |
| 11273 | if (phone == null) { |
| 11274 | return 0; |
| 11275 | } |
| 11276 | // Now that all security checks passes, perform the operation as ourselves. |
| 11277 | final long identity = Binder.clearCallingIdentity(); |
| 11278 | try { |
| 11279 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11280 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11281 | return attemptsRemaining; |
| 11282 | |
| 11283 | } catch (Exception e) { |
| 11284 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11285 | } finally { |
| 11286 | Binder.restoreCallingIdentity(identity); |
| 11287 | } |
| 11288 | return 0; |
| 11289 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11290 | |
| 11291 | /** |
| 11292 | * Request for receiving user activity notification |
| 11293 | */ |
| 11294 | @Override |
| 11295 | public void requestUserActivityNotification() { |
| 11296 | if (!mNotifyUserActivity.get() |
| 11297 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11298 | mNotifyUserActivity.set(true); |
| 11299 | } |
| 11300 | } |
| 11301 | |
| 11302 | /** |
| 11303 | * Called when userActivity is signalled in the power manager. |
| 11304 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11305 | */ |
| 11306 | @Override |
| 11307 | public void userActivity() { |
| 11308 | // *************************************** |
| 11309 | // * Inherited from PhoneWindowManager * |
| 11310 | // *************************************** |
| 11311 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11312 | // WITH ITS LOCKS HELD. |
| 11313 | // |
| 11314 | // This code must be VERY careful about the locks |
| 11315 | // it acquires. |
| 11316 | // In fact, the current code acquires way too many, |
| 11317 | // and probably has lurking deadlocks. |
| 11318 | |
| 11319 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11320 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11321 | } |
| 11322 | |
| 11323 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11324 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11325 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11326 | } |
| 11327 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11328 | |
| 11329 | @Override |
| 11330 | public boolean canConnectTo5GInDsdsMode() { |
| 11331 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11332 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11333 | |
| 11334 | @Override |
| 11335 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11336 | String callingFeatureId) { |
| 11337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11338 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11339 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11340 | } |
| 11341 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11342 | enforceTelephonyFeatureWithException(callingPackage, |
| 11343 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11344 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11345 | Phone phone = getPhone(subId); |
| 11346 | if (phone == null) { |
| 11347 | throw new RuntimeException("phone is not available"); |
| 11348 | } |
| 11349 | // Now that all security checks passes, perform the operation as ourselves. |
| 11350 | final long identity = Binder.clearCallingIdentity(); |
| 11351 | try { |
| 11352 | return phone.getEquivalentHomePlmns(); |
| 11353 | } finally { |
| 11354 | Binder.restoreCallingIdentity(identity); |
| 11355 | } |
| 11356 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11357 | |
| 11358 | @Override |
| 11359 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11360 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11361 | if (!mApp.getResources().getBoolean( |
| 11362 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11363 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11364 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11365 | "isRadioInterfaceCapabilitySupported"); |
| 11366 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11367 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11368 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11369 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11370 | if (radioInterfaceCapabilities == null) { |
| 11371 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11372 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11373 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11374 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11375 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11376 | @Override |
| 11377 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11378 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11379 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11380 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11381 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11382 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11383 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11384 | |
| 11385 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11386 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11387 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11388 | if (DBG) { |
| 11389 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11390 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11391 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11392 | } |
| 11393 | |
| 11394 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11395 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11396 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11397 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11398 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11399 | if (callback != null) { |
| 11400 | try { |
| 11401 | callback.onAuthenticationFailure( |
| 11402 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11403 | } catch (RemoteException exception) { |
| 11404 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11405 | } |
| 11406 | return; |
| 11407 | } |
| 11408 | } |
| 11409 | |
| 11410 | final long token = Binder.clearCallingIdentity(); |
| 11411 | try { |
| 11412 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11413 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11414 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11415 | } finally { |
| 11416 | Binder.restoreCallingIdentity(token); |
| 11417 | } |
| 11418 | } |
| 11419 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11420 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11421 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11422 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11423 | * requested radio power state will actually be set. See {@link |
| 11424 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11425 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11426 | * @param enable {@code true} if trying to turn radio on. |
| 11427 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11428 | * false}. |
| 11429 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11430 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11431 | boolean isPhoneAvailable = false; |
| 11432 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11433 | Phone phone = PhoneFactory.getPhone(i); |
| 11434 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11435 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11436 | isPhoneAvailable = true; |
| 11437 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11438 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11439 | |
| 11440 | // return true if successfully informed the phone object about the thermal radio power |
| 11441 | // request. |
| 11442 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11443 | } |
| 11444 | |
| 11445 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11446 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11447 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11448 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11449 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11450 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11451 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11452 | } |
| 11453 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11454 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11455 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11456 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11457 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11458 | } |
| 11459 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11460 | setDataEnabledForReason( |
| 11461 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11462 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11463 | if (isDataThrottlingSupported) { |
| 11464 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11465 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11466 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11467 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11468 | } else if (thermalMitigationResult |
| 11469 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11470 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11471 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11472 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11473 | } |
| 11474 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11475 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11476 | |
| 11477 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11478 | } |
| 11479 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11480 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11481 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11482 | for (String pckg : context.getResources() |
| 11483 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11484 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11485 | } |
| 11486 | } |
| 11487 | |
| 11488 | return sThermalMitigationAllowlistedPackages; |
| 11489 | } |
| 11490 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11491 | private boolean isAnyPhoneInEmergencyState() { |
| 11492 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11493 | if (tm.isInEmergencyCall()) { |
| 11494 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11495 | return true; |
| 11496 | } |
| 11497 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11498 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11499 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11500 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11501 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11502 | return true; |
| 11503 | } |
| 11504 | } |
| 11505 | |
| 11506 | return false; |
| 11507 | } |
| 11508 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11509 | /** |
| 11510 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11511 | * @param packageName name of package to be allowlisted |
| 11512 | * @param context |
| 11513 | */ |
| 11514 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11515 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11516 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11517 | } |
| 11518 | |
| 11519 | /** |
| 11520 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11521 | * @param packageName name of package to remove from allowlist |
| 11522 | * @param context |
| 11523 | */ |
| 11524 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11525 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11526 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11527 | } |
| 11528 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11529 | /** |
| 11530 | * Thermal mitigation request to control functionalities at modem. |
| 11531 | * |
| 11532 | * @param subId the id of the subscription. |
| 11533 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11534 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11535 | * |
| 11536 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11537 | */ |
| 11538 | @Override |
| 11539 | @ThermalMitigationResult |
| 11540 | public int sendThermalMitigationRequest( |
| 11541 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11542 | ThermalMitigationRequest thermalMitigationRequest, |
| 11543 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11544 | enforceModifyPermission(); |
| 11545 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11546 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11547 | |
| 11548 | enforceTelephonyFeatureWithException(callingPackage, |
| 11549 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11550 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11551 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11552 | .contains(callingPackage)) { |
| 11553 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11554 | + "calling package: " + callingPackage); |
| 11555 | } |
| 11556 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11557 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11558 | final long identity = Binder.clearCallingIdentity(); |
| 11559 | |
| 11560 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11561 | try { |
| 11562 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11563 | switch (thermalMitigationAction) { |
| 11564 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11565 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11566 | handleDataThrottlingRequest(subId, |
| 11567 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11568 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11569 | break; |
| 11570 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11571 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11572 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11573 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11574 | } |
| 11575 | |
| 11576 | // Ensure that radio is on. If not able to power on due to phone being |
| 11577 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11578 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11579 | thermalMitigationResult = |
| 11580 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11581 | break; |
| 11582 | } |
| 11583 | |
| 11584 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11585 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11586 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11587 | break; |
| 11588 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11589 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11590 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11591 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11592 | } |
| 11593 | |
| 11594 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11595 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11596 | Phone phone = getPhone(subId); |
| 11597 | if (phone == null) { |
| 11598 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11599 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11600 | break; |
| 11601 | } |
| 11602 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11603 | TelephonyConnectionService service = |
| 11604 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11605 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11606 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11607 | thermalMitigationResult = |
| 11608 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11609 | break; |
| 11610 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11611 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11612 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11613 | break; |
| 11614 | } |
| 11615 | } else { |
| 11616 | thermalMitigationResult = |
| 11617 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11618 | break; |
| 11619 | } |
| 11620 | |
| 11621 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11622 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11623 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11624 | thermalMitigationResult = |
| 11625 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11626 | break; |
| 11627 | } |
| 11628 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11629 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11630 | break; |
| 11631 | default: |
| 11632 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11633 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11634 | } |
| 11635 | } catch (IllegalArgumentException e) { |
| 11636 | throw e; |
| 11637 | } catch (Exception e) { |
| 11638 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11639 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11640 | } finally { |
| 11641 | Binder.restoreCallingIdentity(identity); |
| 11642 | } |
| 11643 | |
| 11644 | if (DBG) { |
| 11645 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11646 | + thermalMitigationResult); |
| 11647 | } |
| 11648 | |
| 11649 | return thermalMitigationResult; |
| 11650 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11651 | |
| 11652 | /** |
| 11653 | * Set the GbaService Package Name that Telephony will bind to. |
| 11654 | * |
| 11655 | * @param subId The sim that the GbaService is associated with. |
| 11656 | * @param packageName The name of the package to be replaced with. |
| 11657 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11658 | */ |
| 11659 | @Override |
| 11660 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11661 | enforceModifyPermission(); |
| 11662 | |
| 11663 | final long identity = Binder.clearCallingIdentity(); |
| 11664 | try { |
| 11665 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11666 | } finally { |
| 11667 | Binder.restoreCallingIdentity(identity); |
| 11668 | } |
| 11669 | } |
| 11670 | |
| 11671 | /** |
| 11672 | * Return the package name of the currently bound GbaService. |
| 11673 | * |
| 11674 | * @param subId The sim that the GbaService is associated with. |
| 11675 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11676 | */ |
| 11677 | @Override |
| 11678 | public String getBoundGbaService(int subId) { |
| 11679 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11680 | |
| 11681 | final long identity = Binder.clearCallingIdentity(); |
| 11682 | try { |
| 11683 | return getGbaManager(subId).getServicePackage(); |
| 11684 | } finally { |
| 11685 | Binder.restoreCallingIdentity(identity); |
| 11686 | } |
| 11687 | } |
| 11688 | |
| 11689 | /** |
| 11690 | * Set the release time for telephony to unbind GbaService. |
| 11691 | * |
| 11692 | * @param subId The sim that the GbaService is associated with. |
| 11693 | * @param interval The release time to unbind GbaService by millisecond. |
| 11694 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11695 | */ |
| 11696 | @Override |
| 11697 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11698 | enforceModifyPermission(); |
| 11699 | |
| 11700 | final long identity = Binder.clearCallingIdentity(); |
| 11701 | try { |
| 11702 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11703 | } finally { |
| 11704 | Binder.restoreCallingIdentity(identity); |
| 11705 | } |
| 11706 | } |
| 11707 | |
| 11708 | /** |
| 11709 | * Return the release time for telephony to unbind GbaService. |
| 11710 | * |
| 11711 | * @param subId The sim that the GbaService is associated with. |
| 11712 | * @return The release time to unbind GbaService by millisecond. |
| 11713 | */ |
| 11714 | @Override |
| 11715 | public int getGbaReleaseTime(int subId) { |
| 11716 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11717 | |
| 11718 | final long identity = Binder.clearCallingIdentity(); |
| 11719 | try { |
| 11720 | return getGbaManager(subId).getReleaseTime(); |
| 11721 | } finally { |
| 11722 | Binder.restoreCallingIdentity(identity); |
| 11723 | } |
| 11724 | } |
| 11725 | |
| 11726 | private GbaManager getGbaManager(int subId) { |
| 11727 | GbaManager instance = GbaManager.getInstance(subId); |
| 11728 | if (instance == null) { |
| 11729 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11730 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11731 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11732 | } |
| 11733 | return instance; |
| 11734 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11735 | |
| 11736 | /** |
| 11737 | * indicate whether the device and the carrier can support |
| 11738 | * RCS VoLTE single registration. |
| 11739 | */ |
| 11740 | @Override |
| 11741 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11742 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11743 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11744 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11745 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11746 | |
| 11747 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11748 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11749 | } |
| 11750 | |
| 11751 | final long identity = Binder.clearCallingIdentity(); |
| 11752 | try { |
| 11753 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11754 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11755 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11756 | if (isCapable != null) { |
| 11757 | return isCapable; |
| 11758 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11759 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11760 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11761 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11762 | } finally { |
| 11763 | Binder.restoreCallingIdentity(identity); |
| 11764 | } |
| 11765 | } |
| 11766 | |
| 11767 | /** |
| 11768 | * Register RCS provisioning callback. |
| 11769 | */ |
| 11770 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11771 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11772 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11773 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11774 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11775 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11776 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11777 | |
| 11778 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11779 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11780 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11781 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11782 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11783 | Binder.getCallingUserHandle())) { |
| 11784 | if (!isImsAvailableOnDevice()) { |
| 11785 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11786 | "IMS not available on device."); |
| 11787 | } |
| 11788 | } else { |
| 11789 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11790 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11791 | } |
| 11792 | |
| 11793 | final long identity = Binder.clearCallingIdentity(); |
| 11794 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11795 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11796 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11798 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11799 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11800 | } finally { |
| 11801 | Binder.restoreCallingIdentity(identity); |
| 11802 | } |
| 11803 | } |
| 11804 | |
| 11805 | /** |
| 11806 | * Unregister RCS provisioning callback. |
| 11807 | */ |
| 11808 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11809 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11811 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11812 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11813 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11814 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11815 | |
| 11816 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11817 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11818 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11819 | |
| 11820 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11821 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11822 | Binder.getCallingUserHandle())) { |
| 11823 | if (!isImsAvailableOnDevice()) { |
| 11824 | // operation failed silently |
| 11825 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11826 | return; |
| 11827 | } |
| 11828 | } else { |
| 11829 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11830 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11831 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11832 | } |
| 11833 | |
| 11834 | final long identity = Binder.clearCallingIdentity(); |
| 11835 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11836 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11837 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11838 | } finally { |
| 11839 | Binder.restoreCallingIdentity(identity); |
| 11840 | } |
| 11841 | } |
| 11842 | |
| 11843 | /** |
| 11844 | * trigger RCS reconfiguration. |
| 11845 | */ |
| 11846 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11847 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11848 | "triggerRcsReconfiguration", |
| 11849 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11850 | |
| 11851 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11852 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11853 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11854 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11855 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11856 | Binder.getCallingUserHandle())) { |
| 11857 | if (!isImsAvailableOnDevice()) { |
| 11858 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11859 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11860 | throw new IllegalStateException("IMS not available on device."); |
| 11861 | } |
| 11862 | } else { |
| 11863 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11864 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11865 | } |
| 11866 | |
| 11867 | final long identity = Binder.clearCallingIdentity(); |
| 11868 | try { |
| 11869 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11870 | } finally { |
| 11871 | Binder.restoreCallingIdentity(identity); |
| 11872 | } |
| 11873 | } |
| 11874 | |
| 11875 | /** |
| 11876 | * Provide the client configuration parameters of the RCS application. |
| 11877 | */ |
| 11878 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11879 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11880 | "setRcsClientConfiguration", |
| 11881 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11882 | |
| 11883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11884 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11885 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11886 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11887 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11888 | Binder.getCallingUserHandle())) { |
| 11889 | if (!isImsAvailableOnDevice()) { |
| 11890 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11891 | "IMS not available on device."); |
| 11892 | } |
| 11893 | } else { |
| 11894 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11895 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11896 | } |
| 11897 | |
| 11898 | final long identity = Binder.clearCallingIdentity(); |
| 11899 | |
| 11900 | try { |
| 11901 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11902 | if (configBinder == null) { |
| 11903 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11904 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11905 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11906 | } else { |
| 11907 | configBinder.setRcsClientConfiguration(rcc); |
| 11908 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11909 | |
| 11910 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11911 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11912 | } catch (RemoteException e) { |
| 11913 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11914 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11915 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11916 | } finally { |
| 11917 | Binder.restoreCallingIdentity(identity); |
| 11918 | } |
| 11919 | } |
| 11920 | |
| 11921 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11922 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11923 | */ |
| 11924 | @Override |
| 11925 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11926 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11927 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11928 | |
| 11929 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11930 | } |
| 11931 | |
| 11932 | /** |
| 11933 | * Gets the test mode for RCS VoLTE single registration. |
| 11934 | */ |
| 11935 | @Override |
| 11936 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11937 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11938 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11939 | |
| 11940 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11941 | } |
| 11942 | |
| 11943 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11944 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11945 | */ |
| 11946 | @Override |
| 11947 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11948 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11949 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11950 | enforceModifyPermission(); |
| 11951 | |
| 11952 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11953 | : Boolean.parseBoolean(enabledStr); |
| 11954 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11955 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11956 | } |
| 11957 | |
| 11958 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11959 | * Sends a device to device communication message. Only usable via shell. |
| 11960 | * @param message message to send. |
| 11961 | * @param value message value. |
| 11962 | */ |
| 11963 | @Override |
| 11964 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11965 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11966 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11967 | enforceModifyPermission(); |
| 11968 | |
| 11969 | final long identity = Binder.clearCallingIdentity(); |
| 11970 | try { |
| 11971 | TelephonyConnectionService service = |
| 11972 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11973 | if (service == null) { |
| 11974 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11975 | return; |
| 11976 | } |
| 11977 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11978 | } finally { |
| 11979 | Binder.restoreCallingIdentity(identity); |
| 11980 | } |
| 11981 | } |
| 11982 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11983 | /** |
| 11984 | * Sets the specified device to device transport active. |
| 11985 | * @param transport The transport to set active. |
| 11986 | */ |
| 11987 | @Override |
| 11988 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11990 | "setActiveDeviceToDeviceTransport"); |
| 11991 | enforceModifyPermission(); |
| 11992 | |
| 11993 | final long identity = Binder.clearCallingIdentity(); |
| 11994 | try { |
| 11995 | TelephonyConnectionService service = |
| 11996 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11997 | if (service == null) { |
| 11998 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11999 | return; |
| 12000 | } |
| 12001 | service.setActiveDeviceToDeviceTransport(transport); |
| 12002 | } finally { |
| 12003 | Binder.restoreCallingIdentity(identity); |
| 12004 | } |
| 12005 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12006 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12007 | @Override |
| 12008 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12009 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12010 | "setDeviceToDeviceForceEnabled"); |
| 12011 | |
| 12012 | final long identity = Binder.clearCallingIdentity(); |
| 12013 | try { |
| 12014 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12015 | p -> { |
| 12016 | Phone thePhone = p.getImsPhone(); |
| 12017 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12018 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12019 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12020 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12021 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12022 | (ImsPhoneCallTracker) tracker; |
| 12023 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12024 | } |
| 12025 | } |
| 12026 | } |
| 12027 | ); |
| 12028 | } finally { |
| 12029 | Binder.restoreCallingIdentity(identity); |
| 12030 | } |
| 12031 | } |
| 12032 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12033 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12034 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12035 | */ |
| 12036 | @Override |
| 12037 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12038 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12039 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12040 | } |
| 12041 | |
| 12042 | /** |
| 12043 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12044 | */ |
| 12045 | @Override |
| 12046 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12047 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12048 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12049 | enforceModifyPermission(); |
| 12050 | |
| 12051 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12052 | : Boolean.parseBoolean(enabledStr); |
| 12053 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12054 | subId, enabled); |
| 12055 | } |
| 12056 | |
| 12057 | /** |
| 12058 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12059 | */ |
| 12060 | @Override |
| 12061 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12062 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12063 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12064 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12065 | |
| 12066 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12067 | * Overrides the ims feature validation result |
| 12068 | */ |
| 12069 | @Override |
| 12070 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12071 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12072 | "setImsFeatureValidationOverride"); |
| 12073 | |
| 12074 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12075 | : Boolean.parseBoolean(enabledStr); |
| 12076 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12077 | subId, enabled); |
| 12078 | } |
| 12079 | |
| 12080 | /** |
| 12081 | * Gets the ims feature validation override value |
| 12082 | */ |
| 12083 | @Override |
| 12084 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12086 | "getImsFeatureValidationOverride"); |
| 12087 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12088 | } |
| 12089 | |
| 12090 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12091 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12092 | * their mobile plan. |
| 12093 | */ |
| 12094 | @Override |
| 12095 | public String getMobileProvisioningUrl() { |
| 12096 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12097 | final long identity = Binder.clearCallingIdentity(); |
| 12098 | try { |
| 12099 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12100 | } finally { |
| 12101 | Binder.restoreCallingIdentity(identity); |
| 12102 | } |
| 12103 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12104 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12105 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12106 | * Get the EAB contact from the EAB database. |
| 12107 | */ |
| 12108 | @Override |
| 12109 | public String getContactFromEab(String contact) { |
| 12110 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12111 | enforceModifyPermission(); |
| 12112 | final long identity = Binder.clearCallingIdentity(); |
| 12113 | try { |
| 12114 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12115 | } finally { |
| 12116 | Binder.restoreCallingIdentity(identity); |
| 12117 | } |
| 12118 | } |
| 12119 | |
| 12120 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12121 | * Get the EAB capability from the EAB database. |
| 12122 | */ |
| 12123 | @Override |
| 12124 | public String getCapabilityFromEab(String contact) { |
| 12125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12126 | enforceModifyPermission(); |
| 12127 | final long identity = Binder.clearCallingIdentity(); |
| 12128 | try { |
| 12129 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12130 | } finally { |
| 12131 | Binder.restoreCallingIdentity(identity); |
| 12132 | } |
| 12133 | } |
| 12134 | |
| 12135 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12136 | * Remove the EAB contacts from the EAB database. |
| 12137 | */ |
| 12138 | @Override |
| 12139 | public int removeContactFromEab(int subId, String contacts) { |
| 12140 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12141 | enforceModifyPermission(); |
| 12142 | final long identity = Binder.clearCallingIdentity(); |
| 12143 | try { |
| 12144 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12145 | } finally { |
| 12146 | Binder.restoreCallingIdentity(identity); |
| 12147 | } |
| 12148 | } |
| 12149 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12150 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12151 | public boolean getDeviceUceEnabled() { |
| 12152 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12153 | final long identity = Binder.clearCallingIdentity(); |
| 12154 | try { |
| 12155 | return mApp.getDeviceUceEnabled(); |
| 12156 | } finally { |
| 12157 | Binder.restoreCallingIdentity(identity); |
| 12158 | } |
| 12159 | } |
| 12160 | |
| 12161 | @Override |
| 12162 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12164 | final long identity = Binder.clearCallingIdentity(); |
| 12165 | try { |
| 12166 | mApp.setDeviceUceEnabled(isEnabled); |
| 12167 | } finally { |
| 12168 | Binder.restoreCallingIdentity(identity); |
| 12169 | } |
| 12170 | } |
| 12171 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12172 | /** |
| 12173 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12174 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12175 | */ |
| 12176 | // Used for SHELL command only right now. |
| 12177 | @Override |
| 12178 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12179 | List<String> featureTags) { |
| 12180 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12181 | "addUceRegistrationOverrideShell"); |
| 12182 | final long identity = Binder.clearCallingIdentity(); |
| 12183 | try { |
| 12184 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12185 | new ArraySet<>(featureTags)); |
| 12186 | } catch (ImsException e) { |
| 12187 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12188 | } finally { |
| 12189 | Binder.restoreCallingIdentity(identity); |
| 12190 | } |
| 12191 | } |
| 12192 | |
| 12193 | /** |
| 12194 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12195 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12196 | */ |
| 12197 | // Used for SHELL command only right now. |
| 12198 | @Override |
| 12199 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12200 | List<String> featureTags) { |
| 12201 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12202 | "removeUceRegistrationOverrideShell"); |
| 12203 | final long identity = Binder.clearCallingIdentity(); |
| 12204 | try { |
| 12205 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12206 | new ArraySet<>(featureTags)); |
| 12207 | } catch (ImsException e) { |
| 12208 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12209 | } finally { |
| 12210 | Binder.restoreCallingIdentity(identity); |
| 12211 | } |
| 12212 | } |
| 12213 | |
| 12214 | /** |
| 12215 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12216 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12217 | */ |
| 12218 | // Used for SHELL command only right now. |
| 12219 | @Override |
| 12220 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12221 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12222 | "clearUceRegistrationOverrideShell"); |
| 12223 | final long identity = Binder.clearCallingIdentity(); |
| 12224 | try { |
| 12225 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12226 | } catch (ImsException e) { |
| 12227 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12228 | } finally { |
| 12229 | Binder.restoreCallingIdentity(identity); |
| 12230 | } |
| 12231 | } |
| 12232 | |
| 12233 | /** |
| 12234 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12235 | */ |
| 12236 | // Used for SHELL command only right now. |
| 12237 | @Override |
| 12238 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12239 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12240 | "getLatestRcsContactUceCapabilityShell"); |
| 12241 | final long identity = Binder.clearCallingIdentity(); |
| 12242 | try { |
| 12243 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12244 | } catch (ImsException e) { |
| 12245 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12246 | } finally { |
| 12247 | Binder.restoreCallingIdentity(identity); |
| 12248 | } |
| 12249 | } |
| 12250 | |
| 12251 | /** |
| 12252 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12253 | * device does not have an active PUBLISH. |
| 12254 | */ |
| 12255 | // Used for SHELL command only right now. |
| 12256 | @Override |
| 12257 | public String getLastUcePidfXmlShell(int subId) { |
| 12258 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12259 | final long identity = Binder.clearCallingIdentity(); |
| 12260 | try { |
| 12261 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12262 | } catch (ImsException e) { |
| 12263 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12264 | } finally { |
| 12265 | Binder.restoreCallingIdentity(identity); |
| 12266 | } |
| 12267 | } |
| 12268 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12269 | /** |
| 12270 | * Remove UCE requests cannot be sent to the network status. |
| 12271 | */ |
| 12272 | // Used for SHELL command only right now. |
| 12273 | @Override |
| 12274 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12275 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12276 | final long identity = Binder.clearCallingIdentity(); |
| 12277 | try { |
| 12278 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12279 | } catch (ImsException e) { |
| 12280 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12281 | } finally { |
| 12282 | Binder.restoreCallingIdentity(identity); |
| 12283 | } |
| 12284 | } |
| 12285 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12286 | /** |
| 12287 | * Remove UCE requests cannot be sent to the network status. |
| 12288 | */ |
| 12289 | // Used for SHELL command only. |
| 12290 | @Override |
| 12291 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12292 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12293 | final long identity = Binder.clearCallingIdentity(); |
| 12294 | try { |
| 12295 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12296 | } catch (ImsException e) { |
| 12297 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12298 | } finally { |
| 12299 | Binder.restoreCallingIdentity(identity); |
| 12300 | } |
| 12301 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12302 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12303 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12304 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12305 | String callingPackage) { |
| 12306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12307 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12308 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12309 | enforceTelephonyFeatureWithException(callingPackage, |
| 12310 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12311 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12312 | final int callingUid = Binder.getCallingUid(); |
| 12313 | // Verify that tha callingPackage belongs to the calling UID |
| 12314 | mApp.getSystemService(AppOpsManager.class) |
| 12315 | .checkPackage(callingUid, callingPackage); |
| 12316 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12317 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12318 | |
| 12319 | final long identity = Binder.clearCallingIdentity(); |
| 12320 | try { |
| 12321 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12322 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12323 | |
| 12324 | if (result instanceof IllegalStateException) { |
| 12325 | throw (IllegalStateException) result; |
| 12326 | } |
| 12327 | } finally { |
| 12328 | Binder.restoreCallingIdentity(identity); |
| 12329 | } |
| 12330 | } |
| 12331 | |
| 12332 | @Override |
| 12333 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12334 | String callingPackage) { |
| 12335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12336 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12337 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12338 | enforceTelephonyFeatureWithException(callingPackage, |
| 12339 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12340 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12341 | final int callingUid = Binder.getCallingUid(); |
| 12342 | // Verify that tha callingPackage belongs to the calling UID |
| 12343 | mApp.getSystemService(AppOpsManager.class) |
| 12344 | .checkPackage(callingUid, callingPackage); |
| 12345 | |
| 12346 | final long identity = Binder.clearCallingIdentity(); |
| 12347 | try { |
| 12348 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12349 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12350 | |
| 12351 | if (result instanceof IllegalStateException) { |
| 12352 | throw (IllegalStateException) result; |
| 12353 | } |
| 12354 | } finally { |
| 12355 | Binder.restoreCallingIdentity(identity); |
| 12356 | } |
| 12357 | } |
| 12358 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12359 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12360 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12361 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12362 | // phone/system process do not have further restriction on request |
| 12363 | return; |
| 12364 | } |
| 12365 | |
| 12366 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12367 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12368 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12369 | context.enforceCallingOrSelfPermission( |
| 12370 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12371 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12372 | } |
| 12373 | |
| 12374 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12375 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12376 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12377 | || info.isEnabled()) { |
| 12378 | throw new IllegalArgumentException( |
| 12379 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12380 | } |
| 12381 | |
| 12382 | // Thresholds length for each RAN need in range. This has been validated in |
| 12383 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12384 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12385 | final int[] thresholds = info.getThresholds(); |
| 12386 | Objects.requireNonNull(thresholds); |
| 12387 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12388 | || thresholds.length |
| 12389 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12390 | throw new IllegalArgumentException( |
| 12391 | "thresholds length is out of range: " + thresholds.length); |
| 12392 | } |
| 12393 | } |
| 12394 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12395 | |
| 12396 | /** |
| 12397 | * Gets the current phone capability. |
| 12398 | * |
| 12399 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12400 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12401 | * It's used to evaluate possible phone config change, for example from single |
| 12402 | * SIM device to multi-SIM device. |
| 12403 | */ |
| 12404 | @Override |
| 12405 | public PhoneCapability getPhoneCapability() { |
| 12406 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12407 | |
| 12408 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12409 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12410 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12411 | final long identity = Binder.clearCallingIdentity(); |
| 12412 | try { |
| 12413 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12414 | } finally { |
| 12415 | Binder.restoreCallingIdentity(identity); |
| 12416 | } |
| 12417 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12418 | |
| 12419 | /** |
| 12420 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12421 | * required to be done shortly after the API is invoked. |
| 12422 | */ |
| 12423 | @Override |
| 12424 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12425 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12426 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12427 | enforceRebootPermission(); |
| 12428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12430 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12431 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12432 | final long identity = Binder.clearCallingIdentity(); |
| 12433 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12434 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12435 | } finally { |
| 12436 | Binder.restoreCallingIdentity(identity); |
| 12437 | } |
| 12438 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12439 | |
| 12440 | /** |
| 12441 | * Request to get the current slicing configuration including URSP rules and |
| 12442 | * NSSAIs (configured, allowed and rejected). |
| 12443 | * |
| 12444 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12445 | */ |
| 12446 | @Override |
| 12447 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12448 | TelephonyPermissions |
| 12449 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12450 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12451 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12452 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12453 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12454 | "getSlicingConfig"); |
| 12455 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12456 | final long identity = Binder.clearCallingIdentity(); |
| 12457 | try { |
| 12458 | Phone phone = getDefaultPhone(); |
| 12459 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12460 | } finally { |
| 12461 | Binder.restoreCallingIdentity(identity); |
| 12462 | } |
| 12463 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12464 | |
| 12465 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12466 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12467 | * |
| 12468 | * @param capability The premium capability to check. |
| 12469 | * @param subId The subId to check the premium capability for. |
| 12470 | * |
| 12471 | * @return Whether the given premium capability is available to purchase. |
| 12472 | */ |
| 12473 | @Override |
| 12474 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12475 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12476 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12477 | log("Premium capability " |
| 12478 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12479 | + " is not available for purchase due to missing permissions."); |
| 12480 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12481 | + "permission READ_BASIC_PHONE_STATE."); |
| 12482 | } |
| 12483 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12484 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12485 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12486 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12487 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12488 | if (phone == null) { |
| 12489 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12490 | return false; |
| 12491 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12492 | final long identity = Binder.clearCallingIdentity(); |
| 12493 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12494 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12495 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12496 | } finally { |
| 12497 | Binder.restoreCallingIdentity(identity); |
| 12498 | } |
| 12499 | } |
| 12500 | |
| 12501 | /** |
| 12502 | * Purchase the given premium capability from the carrier. |
| 12503 | * |
| 12504 | * @param capability The premium capability to purchase. |
| 12505 | * @param callback The result of the purchase request. |
| 12506 | * @param subId The subId to purchase the premium capability for. |
| 12507 | */ |
| 12508 | @Override |
| 12509 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12510 | log("purchasePremiumCapability: capability=" |
| 12511 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12512 | + getCurrentPackageName()); |
| 12513 | |
| 12514 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12515 | mApp, "purchasePremiumCapability")) { |
| 12516 | log("purchasePremiumCapability " |
| 12517 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12518 | + " failed due to missing permissions."); |
| 12519 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12520 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12521 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12522 | mApp, "purchasePremiumCapability")) { |
| 12523 | log("purchasePremiumCapability " |
| 12524 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12525 | + " failed due to missing permissions."); |
| 12526 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12527 | } |
| 12528 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12529 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12530 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12531 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12532 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12533 | if (phone == null) { |
| 12534 | try { |
| 12535 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12536 | callback.accept(result); |
| 12537 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12538 | } catch (RemoteException e) { |
| 12539 | String logStr = "Purchase premium capability " |
| 12540 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12541 | + " failed due to RemoteException handling null phone: " + e; |
| 12542 | if (DBG) log(logStr); |
| 12543 | AnomalyReporter.reportAnomaly( |
| 12544 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12545 | } |
| 12546 | return; |
| 12547 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12548 | |
| 12549 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12550 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12551 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12552 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12553 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12554 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12555 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12556 | |
| 12557 | boolean isVisible = false; |
| 12558 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12559 | if (am != null) { |
| 12560 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12561 | if (processes != null) { |
| 12562 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12563 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12564 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12565 | if (process.processName.equals(callingProcess) && process.importance |
| 12566 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12567 | isVisible = true; |
| 12568 | break; |
| 12569 | } |
| 12570 | } |
| 12571 | } |
| 12572 | } |
| 12573 | |
| 12574 | if (!isVisible) { |
| 12575 | try { |
| 12576 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12577 | callback.accept(result); |
| 12578 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12579 | } catch (RemoteException e) { |
| 12580 | String logStr = "Purchase premium capability " |
| 12581 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12582 | + " failed due to RemoteException handling background application: " + e; |
| 12583 | if (DBG) log(logStr); |
| 12584 | AnomalyReporter.reportAnomaly( |
| 12585 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12586 | } |
| 12587 | return; |
| 12588 | } |
| 12589 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12590 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12591 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12592 | } |
| 12593 | |
| 12594 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12595 | * Register an IMS connection state callback |
| 12596 | */ |
| 12597 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12598 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12599 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12600 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12601 | // ImsMmTelManager |
| 12602 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12603 | TelephonyPermissions |
| 12604 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12605 | mApp, subId, "registerImsStateCallback"); |
| 12606 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12607 | // ImsRcsManager or SipDelegateManager |
| 12608 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12609 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12610 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12611 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12612 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12613 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12614 | } |
| 12615 | |
| 12616 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12617 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12618 | "IMS not available on device."); |
| 12619 | } |
| 12620 | |
| 12621 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12622 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12623 | } |
| 12624 | |
| 12625 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12626 | if (controller == null) { |
| 12627 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12628 | "IMS not available on device."); |
| 12629 | } |
| 12630 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12631 | if (callingPackage == null) { |
| 12632 | callingPackage = getCurrentPackageName(); |
| 12633 | } |
| 12634 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12635 | final long token = Binder.clearCallingIdentity(); |
| 12636 | try { |
| 12637 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12638 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12639 | } catch (ImsException e) { |
| 12640 | throw new ServiceSpecificException(e.getCode()); |
| 12641 | } finally { |
| 12642 | Binder.restoreCallingIdentity(token); |
| 12643 | } |
| 12644 | } |
| 12645 | |
| 12646 | /** |
| 12647 | * Unregister an IMS connection state callback |
| 12648 | */ |
| 12649 | @Override |
| 12650 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12651 | final long token = Binder.clearCallingIdentity(); |
| 12652 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12653 | if (controller == null) { |
| 12654 | return; |
| 12655 | } |
| 12656 | try { |
| 12657 | controller.unregisterImsStateCallback(cb); |
| 12658 | } finally { |
| 12659 | Binder.restoreCallingIdentity(token); |
| 12660 | } |
| 12661 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12662 | |
| 12663 | /** |
| 12664 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12665 | * |
| 12666 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12667 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12668 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12669 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12670 | * If there is current registered network this value will be same as the registered cell |
| 12671 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12672 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12673 | * it will be cleared and null will be returned. |
| 12674 | * |
| 12675 | */ |
| 12676 | @Override |
| 12677 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12678 | String callingFeatureId) { |
| 12679 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12680 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12681 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12682 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12683 | .setCallingPackage(callingPackage) |
| 12684 | .setCallingFeatureId(callingFeatureId) |
| 12685 | .setCallingPid(Binder.getCallingPid()) |
| 12686 | .setCallingUid(Binder.getCallingUid()) |
| 12687 | .setMethod("getLastKnownCellIdentity") |
| 12688 | .setLogAsInfo(true) |
| 12689 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12690 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12691 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12692 | .build()); |
| 12693 | |
| 12694 | boolean hasFinePermission = |
| 12695 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12696 | if (!hasFinePermission |
| 12697 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12698 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12699 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12700 | } |
| 12701 | |
| 12702 | final long identity = Binder.clearCallingIdentity(); |
| 12703 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12704 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12705 | if (sst == null) return null; |
| 12706 | return sst.getLastKnownCellIdentity(); |
| 12707 | } finally { |
| 12708 | Binder.restoreCallingIdentity(identity); |
| 12709 | } |
| 12710 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12711 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12712 | /** |
| 12713 | * Sets the modem service class Name that Telephony will bind to. |
| 12714 | * |
| 12715 | * @param serviceName The class name of the modem service. |
| 12716 | * @return true if the operation is succeed, otherwise false. |
| 12717 | */ |
| 12718 | public boolean setModemService(String serviceName) { |
| 12719 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12720 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12722 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12723 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12724 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12725 | } |
| 12726 | |
| 12727 | /** |
| 12728 | * Return the class name of the currently bounded modem service. |
| 12729 | * |
| 12730 | * @return the class name of the modem service. |
| 12731 | */ |
| 12732 | public String getModemService() { |
| 12733 | String result; |
| 12734 | Log.d(LOG_TAG, "getModemService"); |
| 12735 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12736 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12737 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12738 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12739 | "getModemService"); |
| 12740 | result = mPhoneConfigurationManager.getModemService(); |
| 12741 | Log.d(LOG_TAG, "result = " + result); |
| 12742 | return result; |
| 12743 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12744 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12745 | /** |
| 12746 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12747 | * including carrier config, entitlement server, and config update. |
| 12748 | * |
| 12749 | * @param subId subId The subscription ID of the carrier. |
| 12750 | * |
| 12751 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12752 | * be returned. |
| 12753 | * |
| 12754 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12755 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12756 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12757 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12758 | final long identity = Binder.clearCallingIdentity(); |
| 12759 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12760 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12761 | } finally { |
| 12762 | Binder.restoreCallingIdentity(identity); |
| 12763 | } |
| 12764 | } |
| 12765 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12766 | @Override |
| 12767 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12768 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12769 | mApp.enforceCallingOrSelfPermission( |
| 12770 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12771 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12772 | |
| 12773 | final long identity = Binder.clearCallingIdentity(); |
| 12774 | try { |
| 12775 | Phone phone = getPhone(subId); |
| 12776 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12777 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12778 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12779 | phone.setVoiceServiceStateOverride(hasService); |
| 12780 | } finally { |
| 12781 | Binder.restoreCallingIdentity(identity); |
| 12782 | } |
| 12783 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12784 | |
| 12785 | /** |
| 12786 | * set removable eSIM as default eUICC. |
| 12787 | * |
| 12788 | * @hide |
| 12789 | */ |
| 12790 | @Override |
| 12791 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12792 | enforceModifyPermission(); |
| 12793 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12794 | |
| 12795 | final long identity = Binder.clearCallingIdentity(); |
| 12796 | try { |
| 12797 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12798 | } finally { |
| 12799 | Binder.restoreCallingIdentity(identity); |
| 12800 | } |
| 12801 | } |
| 12802 | |
| 12803 | /** |
| 12804 | * Returns whether the removable eSIM is default eUICC or not. |
| 12805 | * |
| 12806 | * @hide |
| 12807 | */ |
| 12808 | @Override |
| 12809 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12810 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12811 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12812 | |
| 12813 | final long identity = Binder.clearCallingIdentity(); |
| 12814 | try { |
| 12815 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12816 | } finally { |
| 12817 | Binder.restoreCallingIdentity(identity); |
| 12818 | } |
| 12819 | } |
| 12820 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12821 | /** |
| 12822 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12823 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12824 | * application currently configured for this user. |
| 12825 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12826 | * {@code null} if the functionality is not supported. |
| 12827 | * @hide |
| 12828 | */ |
| 12829 | @Override |
| 12830 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12831 | boolean updateIfNeeded) { |
| 12832 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12833 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12834 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12835 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12836 | "getDefaultRespondViaMessageApplication"); |
| 12837 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12838 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12839 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12840 | UserHandle userHandle = null; |
| 12841 | final long identity = Binder.clearCallingIdentity(); |
| 12842 | try { |
| 12843 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12844 | } finally { |
| 12845 | Binder.restoreCallingIdentity(identity); |
| 12846 | } |
| 12847 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12848 | updateIfNeeded, userHandle); |
| 12849 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12850 | |
| 12851 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12852 | * Set whether the device is able to connect with null ciphering or integrity |
| 12853 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12854 | * and all new subscriptions after this. |
| 12855 | * |
| 12856 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12857 | * @hide |
| 12858 | */ |
| 12859 | @Override |
| 12860 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12861 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12862 | enforceModifyPermission(); |
| 12863 | checkForNullCipherAndIntegritySupport(); |
| 12864 | |
| 12865 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12866 | // for listening to these preference changes and applying them immediately. |
| 12867 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12868 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12869 | editor.apply(); |
| 12870 | |
| 12871 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12872 | phone.handleNullCipherEnabledChange(); |
| 12873 | } |
| 12874 | } |
| 12875 | |
| 12876 | |
| 12877 | /** |
| 12878 | * Get whether the device is able to connect with null ciphering or integrity |
| 12879 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12880 | * the state of the radio. |
| 12881 | * |
| 12882 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12883 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12884 | * version for this feature. |
| 12885 | * @hide |
| 12886 | */ |
| 12887 | @Override |
| 12888 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12889 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12890 | enforceReadPermission(); |
| 12891 | checkForNullCipherAndIntegritySupport(); |
| 12892 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12893 | } |
| 12894 | |
| 12895 | private void checkForNullCipherAndIntegritySupport() { |
| 12896 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12897 | throw new UnsupportedOperationException( |
| 12898 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12899 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12900 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12901 | throw new UnsupportedOperationException( |
| 12902 | "Null cipher and integrity operations unsupported by modem"); |
| 12903 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12904 | } |
| 12905 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12906 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12907 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12908 | throw new UnsupportedOperationException( |
| 12909 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12910 | + "above"); |
| 12911 | } |
| 12912 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12913 | throw new UnsupportedOperationException( |
| 12914 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12915 | } |
| 12916 | } |
| 12917 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12918 | private void checkForNullCipherNotificationSupport() { |
| 12919 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12920 | throw new UnsupportedOperationException( |
| 12921 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12922 | } |
| 12923 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12924 | throw new UnsupportedOperationException( |
| 12925 | "Null cipher notification operations unsupported by modem"); |
| 12926 | } |
| 12927 | } |
| 12928 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12929 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12930 | * Get the SIM state for the slot index. |
| 12931 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12932 | * |
| 12933 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12934 | */ |
| 12935 | @Override |
| 12936 | @SimState |
| 12937 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 12938 | if (!mApp.getResources().getBoolean( |
| 12939 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 12940 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12941 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12942 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12943 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12944 | IccCardConstants.State simState; |
| 12945 | if (slotIndex < 0) { |
| 12946 | simState = IccCardConstants.State.UNKNOWN; |
| 12947 | } else { |
| 12948 | Phone phone = null; |
| 12949 | try { |
| 12950 | phone = PhoneFactory.getPhone(slotIndex); |
| 12951 | } catch (IllegalStateException e) { |
| 12952 | // ignore |
| 12953 | } |
| 12954 | if (phone == null) { |
| 12955 | simState = IccCardConstants.State.UNKNOWN; |
| 12956 | } else { |
| 12957 | IccCard icc = phone.getIccCard(); |
| 12958 | if (icc == null) { |
| 12959 | simState = IccCardConstants.State.UNKNOWN; |
| 12960 | } else { |
| 12961 | simState = icc.getState(); |
| 12962 | } |
| 12963 | } |
| 12964 | } |
| 12965 | return simState.ordinal(); |
| 12966 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12967 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12968 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12969 | boolean enableLogcat, |
| 12970 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12971 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12972 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12973 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12974 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12975 | ecdDataBuilder |
| 12976 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12977 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12978 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12979 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12980 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12981 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12982 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12983 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12984 | Executors.newCachedThreadPool(), db, |
| 12985 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12986 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12987 | } |
| 12988 | |
| 12989 | /** |
| 12990 | * Request telephony to persist state for debugging emergency call failures. |
| 12991 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12992 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12993 | * @param enableLogcat whether to collect logcat output |
| 12994 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12995 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12996 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12997 | */ |
| 12998 | @Override |
| 12999 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13000 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13001 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13002 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13003 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13004 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13005 | && Flags.enableReadDropboxPermission()) { |
| 13006 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13007 | "persistEmergencyCallDiagnosticData"); |
| 13008 | } else { |
| 13009 | // Otherwise, enforce legacy permission. |
| 13010 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13011 | "persistEmergencyCallDiagnosticData"); |
| 13012 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13013 | final long identity = Binder.clearCallingIdentity(); |
| 13014 | try { |
| 13015 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13016 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13017 | |
| 13018 | } finally { |
| 13019 | Binder.restoreCallingIdentity(identity); |
| 13020 | } |
| 13021 | } |
| 13022 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13023 | /** |
| 13024 | * Get current cell broadcast ranges. |
| 13025 | */ |
| 13026 | @Override |
| 13027 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13028 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13029 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13030 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13031 | |
| 13032 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13033 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13034 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13035 | final long identity = Binder.clearCallingIdentity(); |
| 13036 | try { |
| 13037 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13038 | } finally { |
| 13039 | Binder.restoreCallingIdentity(identity); |
| 13040 | } |
| 13041 | } |
| 13042 | |
| 13043 | /** |
| 13044 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13045 | * |
| 13046 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13047 | */ |
| 13048 | @Override |
| 13049 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13050 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13051 | @Nullable IIntegerConsumer callback) { |
| 13052 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13053 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13054 | |
| 13055 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13056 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13057 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13058 | final long identity = Binder.clearCallingIdentity(); |
| 13059 | try { |
| 13060 | Phone phone = getPhoneFromSubId(subId); |
| 13061 | if (DBG) { |
| 13062 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13063 | } |
| 13064 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13065 | if (callback != null) { |
| 13066 | try { |
| 13067 | callback.accept(result); |
| 13068 | } catch (RemoteException e) { |
| 13069 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13070 | } |
| 13071 | } |
| 13072 | }); |
| 13073 | } finally { |
| 13074 | Binder.restoreCallingIdentity(identity); |
| 13075 | } |
| 13076 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13077 | |
| 13078 | /** |
| 13079 | * Returns whether the device supports the domain selection service. |
| 13080 | * |
| 13081 | * @return {@code true} if the device supports the domain selection service. |
| 13082 | */ |
| 13083 | @Override |
| 13084 | public boolean isDomainSelectionSupported() { |
| 13085 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13086 | "isDomainSelectionSupported"); |
| 13087 | |
| 13088 | final long identity = Binder.clearCallingIdentity(); |
| 13089 | try { |
| 13090 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13091 | } finally { |
| 13092 | Binder.restoreCallingIdentity(identity); |
| 13093 | } |
| 13094 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13095 | |
| 13096 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13097 | * Returns whether the AOSP domain selection service is supported. |
| 13098 | * |
| 13099 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13100 | * {@code false} otherwise. |
| 13101 | */ |
| 13102 | @Override |
| 13103 | public boolean isAospDomainSelectionService() { |
| 13104 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13105 | "isAospDomainSelectionService"); |
| 13106 | |
| 13107 | final long identity = Binder.clearCallingIdentity(); |
| 13108 | try { |
| 13109 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13110 | String dssComponentName = mApp.getResources().getString( |
| 13111 | R.string.config_domain_selection_service_component_name); |
| 13112 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13113 | TelephonyDomainSelectionService.class.getName()); |
| 13114 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13115 | + ", aosp=" + componentName.flattenToString()); |
| 13116 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13117 | } |
| 13118 | } finally { |
| 13119 | Binder.restoreCallingIdentity(identity); |
| 13120 | } |
| 13121 | return false; |
| 13122 | } |
| 13123 | |
| 13124 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13125 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13126 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13127 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13128 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13129 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13130 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13131 | * {@code false} to disable. |
| 13132 | * @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] | 13133 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13134 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13135 | * |
| 13136 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13137 | */ |
| 13138 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13139 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13140 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13141 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13142 | if (enableSatellite) { |
| 13143 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13144 | @Override |
| 13145 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13146 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13147 | + ", resultData=" + resultData); |
| 13148 | boolean isAllowed = false; |
| 13149 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13150 | callback::accept); |
| 13151 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13152 | if (resultData != null |
| 13153 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13154 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13155 | } else { |
| 13156 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13157 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13158 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13159 | result.accept(resultCode); |
| 13160 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13161 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13162 | if (isAllowed) { |
| 13163 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13164 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13165 | } else { |
| 13166 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13167 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13168 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13169 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13170 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13171 | subId, resultReceiver); |
| 13172 | } else { |
| 13173 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13174 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13175 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13176 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13177 | } |
| 13178 | |
| 13179 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13180 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13181 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13182 | * @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] | 13183 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13184 | * 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] | 13185 | * |
| 13186 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13187 | */ |
| 13188 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13189 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13190 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13191 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13192 | } |
| 13193 | |
| 13194 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13195 | * Request to get whether the satellite service demo mode is enabled. |
| 13196 | * |
| 13197 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13198 | * is enabled for. |
| 13199 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13200 | * if the request is successful or an error code if the request failed. |
| 13201 | * |
| 13202 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13203 | */ |
| 13204 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13205 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13206 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13207 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13208 | } |
| 13209 | |
| 13210 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13211 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13212 | * |
| 13213 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13214 | * is enabled for. |
| 13215 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13216 | * enabled if the request is successful or an error code if the request failed. |
| 13217 | * |
| 13218 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13219 | */ |
| 13220 | @Override |
| 13221 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13222 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
joonhunshin | fd78fd5 | 2024-07-11 05:28:13 +0000 | [diff] [blame] | 13223 | mSatelliteController.requestIsEmergencyModeEnabled(subId, result); |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13224 | } |
| 13225 | |
| 13226 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13227 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13228 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13229 | * @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] | 13230 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13231 | * 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] | 13232 | */ |
| 13233 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13234 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13235 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13236 | } |
| 13237 | |
| 13238 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13239 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13240 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13241 | * @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] | 13242 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13243 | * 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] | 13244 | * |
| 13245 | * @throws SecurityException if the caller doesn't have required permission. |
| 13246 | */ |
| 13247 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13248 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13249 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13250 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13251 | } |
| 13252 | |
| 13253 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13254 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13255 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13256 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13257 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13258 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13259 | * @param resultCallback The callback to get the result of the request. |
| 13260 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13261 | * |
| 13262 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13263 | */ |
| 13264 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13265 | public void startSatelliteTransmissionUpdates(int subId, |
| 13266 | @NonNull IIntegerConsumer resultCallback, |
| 13267 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13268 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13269 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13270 | } |
| 13271 | |
| 13272 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13273 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13274 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13275 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13276 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13277 | * @param resultCallback The callback to get the result of the request. |
| 13278 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13279 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13280 | * |
| 13281 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13282 | */ |
| 13283 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13284 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13285 | @NonNull IIntegerConsumer resultCallback, |
| 13286 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13287 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13288 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13289 | } |
| 13290 | |
| 13291 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13292 | * Register the subscription with a satellite provider. |
| 13293 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13294 | * |
| 13295 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13296 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13297 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13298 | * @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] | 13299 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13300 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13301 | * @return The signal transport used by the caller to cancel the provision request, |
| 13302 | * or {@code null} if the request failed. |
| 13303 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13304 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13305 | */ |
| 13306 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13307 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13308 | @NonNull String token, @NonNull byte[] provisionData, |
| 13309 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13310 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13311 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13312 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13313 | } |
| 13314 | |
| 13315 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13316 | * Unregister the device/subscription with the satellite provider. |
| 13317 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13318 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13319 | * should report as deprovisioned. |
| 13320 | * |
| 13321 | * @param subId The subId of the subscription to be deprovisioned. |
| 13322 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13323 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13324 | * |
| 13325 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13326 | */ |
| 13327 | @Override |
| 13328 | public void deprovisionSatelliteService(int subId, |
| 13329 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13330 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13331 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13332 | } |
| 13333 | |
| 13334 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13335 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13336 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13337 | * @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] | 13338 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13339 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13340 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13341 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13342 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13343 | */ |
| 13344 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13345 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13346 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13347 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13348 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13349 | } |
| 13350 | |
| 13351 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13352 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13353 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13354 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13355 | * @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] | 13356 | * @param callback The callback that was passed to |
| 13357 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13358 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13359 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13360 | */ |
| 13361 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13362 | public void unregisterForSatelliteProvisionStateChanged( |
| 13363 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13364 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13365 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13366 | } |
| 13367 | |
| 13368 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13369 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13370 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13371 | * @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] | 13372 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13373 | * satellite provider if the request is successful or an error code if the |
| 13374 | * request failed. |
| 13375 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13376 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13377 | */ |
| 13378 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13379 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13380 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13381 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13382 | } |
| 13383 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13384 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13385 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13386 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13387 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13388 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13389 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13390 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13391 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13392 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13393 | */ |
| 13394 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13395 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13396 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13397 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13398 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13399 | } |
| 13400 | |
| 13401 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13402 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13403 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13404 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13405 | * @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] | 13406 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13407 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13408 | * |
| 13409 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13410 | */ |
| 13411 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13412 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13413 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13414 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13415 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13416 | } |
| 13417 | |
| 13418 | /** |
| 13419 | * Register to receive incoming datagrams over satellite. |
| 13420 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13421 | * @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] | 13422 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13423 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13424 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13425 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13426 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13427 | */ |
| 13428 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13429 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13430 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13431 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13432 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13433 | } |
| 13434 | |
| 13435 | /** |
| 13436 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13437 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13438 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13439 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13440 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13441 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13442 | * |
| 13443 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13444 | */ |
| 13445 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13446 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13447 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13448 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13449 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13450 | } |
| 13451 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13452 | /** |
| 13453 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13454 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13455 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13456 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13457 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13458 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13459 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13460 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13461 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13462 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13463 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13464 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13465 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13466 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13467 | } |
| 13468 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13469 | /** |
| 13470 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13471 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13472 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13473 | * input to this method. Datagram received here will be passed down to modem without any |
| 13474 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13475 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13476 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13477 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13478 | * SOS_SMS or LOCATION_SHARING. |
| 13479 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13480 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13481 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13482 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13483 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13484 | * |
| 13485 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13486 | */ |
| 13487 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13488 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13489 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13490 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13491 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13492 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13493 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13494 | } |
| 13495 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13496 | /** |
| 13497 | * Request to get whether satellite communication is allowed for the current location. |
| 13498 | * |
| 13499 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13500 | * allowed for the current location for. |
| 13501 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13502 | * for the current location if the request is successful or an error code |
| 13503 | * if the request failed. |
| 13504 | * |
| 13505 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13506 | */ |
| 13507 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13508 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13509 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13510 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13511 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13512 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13513 | } |
| 13514 | |
| 13515 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13516 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13517 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13518 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13519 | * @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] | 13520 | * be visible if the request is successful or an error code if the request failed. |
| 13521 | * |
| 13522 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13523 | */ |
| 13524 | @Override |
| 13525 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13526 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13527 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13528 | } |
| 13529 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13530 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13531 | * Inform that Device is aligned to satellite for demo mode. |
| 13532 | * |
| 13533 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13534 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13535 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13536 | * |
| 13537 | * @throws SecurityException if the caller doesn't have required permission. |
| 13538 | */ |
| 13539 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13540 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13541 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13542 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13543 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13544 | } |
| 13545 | |
| 13546 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13547 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13548 | * by modem. |
| 13549 | * |
| 13550 | * @param subId The subId of the subscription to request for. |
| 13551 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13552 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13553 | * operation. |
| 13554 | * |
| 13555 | * @throws SecurityException if the caller doesn't have required permission. |
| 13556 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13557 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13558 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13559 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13560 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13561 | final long identity = Binder.clearCallingIdentity(); |
| 13562 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13563 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13564 | } finally { |
| 13565 | Binder.restoreCallingIdentity(identity); |
| 13566 | } |
| 13567 | } |
| 13568 | |
| 13569 | /** |
| 13570 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13571 | * by modem. |
| 13572 | * |
| 13573 | * @param subId The subId of the subscription to request for. |
| 13574 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13575 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13576 | * operation. |
| 13577 | * |
| 13578 | * @throws SecurityException if the caller doesn't have required permission. |
| 13579 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13580 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13581 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13582 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13583 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13584 | final long identity = Binder.clearCallingIdentity(); |
| 13585 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13586 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13587 | } finally { |
| 13588 | Binder.restoreCallingIdentity(identity); |
| 13589 | } |
| 13590 | } |
| 13591 | |
| 13592 | /** |
| 13593 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13594 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13595 | * |
| 13596 | * @param subId The subId of the subscription to request for. |
| 13597 | * |
| 13598 | * @return Integer array of reasons for disallowing satellite communication. |
| 13599 | * |
| 13600 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13601 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13602 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13603 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13604 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13605 | final long identity = Binder.clearCallingIdentity(); |
| 13606 | try { |
| 13607 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13608 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13609 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13610 | } finally { |
| 13611 | Binder.restoreCallingIdentity(identity); |
| 13612 | } |
| 13613 | } |
| 13614 | |
| 13615 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13616 | * Request to get the signal strength of the satellite connection. |
| 13617 | * |
| 13618 | * @param subId The subId of the subscription to request for. |
| 13619 | * @param result Result receiver to get the error code of the request and the current signal |
| 13620 | * strength of the satellite connection. |
| 13621 | * |
| 13622 | * @throws SecurityException if the caller doesn't have required permission. |
| 13623 | */ |
| 13624 | @Override |
| 13625 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13626 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13627 | final long identity = Binder.clearCallingIdentity(); |
| 13628 | try { |
| 13629 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13630 | } finally { |
| 13631 | Binder.restoreCallingIdentity(identity); |
| 13632 | } |
| 13633 | } |
| 13634 | |
| 13635 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13636 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13637 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13638 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13639 | * |
| 13640 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13641 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13642 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13643 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13644 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13645 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13646 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13647 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13648 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13649 | */ |
| 13650 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13651 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13652 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13653 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13654 | final long identity = Binder.clearCallingIdentity(); |
| 13655 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13656 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13657 | } finally { |
| 13658 | Binder.restoreCallingIdentity(identity); |
| 13659 | } |
| 13660 | } |
| 13661 | |
| 13662 | /** |
| 13663 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13664 | * If callback was not registered before, the request will be ignored. |
| 13665 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13666 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13667 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13668 | * @param callback The callback that was passed to |
| 13669 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13670 | * |
| 13671 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13672 | */ |
| 13673 | @Override |
| 13674 | public void unregisterForNtnSignalStrengthChanged( |
| 13675 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13676 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13677 | final long identity = Binder.clearCallingIdentity(); |
| 13678 | try { |
| 13679 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13680 | } finally { |
| 13681 | Binder.restoreCallingIdentity(identity); |
| 13682 | } |
| 13683 | } |
| 13684 | |
| 13685 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13686 | * Registers for satellite capabilities change event from the satellite service. |
| 13687 | * |
| 13688 | * @param subId The subId of the subscription to request for. |
| 13689 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13690 | * |
| 13691 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13692 | * |
| 13693 | * @throws SecurityException if the caller doesn't have required permission. |
| 13694 | */ |
| 13695 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13696 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13697 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13698 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13699 | final long identity = Binder.clearCallingIdentity(); |
| 13700 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13701 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13702 | } finally { |
| 13703 | Binder.restoreCallingIdentity(identity); |
| 13704 | } |
| 13705 | } |
| 13706 | |
| 13707 | /** |
| 13708 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13709 | * If callback was not registered before, the request will be ignored. |
| 13710 | * |
| 13711 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13712 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13713 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13714 | * |
| 13715 | * @throws SecurityException if the caller doesn't have required permission. |
| 13716 | */ |
| 13717 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13718 | public void unregisterForCapabilitiesChanged(int subId, |
| 13719 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13720 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13721 | final long identity = Binder.clearCallingIdentity(); |
| 13722 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13723 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13724 | } finally { |
| 13725 | Binder.restoreCallingIdentity(identity); |
| 13726 | } |
| 13727 | } |
| 13728 | |
| 13729 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13730 | * Registers for the satellite supported state changed. |
| 13731 | * |
| 13732 | * @param subId The subId of the subscription to register for supported state changed. |
| 13733 | * @param callback The callback to handle the satellite supported state changed event. |
| 13734 | * |
| 13735 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13736 | * |
| 13737 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13738 | */ |
| 13739 | @Override |
| 13740 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13741 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13742 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13743 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13744 | } |
| 13745 | |
| 13746 | /** |
| 13747 | * Unregisters for the satellite supported state changed. |
| 13748 | * If callback was not registered before, the request will be ignored. |
| 13749 | * |
| 13750 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13751 | * @param callback The callback that was passed to |
| 13752 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13753 | * |
| 13754 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13755 | */ |
| 13756 | @Override |
| 13757 | public void unregisterForSatelliteSupportedStateChanged( |
| 13758 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13759 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13760 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13761 | } |
| 13762 | |
| 13763 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13764 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13765 | * |
| 13766 | * @param servicePackageName The package name of the satellite vendor service. |
| 13767 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13768 | * {@code false} otherwise. |
| 13769 | */ |
| 13770 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13771 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13772 | TelephonyPermissions.enforceShellOnly( |
| 13773 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13775 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13776 | "setSatelliteServicePackageName"); |
| 13777 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13778 | } |
| 13779 | |
| 13780 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13781 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13782 | * |
| 13783 | * @param servicePackageName The package name of the satellite gateway service. |
| 13784 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13785 | * {@code false} otherwise. |
| 13786 | */ |
| 13787 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13788 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13789 | TelephonyPermissions.enforceShellOnly( |
| 13790 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13792 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13793 | "setSatelliteGatewayServicePackageName"); |
| 13794 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13795 | } |
| 13796 | |
| 13797 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13798 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13799 | * |
| 13800 | * @param packageName The package name of the satellite pointing UI app. |
| 13801 | * @param className The class name of the satellite pointing UI app. |
| 13802 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13803 | * {@code false} otherwise. |
| 13804 | */ |
| 13805 | public boolean setSatellitePointingUiClassName( |
| 13806 | @Nullable String packageName, @Nullable String className) { |
| 13807 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13808 | + ", className=" + className); |
| 13809 | TelephonyPermissions.enforceShellOnly( |
| 13810 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13812 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13813 | "setSatelliteGatewayServicePackageName"); |
| 13814 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13815 | } |
| 13816 | |
| 13817 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13818 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13819 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13820 | * listening mode. |
| 13821 | * |
| 13822 | * @param timeoutMillis The timeout duration in millisecond. |
| 13823 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13824 | */ |
| 13825 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13826 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13827 | TelephonyPermissions.enforceShellOnly( |
| 13828 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13830 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13831 | "setSatelliteListeningTimeoutDuration"); |
| 13832 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13833 | } |
| 13834 | |
| 13835 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13836 | * This API can be used by only CTS to override the timeout durations used by the |
| 13837 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13838 | * |
| 13839 | * @param timeoutMillis The timeout duration in millisecond. |
| 13840 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13841 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13842 | public boolean setDatagramControllerTimeoutDuration( |
| 13843 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13844 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13845 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13846 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13847 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13849 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13850 | "setDatagramControllerTimeoutDuration"); |
| 13851 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13852 | reset, timeoutType, timeoutMillis); |
| 13853 | } |
| 13854 | |
| 13855 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 13856 | * This API can be used by only CTS to override the boolean configs used by the |
| 13857 | * DatagramController module. |
| 13858 | * |
| 13859 | * @param enable Whether to enable or disable boolean config. |
| 13860 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 13861 | */ |
| 13862 | public boolean setDatagramControllerBooleanConfig( |
| 13863 | boolean reset, int booleanType, boolean enable) { |
| 13864 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 13865 | + ", reset=" + reset + ", enable=" + enable); |
| 13866 | TelephonyPermissions.enforceShellOnly( |
| 13867 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 13868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13869 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13870 | "ssetDatagramControllerBooleanConfig"); |
| 13871 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable); |
| 13872 | } |
| 13873 | |
| 13874 | |
| 13875 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13876 | * This API can be used by only CTS to override the timeout durations used by the |
| 13877 | * SatelliteController module. |
| 13878 | * |
| 13879 | * @param timeoutMillis The timeout duration in millisecond. |
| 13880 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13881 | */ |
| 13882 | public boolean setSatelliteControllerTimeoutDuration( |
| 13883 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13884 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13885 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13886 | TelephonyPermissions.enforceShellOnly( |
| 13887 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13889 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13890 | "setSatelliteControllerTimeoutDuration"); |
| 13891 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13892 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13893 | } |
| 13894 | |
| 13895 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13896 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13897 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13898 | * |
| 13899 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13900 | * of the following values to enable the override: |
| 13901 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13902 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13903 | * To disable the override, use -1 for handoverType. |
| 13904 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13905 | * delaySeconds after the emergency call starts. |
| 13906 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13907 | */ |
| 13908 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13909 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13910 | TelephonyPermissions.enforceShellOnly( |
| 13911 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13913 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13914 | "setEmergencyCallToSatelliteHandoverType"); |
| 13915 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13916 | handoverType, delaySeconds); |
| 13917 | } |
| 13918 | |
| 13919 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13920 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13921 | * |
| 13922 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13923 | * otherwise. |
| 13924 | * @param isProvisioned The overriding provision status. |
| 13925 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13926 | */ |
| 13927 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13928 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13929 | + ", isProvisioned=" + isProvisioned); |
| 13930 | TelephonyPermissions.enforceShellOnly( |
| 13931 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13933 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13934 | "setOemEnabledSatelliteProvisionStatus"); |
| 13935 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13936 | } |
| 13937 | |
| 13938 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13939 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13940 | * |
| 13941 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13942 | */ |
| 13943 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13944 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13945 | long locationCountryCodeTimestampNanos) { |
| 13946 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13947 | + String.join(", ", currentNetworkCountryCodes) |
| 13948 | + ", locationCountryCode=" + locationCountryCode |
| 13949 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13950 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13951 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13952 | TelephonyPermissions.enforceShellOnly( |
| 13953 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13954 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13955 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13956 | "setCachedLocationCountryCode"); |
| 13957 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13958 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13959 | locationCountryCodeTimestampNanos); |
| 13960 | } |
| 13961 | |
| 13962 | /** |
| 13963 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13964 | * access controller. |
| 13965 | * |
| 13966 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13967 | * otherwise. |
| 13968 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13969 | */ |
| 13970 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13971 | String s2CellFile, long locationFreshDurationNanos, |
| 13972 | List<String> satelliteCountryCodes) { |
| 13973 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13974 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13975 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13976 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13977 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13978 | TelephonyPermissions.enforceShellOnly( |
| 13979 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13980 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13981 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13982 | "setSatelliteAccessControlOverlayConfigs"); |
| 13983 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13984 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13985 | } |
| 13986 | |
| 13987 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13988 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13989 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13990 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13991 | * |
| 13992 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13993 | * satellite modem or not. |
| 13994 | * |
| 13995 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13996 | */ |
| 13997 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13998 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13999 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14000 | + "disabled"); |
| 14001 | return false; |
| 14002 | } |
| 14003 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14004 | TelephonyPermissions.enforceShellOnly( |
| 14005 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14007 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14008 | "setShouldSendDatagramToModemInDemoMode"); |
| 14009 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14010 | shouldSendToModemInDemoMode); |
| 14011 | } |
| 14012 | |
| 14013 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14014 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14015 | * |
| 14016 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14017 | * the allowed state. |
| 14018 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14019 | */ |
| 14020 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14021 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14022 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14023 | + "oemEnabledSatelliteFlag is disabled"); |
| 14024 | return false; |
| 14025 | } |
| 14026 | |
| 14027 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14028 | + "state=" + state); |
| 14029 | TelephonyPermissions.enforceShellOnly( |
| 14030 | Binder.getCallingUid(), |
| 14031 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14033 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14034 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14035 | return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache( |
| 14036 | state); |
| 14037 | } |
| 14038 | |
| 14039 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14040 | * Sets the service defined in ComponentName to be bound. |
| 14041 | * |
| 14042 | * This should only be used for testing. |
| 14043 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14044 | * {@code false} otherwise. |
| 14045 | */ |
| 14046 | @Override |
| 14047 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14048 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14049 | |
| 14050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14051 | "setDomainSelectionServiceOverride"); |
| 14052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14053 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14054 | |
| 14055 | final long identity = Binder.clearCallingIdentity(); |
| 14056 | try { |
| 14057 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14058 | return DomainSelectionResolver.getInstance() |
| 14059 | .setDomainSelectionServiceOverride(componentName); |
| 14060 | } |
| 14061 | } finally { |
| 14062 | Binder.restoreCallingIdentity(identity); |
| 14063 | } |
| 14064 | return false; |
| 14065 | } |
| 14066 | |
| 14067 | /** |
| 14068 | * Clears the DomainSelectionService override. |
| 14069 | * |
| 14070 | * This should only be used for testing. |
| 14071 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14072 | * {@code false} otherwise. |
| 14073 | */ |
| 14074 | @Override |
| 14075 | public boolean clearDomainSelectionServiceOverride() { |
| 14076 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14077 | |
| 14078 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14079 | "clearDomainSelectionServiceOverride"); |
| 14080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14081 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14082 | |
| 14083 | final long identity = Binder.clearCallingIdentity(); |
| 14084 | try { |
| 14085 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14086 | return DomainSelectionResolver.getInstance() |
| 14087 | .clearDomainSelectionServiceOverride(); |
| 14088 | } |
| 14089 | } finally { |
| 14090 | Binder.restoreCallingIdentity(identity); |
| 14091 | } |
| 14092 | return false; |
| 14093 | } |
| 14094 | |
| 14095 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14096 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14097 | * |
| 14098 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14099 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14100 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14101 | * |
| 14102 | * @param enable if notifications about disclosure events should be enabled |
| 14103 | * @throws SecurityException if the caller does not have the required privileges |
| 14104 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14105 | */ |
| 14106 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14107 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14108 | enforceModifyPermission(); |
| 14109 | checkForIdentifierDisclosureNotificationSupport(); |
| 14110 | |
| 14111 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14112 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14113 | editor.apply(); |
| 14114 | |
| 14115 | // Each phone instance is responsible for updating its respective modem immediately |
| 14116 | // after we've made a preference change. |
| 14117 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14118 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14119 | } |
| 14120 | } |
| 14121 | |
| 14122 | /** |
| 14123 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14124 | * |
| 14125 | * @throws SecurityException if the caller does not have the required privileges |
| 14126 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14127 | */ |
| 14128 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14129 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14130 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14131 | checkForIdentifierDisclosureNotificationSupport(); |
| 14132 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14133 | } |
| 14134 | |
| 14135 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14136 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14137 | * are in use by the cellular modem. |
| 14138 | * |
| 14139 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14140 | * @throws SecurityException if the caller does not have the required privileges |
| 14141 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14142 | * and integrity algorithms in use |
| 14143 | * @hide |
| 14144 | */ |
| 14145 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14146 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14147 | enforceModifyPermission(); |
| 14148 | checkForNullCipherNotificationSupport(); |
| 14149 | |
| 14150 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14151 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14152 | editor.apply(); |
| 14153 | |
| 14154 | // Each phone instance is responsible for updating its respective modem immediately |
| 14155 | // after a preference change. |
| 14156 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14157 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14158 | } |
| 14159 | } |
| 14160 | |
| 14161 | /** |
| 14162 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14163 | * cellular modem. |
| 14164 | * |
| 14165 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14166 | * @throws SecurityException if the caller does not have the required privileges |
| 14167 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14168 | * and integrity algorithms in use |
| 14169 | * @hide |
| 14170 | */ |
| 14171 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14172 | public boolean isNullCipherNotificationsEnabled() { |
| 14173 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14174 | checkForNullCipherNotificationSupport(); |
| 14175 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14176 | } |
| 14177 | |
| 14178 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14179 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14180 | * |
| 14181 | * <p>This method behaves in one of the following ways: |
| 14182 | * <ul> |
| 14183 | * <li>return true : if the calling package has the appop permission {@link |
| 14184 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14185 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14186 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14187 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14188 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14189 | * </ul> |
| 14190 | */ |
| 14191 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14192 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14193 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14194 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14195 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14196 | return true; |
| 14197 | } |
| 14198 | } |
| 14199 | return false; |
| 14200 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14201 | |
| 14202 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14203 | * @return The subscription manager service instance. |
| 14204 | */ |
| 14205 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14206 | return SubscriptionManagerService.getInstance(); |
| 14207 | } |
| 14208 | |
| 14209 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14210 | * Class binds the consumer[callback] and carrierId. |
| 14211 | */ |
| 14212 | private static class CallerCallbackInfo { |
| 14213 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14214 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14215 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14216 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14217 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14218 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14219 | } |
| 14220 | |
| 14221 | public Consumer<Integer> getConsumer() { |
| 14222 | return mConsumer; |
| 14223 | } |
| 14224 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14225 | public Set<Integer> getCarrierIds() { |
| 14226 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14227 | } |
| 14228 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14229 | |
| 14230 | /* |
| 14231 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14232 | * But the context that is passed in is unused if the phone app is already alive. |
| 14233 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14234 | */ |
| 14235 | @VisibleForTesting |
| 14236 | public void setPackageManager(PackageManager packageManager) { |
| 14237 | mPackageManager = packageManager; |
| 14238 | } |
| 14239 | |
| 14240 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14241 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14242 | * But the context that is passed in is unused if the phone app is already alive. |
| 14243 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14244 | */ |
| 14245 | @VisibleForTesting |
| 14246 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14247 | mAppOps = appOps; |
| 14248 | } |
| 14249 | |
| 14250 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14251 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14252 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14253 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14254 | */ |
| 14255 | @VisibleForTesting |
| 14256 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14257 | mFeatureFlags = featureFlags; |
| 14258 | } |
| 14259 | |
| 14260 | /** |
| 14261 | * Make sure the device has required telephony feature |
| 14262 | * |
| 14263 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14264 | */ |
| 14265 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14266 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14267 | if (callingPackage == null || mPackageManager == null) { |
| 14268 | return; |
| 14269 | } |
| 14270 | |
| 14271 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14272 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14273 | Binder.getCallingUserHandle()) |
| 14274 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14275 | // Skip to check associated telephony feature, |
| 14276 | // if compatibility change is not enabled for the current process or |
| 14277 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14278 | return; |
| 14279 | } |
| 14280 | |
| 14281 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14282 | throw new UnsupportedOperationException( |
| 14283 | methodName + " is unsupported without " + telephonyFeature); |
| 14284 | } |
| 14285 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14286 | |
| 14287 | /** |
| 14288 | * Registers for the satellite communication allowed state changed. |
| 14289 | * |
| 14290 | * @param subId The subId of the subscription to register for the satellite communication |
| 14291 | * allowed state changed. |
| 14292 | * @param callback The callback to handle the satellite communication allowed |
| 14293 | * state changed event. |
| 14294 | * |
| 14295 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14296 | * |
| 14297 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14298 | */ |
| 14299 | @Override |
| 14300 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14301 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14302 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
| 14303 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14304 | subId, callback); |
| 14305 | } |
| 14306 | |
| 14307 | /** |
| 14308 | * Unregisters for the satellite communication allowed state changed. |
| 14309 | * If callback was not registered before, the request will be ignored. |
| 14310 | * |
| 14311 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14312 | * allowed state changed. |
| 14313 | * @param callback The callback that was passed to |
| 14314 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14315 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14316 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14317 | */ |
| 14318 | @Override |
| 14319 | public void unregisterForCommunicationAllowedStateChanged( |
| 14320 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14321 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
| 14322 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback); |
| 14323 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14324 | |
| 14325 | /** |
| 14326 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14327 | * |
| 14328 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14329 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14330 | * if the request is successful or an error code if the request failed. |
| 14331 | * |
| 14332 | * @throws SecurityException if the caller doesn't have required permission. |
| 14333 | */ |
| 14334 | @Override |
| 14335 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14336 | enforceModifyPermission(); |
| 14337 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
| 14338 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14339 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14340 | |
| 14341 | /** |
| 14342 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14343 | * |
| 14344 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14345 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14346 | * |
| 14347 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14348 | */ |
| 14349 | @Override |
| 14350 | public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) { |
| 14351 | enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds"); |
| 14352 | mSatelliteController.requestProvisionSubscriberIds(result); |
| 14353 | } |
| 14354 | |
| 14355 | /** |
| 14356 | * Request to get provisioned status for given a satellite subscriber id. |
| 14357 | * |
| 14358 | * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check. |
| 14359 | * @param result The result receiver, which returns the provisioned status of the token if the |
| 14360 | * request is successful or an error code if the request failed. |
| 14361 | * |
| 14362 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14363 | */ |
| 14364 | @Override |
Hyosun Kim | c7ae4d5 | 2024-07-05 02:44:27 +0000 | [diff] [blame] | 14365 | public void requestIsProvisioned(@NonNull String satelliteSubscriberId, |
| 14366 | @NonNull ResultReceiver result) { |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14367 | enforceSatelliteCommunicationPermission("requestIsProvisioned"); |
| 14368 | mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result); |
| 14369 | } |
| 14370 | |
| 14371 | /** |
| 14372 | * Deliver the list of provisioned satellite subscriber ids. |
| 14373 | * |
| 14374 | * @param list List of provisioned satellite subscriber ids. |
| 14375 | * @param result The result receiver that returns whether deliver success or fail. |
| 14376 | * |
| 14377 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14378 | */ |
| 14379 | @Override |
Hyosun Kim | c7ae4d5 | 2024-07-05 02:44:27 +0000 | [diff] [blame] | 14380 | public void provisionSatellite(@NonNull List<ProvisionSubscriberId> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14381 | @NonNull ResultReceiver result) { |
| 14382 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
| 14383 | mSatelliteController.provisionSatellite(list, result); |
| 14384 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14385 | } |