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; |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 30 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 34 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 35 | 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] | 36 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 37 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 38 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 39 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 40 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 42 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 44 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 45 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 46 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 47 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 48 | import android.compat.annotation.ChangeId; |
| 49 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 50 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 51 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 52 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.content.Context; |
| 54 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 55 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 56 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.net.Uri; |
| 59 | import android.os.AsyncResult; |
| 60 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 61 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 63 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 65 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 66 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 67 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.Looper; |
| 69 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 71 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 72 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 74 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 75 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 76 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 77 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 78 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 79 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 81 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 83 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 84 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 85 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 86 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 87 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 88 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 90 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 91 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 92 | import android.telephony.AccessNetworkConstants; |
| 93 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 95 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 96 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 97 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 98 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 99 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 100 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 101 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 102 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 103 | import android.telephony.CellIdentityCdma; |
| 104 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 106 | import android.telephony.CellInfoGsm; |
| 107 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 108 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 110 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 111 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 112 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 113 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 114 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 115 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 116 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 118 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 119 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 120 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 123 | import android.telephony.SignalStrengthUpdateRequest; |
| 124 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 126 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 127 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 129 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 131 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 132 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 133 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 134 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 136 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 137 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 138 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 139 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 140 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 141 | import android.telephony.gba.GbaAuthRequest; |
| 142 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 143 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 144 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 146 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 147 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 154 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 155 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 157 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 165 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 166 | import android.telephony.satellite.NtnSignalStrength; |
| 167 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
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; |
| 2734 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2735 | UnlockSim(int phoneId, IccCard simCard) { |
| 2736 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | mSimCard = simCard; |
| 2738 | } |
| 2739 | |
| 2740 | @Override |
| 2741 | public void run() { |
| 2742 | Looper.prepare(); |
| 2743 | synchronized (UnlockSim.this) { |
| 2744 | mHandler = new Handler() { |
| 2745 | @Override |
| 2746 | public void handleMessage(Message msg) { |
| 2747 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2748 | switch (msg.what) { |
| 2749 | case SUPPLY_PIN_COMPLETE: |
| 2750 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2751 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2752 | mRetryCount = msg.arg1; |
| 2753 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2754 | CommandException.Error error = null; |
| 2755 | if (ar.exception instanceof CommandException) { |
| 2756 | error = ((CommandException) (ar.exception)) |
| 2757 | .getCommandError(); |
| 2758 | } |
| 2759 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2760 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2761 | } else if (error == CommandException.Error.ABORTED) { |
| 2762 | /* When UiccCardApp dispose, handle message and return |
| 2763 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2764 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2765 | } else { |
| 2766 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2767 | } |
| 2768 | } else { |
| 2769 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | mDone = true; |
| 2772 | UnlockSim.this.notifyAll(); |
| 2773 | } |
| 2774 | break; |
| 2775 | } |
| 2776 | } |
| 2777 | }; |
| 2778 | UnlockSim.this.notifyAll(); |
| 2779 | } |
| 2780 | Looper.loop(); |
| 2781 | } |
| 2782 | |
| 2783 | /* |
| 2784 | * Use PIN or PUK to unlock SIM card |
| 2785 | * |
| 2786 | * If PUK is null, unlock SIM card with PIN |
| 2787 | * |
| 2788 | * 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] | 2789 | * |
| 2790 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2791 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2793 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | |
| 2795 | while (mHandler == null) { |
| 2796 | try { |
| 2797 | wait(); |
| 2798 | } catch (InterruptedException e) { |
| 2799 | Thread.currentThread().interrupt(); |
| 2800 | } |
| 2801 | } |
| 2802 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2803 | |
| 2804 | if (puk == null) { |
| 2805 | mSimCard.supplyPin(pin, callback); |
| 2806 | } else { |
| 2807 | mSimCard.supplyPuk(puk, pin, callback); |
| 2808 | } |
| 2809 | |
| 2810 | while (!mDone) { |
| 2811 | try { |
| 2812 | Log.d(LOG_TAG, "wait for done"); |
| 2813 | wait(); |
| 2814 | } catch (InterruptedException e) { |
| 2815 | // Restore the interrupted status |
| 2816 | Thread.currentThread().interrupt(); |
| 2817 | } |
| 2818 | } |
| 2819 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2820 | int[] resultArray = new int[2]; |
| 2821 | resultArray[0] = mResult; |
| 2822 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2823 | |
| 2824 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2825 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2826 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2827 | // This instance is no longer reused, so quit its thread's looper. |
| 2828 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2829 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2830 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | } |
| 2832 | } |
| 2833 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2834 | /** |
| 2835 | * This method has been removed due to privacy and stability concerns. |
| 2836 | */ |
| 2837 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2839 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2840 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2843 | @Override |
| 2844 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2845 | mApp.getSystemService(AppOpsManager.class) |
| 2846 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2847 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2848 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2849 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2850 | // Callers targeting S have no business invoking this method. |
| 2851 | return; |
| 2852 | } |
| 2853 | |
| 2854 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2855 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2856 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2857 | .setCallingPackage(callingPackage) |
| 2858 | .setCallingFeatureId(null) |
| 2859 | .setCallingPid(Binder.getCallingPid()) |
| 2860 | .setCallingUid(Binder.getCallingUid()) |
| 2861 | .setMethod("updateServiceLocation") |
| 2862 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2863 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2864 | .build()); |
| 2865 | // Apps that lack location permission have no business calling this method; |
| 2866 | // however, because no permission was declared in the public API, denials must |
| 2867 | // all be "soft". |
| 2868 | switch (locationResult) { |
| 2869 | case DENIED_HARD: /* fall through */ |
| 2870 | case DENIED_SOFT: |
| 2871 | return; |
| 2872 | } |
| 2873 | |
| 2874 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2875 | final long identity = Binder.clearCallingIdentity(); |
| 2876 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2877 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | } finally { |
| 2879 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2880 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2883 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2884 | @Override |
| 2885 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2886 | return isRadioOnWithFeature(callingPackage, null); |
| 2887 | } |
| 2888 | |
| 2889 | |
| 2890 | @Override |
| 2891 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2892 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2893 | callingFeatureId); |
| 2894 | } |
| 2895 | |
| 2896 | @Deprecated |
| 2897 | @Override |
| 2898 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2899 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2902 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2903 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2904 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2905 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2906 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2907 | return false; |
| 2908 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2910 | enforceTelephonyFeatureWithException(callingPackage, |
| 2911 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | final long identity = Binder.clearCallingIdentity(); |
| 2914 | try { |
| 2915 | return isRadioOnForSubscriber(subId); |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
| 2918 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | final Phone phone = getPhone(subId); |
| 2925 | if (phone != null) { |
| 2926 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2927 | } else { |
| 2928 | return false; |
| 2929 | } |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2932 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2936 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2937 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2938 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2939 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2942 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2943 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | final long identity = Binder.clearCallingIdentity(); |
| 2946 | try { |
| 2947 | final Phone phone = getPhone(subId); |
| 2948 | if (phone != null) { |
| 2949 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2950 | } |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2953 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2957 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2960 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2961 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2962 | |
| 2963 | final long identity = Binder.clearCallingIdentity(); |
| 2964 | try { |
| 2965 | final Phone phone = getPhone(subId); |
| 2966 | if (phone == null) { |
| 2967 | return false; |
| 2968 | } |
| 2969 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2970 | toggleRadioOnOffForSubscriber(subId); |
| 2971 | } |
| 2972 | return true; |
| 2973 | } finally { |
| 2974 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2975 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2976 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2977 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2978 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2979 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2980 | |
| 2981 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2982 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2983 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2984 | /* |
| 2985 | * If any of the Radios are available, it will need to be |
| 2986 | * shutdown. So return true if any Radio is available. |
| 2987 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 | final long identity = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2991 | Phone phone = PhoneFactory.getPhone(i); |
| 2992 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2993 | } |
| 2994 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2995 | return false; |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2998 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3002 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | enforceModifyPermission(); |
| 3004 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3005 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3006 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3011 | logv("Shutting down Phone " + i); |
| 3012 | shutdownRadioUsingPhoneId(i); |
| 3013 | } |
| 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3020 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3021 | if (phone != null && phone.isRadioAvailable()) { |
| 3022 | phone.shutdownRadio(); |
| 3023 | } |
| 3024 | } |
| 3025 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3026 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3027 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3029 | if (!turnOn) { |
| 3030 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3031 | } |
| 3032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3036 | if (defaultPhone != null) { |
| 3037 | defaultPhone.setRadioPower(turnOn); |
| 3038 | return true; |
| 3039 | } else { |
| 3040 | loge("There's no default phone."); |
| 3041 | return false; |
| 3042 | } |
| 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3045 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3048 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3049 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3051 | if (!turnOn) { |
| 3052 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3053 | + ",callingPackage=" + getCurrentPackageName()); |
| 3054 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | final Phone phone = getPhone(subId); |
| 3058 | if (phone != null) { |
| 3059 | phone.setRadioPower(turnOn); |
| 3060 | return true; |
| 3061 | } else { |
| 3062 | return false; |
| 3063 | } |
| 3064 | } finally { |
| 3065 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3066 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3069 | /** |
| 3070 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3071 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3072 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3073 | * powering it off, and these radio off votes will be cleared. |
| 3074 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3075 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3076 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3077 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3078 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3079 | * check its vote. |
| 3080 | * |
| 3081 | * @param subId The subscription ID. |
| 3082 | * @param reason The reason for powering off radio. |
| 3083 | * @return true on success and false on failure. |
| 3084 | */ |
| 3085 | public boolean requestRadioPowerOffForReason(int subId, |
| 3086 | @TelephonyManager.RadioPowerReason int reason) { |
| 3087 | enforceModifyPermission(); |
| 3088 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3089 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3090 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3091 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3092 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3093 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3096 | boolean result = false; |
| 3097 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3098 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3099 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3100 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3101 | if (!result) { |
| 3102 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3103 | } |
| 3104 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3105 | } finally { |
| 3106 | Binder.restoreCallingIdentity(identity); |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | /** |
| 3111 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3112 | * {@link requestRadioPowerOffForReason}. |
| 3113 | * |
| 3114 | * @param subId The subscription ID. |
| 3115 | * @param reason The reason for powering off radio. |
| 3116 | * @return true on success and false on failure. |
| 3117 | */ |
| 3118 | public boolean clearRadioPowerOffForReason(int subId, |
| 3119 | @TelephonyManager.RadioPowerReason int reason) { |
| 3120 | enforceModifyPermission(); |
| 3121 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3122 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3123 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3124 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3125 | final long identity = Binder.clearCallingIdentity(); |
| 3126 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3127 | boolean result = false; |
| 3128 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3129 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3130 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3131 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3132 | if (!result) { |
| 3133 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3134 | } |
| 3135 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(identity); |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | /** |
| 3142 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3143 | * |
| 3144 | * @param subId The subscription ID. |
| 3145 | * @param callingPackage The package making the call. |
| 3146 | * @param callingFeatureId The feature in the package. |
| 3147 | * @return List of reasons for powering off radio. |
| 3148 | */ |
| 3149 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3150 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3151 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3152 | enforceTelephonyFeatureWithException(callingPackage, |
| 3153 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3154 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3155 | final long identity = Binder.clearCallingIdentity(); |
| 3156 | List result = new ArrayList(); |
| 3157 | try { |
| 3158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3159 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3160 | return result; |
| 3161 | } |
| 3162 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3163 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3164 | if (phone != null) { |
| 3165 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3166 | } else { |
| 3167 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3168 | } |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(identity); |
| 3171 | } |
| 3172 | return result; |
| 3173 | } |
| 3174 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3175 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3176 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3177 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3178 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3179 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3180 | enforceTelephonyFeatureWithException(callingPackage, |
| 3181 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3183 | final long identity = Binder.clearCallingIdentity(); |
| 3184 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3185 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | final Phone phone = getPhone(subId); |
| 3187 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3188 | phone.getDataSettingsManager().setDataEnabled( |
| 3189 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | return true; |
| 3191 | } else { |
| 3192 | return false; |
| 3193 | } |
| 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3199 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3200 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3201 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3202 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3204 | enforceTelephonyFeatureWithException(callingPackage, |
| 3205 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3209 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | final Phone phone = getPhone(subId); |
| 3211 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3212 | phone.getDataSettingsManager().setDataEnabled( |
| 3213 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | return true; |
| 3215 | } else { |
| 3216 | return false; |
| 3217 | } |
| 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3223 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3224 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3225 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3226 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | final Phone phone = getPhone(subId); |
| 3231 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3232 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | } else { |
| 3234 | return false; |
| 3235 | } |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3242 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3245 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3246 | enforceCallPermission(); |
| 3247 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3248 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3249 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | final long identity = Binder.clearCallingIdentity(); |
| 3252 | try { |
| 3253 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3254 | return; |
| 3255 | } |
| 3256 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3257 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3258 | } finally { |
| 3259 | Binder.restoreCallingIdentity(identity); |
| 3260 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3261 | }; |
| 3262 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3263 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3264 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3265 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3266 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3267 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
| 3271 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3272 | return false; |
| 3273 | } |
| 3274 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3280 | /** |
| 3281 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3282 | * tag on getCallState Binder call. |
| 3283 | */ |
| 3284 | @Deprecated |
| 3285 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3287 | if (CompatChanges.isChangeEnabled( |
| 3288 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3289 | Binder.getCallingUid())) { |
| 3290 | // Do not allow this API to be called on API version 31+, it should only be |
| 3291 | // called on old apps using this Binder call directly. |
| 3292 | throw new SecurityException("This method can only be used for applications " |
| 3293 | + "targeting API version 30 or less."); |
| 3294 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3295 | final long identity = Binder.clearCallingIdentity(); |
| 3296 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3297 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3298 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3299 | } finally { |
| 3300 | Binder.restoreCallingIdentity(identity); |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | @Override |
| 3305 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3306 | if (CompatChanges.isChangeEnabled( |
| 3307 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3308 | Binder.getCallingUid())) { |
| 3309 | // Check READ_PHONE_STATE for API version 31+ |
| 3310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3311 | featureId, "getCallStateForSubscription")) { |
| 3312 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3313 | + "targeting API level 31+."); |
| 3314 | } |
| 3315 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3316 | |
| 3317 | enforceTelephonyFeatureWithException(callingPackage, |
| 3318 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3319 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3320 | final long identity = Binder.clearCallingIdentity(); |
| 3321 | try { |
| 3322 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3323 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3324 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3330 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3331 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3332 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | @Override |
| 3336 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3337 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3338 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3340 | final long identity = Binder.clearCallingIdentity(); |
| 3341 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3342 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3344 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3345 | } else { |
| 3346 | return PhoneConstantConversions.convertDataState( |
| 3347 | PhoneConstants.DataState.DISCONNECTED); |
| 3348 | } |
| 3349 | } finally { |
| 3350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3354 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3355 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3356 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3360 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3362 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3364 | final long identity = Binder.clearCallingIdentity(); |
| 3365 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3366 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3368 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3369 | } else { |
| 3370 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3371 | } |
| 3372 | } finally { |
| 3373 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3378 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3379 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3380 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3381 | |
| 3382 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3383 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3384 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3385 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3386 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3387 | .setCallingPid(Binder.getCallingPid()) |
| 3388 | .setCallingUid(Binder.getCallingUid()) |
| 3389 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3390 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3391 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3392 | .build()); |
| 3393 | switch (locationResult) { |
| 3394 | case DENIED_HARD: |
| 3395 | throw new SecurityException("Not allowed to access cell location"); |
| 3396 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3397 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3398 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3401 | enforceTelephonyFeatureWithException(callingPackage, |
| 3402 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3403 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3404 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3405 | final long identity = Binder.clearCallingIdentity(); |
| 3406 | try { |
| 3407 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3408 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3409 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3410 | } finally { |
| 3411 | Binder.restoreCallingIdentity(identity); |
| 3412 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3415 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3416 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3417 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3418 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3419 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3420 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3421 | // registered cell info, so return a NULL country instead. |
| 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3424 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3425 | // Get default phone in this case. |
| 3426 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3427 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3428 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3430 | if (phone == null) return ""; |
| 3431 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3432 | if (sst == null) return ""; |
| 3433 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3434 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3435 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(identity); |
| 3438 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3441 | /** |
| 3442 | * This method was removed due to potential issues caused by performing partial |
| 3443 | * updates of service state, and lack of a credible use case. |
| 3444 | * |
| 3445 | * This has the ability to break the telephony implementation by disabling notification of |
| 3446 | * changes in device connectivity. DO NOT USE THIS! |
| 3447 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3448 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3449 | public void enableLocationUpdates() { |
| 3450 | mApp.enforceCallingOrSelfPermission( |
| 3451 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3454 | /** |
| 3455 | * This method was removed due to potential issues caused by performing partial |
| 3456 | * updates of service state, and lack of a credible use case. |
| 3457 | * |
| 3458 | * This has the ability to break the telephony implementation by disabling notification of |
| 3459 | * changes in device connectivity. DO NOT USE THIS! |
| 3460 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3461 | @Override |
| 3462 | public void disableLocationUpdates() { |
| 3463 | mApp.enforceCallingOrSelfPermission( |
| 3464 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | @Override |
| 3468 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3469 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3470 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3471 | try { |
| 3472 | mApp.getSystemService(AppOpsManager.class) |
| 3473 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3474 | } catch (SecurityException e) { |
| 3475 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3476 | throw e; |
| 3477 | } |
| 3478 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3479 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3480 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3481 | throw new SecurityException( |
| 3482 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3483 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3484 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3485 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3486 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3487 | return null; |
| 3488 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3489 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3491 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3492 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3493 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3495 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3496 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3497 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3498 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3499 | for (CellInfo ci : info) { |
| 3500 | if (ci instanceof CellInfoGsm) { |
| 3501 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3502 | } else if (ci instanceof CellInfoWcdma) { |
| 3503 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3505 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3506 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3509 | private List<CellInfo> getCachedCellInfo() { |
| 3510 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3511 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3512 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3513 | if (info != null) cellInfos.addAll(info); |
| 3514 | } |
| 3515 | return cellInfos; |
| 3516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3517 | |
| 3518 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3519 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3520 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3521 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3522 | |
| 3523 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3524 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3525 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3526 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3527 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3528 | .setCallingPid(Binder.getCallingPid()) |
| 3529 | .setCallingUid(Binder.getCallingUid()) |
| 3530 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3531 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3532 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3533 | .build()); |
| 3534 | switch (locationResult) { |
| 3535 | case DENIED_HARD: |
| 3536 | throw new SecurityException("Not allowed to access cell info"); |
| 3537 | case DENIED_SOFT: |
| 3538 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3541 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3542 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3543 | return getCachedCellInfo(); |
| 3544 | } |
| 3545 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3546 | enforceTelephonyFeatureWithException(callingPackage, |
| 3547 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3548 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3549 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3550 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3554 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3555 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3556 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3557 | if (info != null) cellInfos.addAll(info); |
| 3558 | } |
| 3559 | return cellInfos; |
| 3560 | } finally { |
| 3561 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3565 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3566 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3567 | String callingFeatureId) { |
| 3568 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3569 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3573 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3574 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3575 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3576 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3579 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3580 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3581 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3582 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3583 | |
| 3584 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3585 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3586 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3587 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3588 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3589 | .setCallingPid(Binder.getCallingPid()) |
| 3590 | .setCallingUid(Binder.getCallingUid()) |
| 3591 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3592 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3593 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3594 | .build()); |
| 3595 | switch (locationResult) { |
| 3596 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3597 | if (TelephonyPermissions |
| 3598 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3599 | // Safetynet logging for b/154934934 |
| 3600 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3601 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3602 | throw new SecurityException("Not allowed to access cell info"); |
| 3603 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3604 | if (TelephonyPermissions |
| 3605 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3606 | // Safetynet logging for b/154934934 |
| 3607 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3608 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3609 | try { |
| 3610 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3611 | } catch (RemoteException re) { |
| 3612 | // Drop without consequences |
| 3613 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3614 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3617 | enforceTelephonyFeatureWithException(callingPackage, |
| 3618 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3619 | |
| 3620 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3621 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3622 | |
| 3623 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3624 | } |
| 3625 | |
| 3626 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3627 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3628 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3629 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3630 | |
| 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3633 | Phone phone = getPhone(subId); |
| 3634 | if (phone == null) { |
| 3635 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3636 | } else { |
| 3637 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3638 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | } finally { |
| 3640 | Binder.restoreCallingIdentity(identity); |
| 3641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3644 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3645 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3646 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3647 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3648 | return null; |
| 3649 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3650 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3651 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3652 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3653 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3654 | return null; |
| 3655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3657 | enforceTelephonyFeatureWithException(callingPackage, |
| 3658 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | final long identity = Binder.clearCallingIdentity(); |
| 3661 | try { |
| 3662 | return phone.getImei(); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3669 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3670 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3671 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3672 | callingFeatureId, "getPrimaryImei")) { |
| 3673 | throw new SecurityException("Caller does not have permission"); |
| 3674 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3675 | |
| 3676 | enforceTelephonyFeatureWithException(callingPackage, |
| 3677 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3678 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3679 | final long identity = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3682 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3683 | return phone.getImei(); |
| 3684 | } |
| 3685 | } |
| 3686 | throw new UnsupportedOperationException("Operation not supported"); |
| 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(identity); |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3693 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3694 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3695 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3696 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3697 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3698 | String tac = null; |
| 3699 | if (phone != null) { |
| 3700 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3701 | try { |
| 3702 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3703 | } catch (IndexOutOfBoundsException e) { |
| 3704 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3705 | return null; |
| 3706 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3707 | } |
| 3708 | return tac; |
| 3709 | } |
| 3710 | |
| 3711 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3712 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3713 | try { |
| 3714 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3715 | } catch (SecurityException se) { |
| 3716 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3717 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3718 | + Binder.getCallingUid()); |
| 3719 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3720 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3721 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3722 | return null; |
| 3723 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3724 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3725 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3726 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3727 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3728 | return null; |
| 3729 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3731 | enforceTelephonyFeatureWithException(callingPackage, |
| 3732 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | return phone.getMeid(); |
| 3737 | } finally { |
| 3738 | Binder.restoreCallingIdentity(identity); |
| 3739 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3743 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3744 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3745 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3746 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3747 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3748 | String manufacturerCode = null; |
| 3749 | if (phone != null) { |
| 3750 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3751 | try { |
| 3752 | manufacturerCode = |
| 3753 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3754 | } catch (IndexOutOfBoundsException e) { |
| 3755 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3756 | return null; |
| 3757 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3758 | } |
| 3759 | return manufacturerCode; |
| 3760 | } |
| 3761 | |
| 3762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3763 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3764 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3766 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3767 | return null; |
| 3768 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3769 | int subId = phone.getSubId(); |
| 3770 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3771 | mApp, subId, callingPackage, callingFeatureId, |
| 3772 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3773 | return null; |
| 3774 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3775 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3776 | enforceTelephonyFeatureWithException(callingPackage, |
| 3777 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3779 | final long identity = Binder.clearCallingIdentity(); |
| 3780 | try { |
| 3781 | return phone.getDeviceSvn(); |
| 3782 | } finally { |
| 3783 | Binder.restoreCallingIdentity(identity); |
| 3784 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3787 | @Override |
| 3788 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3789 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3790 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3791 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | final Phone phone = getPhone(subId); |
| 3795 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3796 | } finally { |
| 3797 | Binder.restoreCallingIdentity(identity); |
| 3798 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | @Override |
| 3802 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3803 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3804 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | final Phone phone = getPhone(subId); |
| 3809 | return phone == null ? null : phone.getCarrierName(); |
| 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
| 3812 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3813 | } |
| 3814 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3815 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3816 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3817 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3818 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3819 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | final Phone phone = getPhone(subId); |
| 3823 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3824 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3825 | } finally { |
| 3826 | Binder.restoreCallingIdentity(identity); |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3831 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3832 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3833 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3834 | "getSubscriptionSpecificCarrierName"); |
| 3835 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3836 | final long identity = Binder.clearCallingIdentity(); |
| 3837 | try { |
| 3838 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3839 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
| 3843 | } |
| 3844 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3845 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3846 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3847 | if (!isSubscriptionMccMnc) { |
| 3848 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3849 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3850 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3851 | if (phone == null) { |
| 3852 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3853 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3854 | |
| 3855 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3856 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3857 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3858 | final long identity = Binder.clearCallingIdentity(); |
| 3859 | try { |
| 3860 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3861 | } finally { |
| 3862 | Binder.restoreCallingIdentity(identity); |
| 3863 | } |
| 3864 | } |
| 3865 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3866 | // |
| 3867 | // Internal helper methods. |
| 3868 | // |
| 3869 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3870 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3871 | * Make sure the caller is the calling package itself |
| 3872 | * |
| 3873 | * @throws SecurityException if the caller is not the calling package |
| 3874 | */ |
| 3875 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3876 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3877 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3878 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3879 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3880 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3881 | } catch (PackageManager.NameNotFoundException e) { |
| 3882 | // packageUid is -1 |
| 3883 | } |
| 3884 | if (packageUid != callingUid) { |
| 3885 | throw new SecurityException(message + ": Package " + callingPackage |
| 3886 | + " does not belong to " + callingUid); |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3891 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3892 | * |
| 3893 | * @throws SecurityException if the caller does not have the required permission |
| 3894 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3895 | @VisibleForTesting |
| 3896 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3897 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3898 | } |
| 3899 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3900 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3901 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3902 | * |
| 3903 | * @throws SecurityException if the caller does not have the required permission |
| 3904 | */ |
| 3905 | @VisibleForTesting |
| 3906 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3907 | enforceReadPermission(null); |
| 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3912 | * |
| 3913 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3914 | */ |
| 3915 | @VisibleForTesting |
| 3916 | public void enforceReadPermission(String msg) { |
| 3917 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3920 | private void enforceActiveEmergencySessionPermission() { |
| 3921 | mApp.enforceCallingOrSelfPermission( |
| 3922 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3923 | } |
| 3924 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3925 | /** |
| 3926 | * Make sure the caller has the CALL_PHONE permission. |
| 3927 | * |
| 3928 | * @throws SecurityException if the caller does not have the required permission |
| 3929 | */ |
| 3930 | private void enforceCallPermission() { |
| 3931 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3932 | } |
| 3933 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3934 | private void enforceSettingsPermission() { |
| 3935 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3938 | private void enforceRebootPermission() { |
| 3939 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3940 | } |
| 3941 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3942 | /** |
| 3943 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3944 | * @param message - log message to print. |
| 3945 | * @throws SecurityException if the caller does not have the required permission |
| 3946 | */ |
| 3947 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3948 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3949 | } |
| 3950 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3951 | private String createTelUrl(String number) { |
| 3952 | if (TextUtils.isEmpty(number)) { |
| 3953 | return null; |
| 3954 | } |
| 3955 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3956 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3959 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3960 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3963 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3964 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3967 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3968 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3971 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3972 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3973 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3976 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3977 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3978 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3979 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | final long identity = Binder.clearCallingIdentity(); |
| 3982 | try { |
| 3983 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3984 | if (phone == null) { |
| 3985 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3986 | } else { |
| 3987 | return phone.getPhoneType(); |
| 3988 | } |
| 3989 | } finally { |
| 3990 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3991 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | /** |
| 3995 | * Returns the CDMA ERI icon index to display |
| 3996 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3997 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3998 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3999 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4000 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4003 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4004 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4005 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4007 | mApp, subId, callingPackage, callingFeatureId, |
| 4008 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4009 | return -1; |
| 4010 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4011 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4012 | enforceTelephonyFeatureWithException(callingPackage, |
| 4013 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4014 | "getCdmaEriIconIndexForSubscriber"); |
| 4015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | final Phone phone = getPhone(subId); |
| 4019 | if (phone != null) { |
| 4020 | return phone.getCdmaEriIconIndex(); |
| 4021 | } else { |
| 4022 | return -1; |
| 4023 | } |
| 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4026 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | /** |
| 4030 | * Returns the CDMA ERI icon mode, |
| 4031 | * 0 - ON |
| 4032 | * 1 - FLASHING |
| 4033 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4035 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4036 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4037 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4041 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4042 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4043 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4044 | mApp, subId, callingPackage, callingFeatureId, |
| 4045 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4046 | return -1; |
| 4047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | |
| 4049 | final long identity = Binder.clearCallingIdentity(); |
| 4050 | try { |
| 4051 | final Phone phone = getPhone(subId); |
| 4052 | if (phone != null) { |
| 4053 | return phone.getCdmaEriIconMode(); |
| 4054 | } else { |
| 4055 | return -1; |
| 4056 | } |
| 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4059 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * Returns the CDMA ERI text, |
| 4064 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4067 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4068 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4071 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4072 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4073 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4075 | mApp, subId, callingPackage, callingFeatureId, |
| 4076 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4077 | return null; |
| 4078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | |
| 4080 | final long identity = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | final Phone phone = getPhone(subId); |
| 4083 | if (phone != null) { |
| 4084 | return phone.getCdmaEriText(); |
| 4085 | } else { |
| 4086 | return null; |
| 4087 | } |
| 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4090 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4094 | * Returns the CDMA MDN. |
| 4095 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4096 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4097 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4099 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4101 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4102 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4103 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4104 | final long identity = Binder.clearCallingIdentity(); |
| 4105 | try { |
| 4106 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4107 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4108 | return phone.getLine1Number(); |
| 4109 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4110 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | return null; |
| 4112 | } |
| 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | /** |
| 4119 | * Returns the CDMA MIN. |
| 4120 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4121 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4122 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4124 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4126 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4127 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4128 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4129 | final long identity = Binder.clearCallingIdentity(); |
| 4130 | try { |
| 4131 | final Phone phone = getPhone(subId); |
| 4132 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4133 | return phone.getCdmaMin(); |
| 4134 | } else { |
| 4135 | return null; |
| 4136 | } |
| 4137 | } finally { |
| 4138 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4142 | @Override |
| 4143 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4144 | INumberVerificationCallback callback, String callingPackage) { |
| 4145 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4146 | != PERMISSION_GRANTED) { |
| 4147 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4148 | } |
| 4149 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4150 | |
| 4151 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4152 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4153 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4154 | + "calling package: " + callingPackage |
| 4155 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4158 | enforceTelephonyFeatureWithException(callingPackage, |
| 4159 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4160 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4161 | if (range == null) { |
| 4162 | throw new NullPointerException("Range must be non-null"); |
| 4163 | } |
| 4164 | |
| 4165 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4166 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4167 | |
| 4168 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4169 | } |
| 4170 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4171 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4172 | * Returns true if CDMA provisioning needs to run. |
| 4173 | */ |
| 4174 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4175 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4176 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4177 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4178 | final long identity = Binder.clearCallingIdentity(); |
| 4179 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4180 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4187 | * Sets the voice mail number of a given subId. |
| 4188 | */ |
| 4189 | @Override |
| 4190 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4191 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4192 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4194 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4195 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4196 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
| 4199 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4200 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4201 | return success; |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
| 4204 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4205 | } |
| 4206 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4207 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4208 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4209 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4210 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4211 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4212 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4213 | throw new SecurityException("caller must be system dialer"); |
| 4214 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4216 | enforceTelephonyFeatureWithException(callingPackage, |
| 4217 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
| 4221 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4222 | if (phoneAccountHandle == null) { |
| 4223 | return null; |
| 4224 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4225 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4228 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4232 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4233 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4234 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4236 | mApp, subId, callingPackage, callingFeatureId, |
| 4237 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4238 | return null; |
| 4239 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4241 | enforceTelephonyFeatureWithException(callingPackage, |
| 4242 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4243 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4244 | final long identity = Binder.clearCallingIdentity(); |
| 4245 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4246 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4247 | } finally { |
| 4248 | Binder.restoreCallingIdentity(identity); |
| 4249 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4253 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4254 | VisualVoicemailSmsFilterSettings settings) { |
| 4255 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4257 | enforceTelephonyFeatureWithException(callingPackage, |
| 4258 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4259 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
| 4262 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4263 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | } finally { |
| 4265 | Binder.restoreCallingIdentity(identity); |
| 4266 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4270 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4271 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
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, "disableVisualVoicemailSmsFilter"); |
| 4275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
| 4278 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4279 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(identity); |
| 4282 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4286 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4287 | String callingPackage, int subId) { |
| 4288 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | |
| 4290 | final long identity = Binder.clearCallingIdentity(); |
| 4291 | try { |
| 4292 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4293 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
| 4296 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4300 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4301 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4302 | |
| 4303 | final long identity = Binder.clearCallingIdentity(); |
| 4304 | try { |
| 4305 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4306 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | } finally { |
| 4308 | Binder.restoreCallingIdentity(identity); |
| 4309 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4313 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4314 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4315 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4316 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4317 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4318 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4319 | |
| 4320 | enforceTelephonyFeatureWithException(callingPackage, |
| 4321 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4322 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4323 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4324 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4325 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4326 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4327 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4328 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4329 | * Sets the voice activation state of a given subId. |
| 4330 | */ |
| 4331 | @Override |
| 4332 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4334 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4336 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4337 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
| 4341 | final Phone phone = getPhone(subId); |
| 4342 | if (phone != null) { |
| 4343 | phone.setVoiceActivationState(activationState); |
| 4344 | } else { |
| 4345 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4346 | } |
| 4347 | } finally { |
| 4348 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | /** |
| 4353 | * Sets the data activation state of a given subId. |
| 4354 | */ |
| 4355 | @Override |
| 4356 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4357 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4358 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4359 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4360 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4361 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4363 | final long identity = Binder.clearCallingIdentity(); |
| 4364 | try { |
| 4365 | final Phone phone = getPhone(subId); |
| 4366 | if (phone != null) { |
| 4367 | phone.setDataActivationState(activationState); |
| 4368 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4369 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | } |
| 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | /** |
| 4377 | * Returns the voice activation state of a given subId. |
| 4378 | */ |
| 4379 | @Override |
| 4380 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4381 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4383 | enforceTelephonyFeatureWithException(callingPackage, |
| 4384 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4385 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4386 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4387 | final long identity = Binder.clearCallingIdentity(); |
| 4388 | try { |
| 4389 | if (phone != null) { |
| 4390 | return phone.getVoiceActivationState(); |
| 4391 | } else { |
| 4392 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4393 | } |
| 4394 | } finally { |
| 4395 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | /** |
| 4400 | * Returns the data activation state of a given subId. |
| 4401 | */ |
| 4402 | @Override |
| 4403 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4404 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4406 | enforceTelephonyFeatureWithException(callingPackage, |
| 4407 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4408 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4409 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | if (phone != null) { |
| 4413 | return phone.getDataActivationState(); |
| 4414 | } else { |
| 4415 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4416 | } |
| 4417 | } finally { |
| 4418 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4423 | * Returns the unread count of voicemails for a subId |
| 4424 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4425 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4426 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4427 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4428 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4429 | mApp, subId, callingPackage, callingFeatureId, |
| 4430 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4431 | return 0; |
| 4432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4433 | final long identity = Binder.clearCallingIdentity(); |
| 4434 | try { |
| 4435 | final Phone phone = getPhone(subId); |
| 4436 | if (phone != null) { |
| 4437 | return phone.getVoiceMessageCount(); |
| 4438 | } else { |
| 4439 | return 0; |
| 4440 | } |
| 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4443 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4447 | * returns true, if the device is in a state where both voice and data |
| 4448 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4449 | */ |
| 4450 | @Override |
| 4451 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4452 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4453 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4454 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4457 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
| 4460 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4464 | * Send the dialer code if called from the current default dialer or the caller has |
| 4465 | * carrier privilege. |
| 4466 | * @param inputCode The dialer code to send |
| 4467 | */ |
| 4468 | @Override |
| 4469 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4470 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4471 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4472 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4473 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4474 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4475 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4476 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4477 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4479 | enforceTelephonyFeatureWithException(callingPackage, |
| 4480 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4484 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4490 | @Override |
| 4491 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4492 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4493 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4494 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4495 | |
| 4496 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4497 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4498 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4499 | final long identity = Binder.clearCallingIdentity(); |
| 4500 | try { |
| 4501 | if (!isActiveSubscription(subId)) { |
| 4502 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4503 | } |
| 4504 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4507 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4508 | } |
| 4509 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4510 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4511 | public boolean isInEmergencySmsMode() { |
| 4512 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4513 | |
| 4514 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4515 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4516 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
| 4519 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4520 | if (phone.isInEmergencySmsMode()) { |
| 4521 | return true; |
| 4522 | } |
| 4523 | } |
| 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
| 4527 | return false; |
| 4528 | } |
| 4529 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4530 | /** |
| 4531 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4532 | * @param subId The subscription to use to check the configuration. |
| 4533 | * @param c The callback that will be used to send the result. |
| 4534 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4535 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4536 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4537 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4538 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4539 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4540 | |
| 4541 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4543 | "IMS not available on device."); |
| 4544 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4545 | final long token = Binder.clearCallingIdentity(); |
| 4546 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4547 | int slotId = getSlotIndexOrException(subId); |
| 4548 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4549 | |
| 4550 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4551 | if (controller != null) { |
| 4552 | ImsManager imsManager = controller.getImsManager(subId); |
| 4553 | if (imsManager != null) { |
| 4554 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4555 | } else { |
| 4556 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4557 | } |
| 4558 | } else { |
| 4559 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4560 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4561 | } catch (ImsException e) { |
| 4562 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4563 | } finally { |
| 4564 | Binder.restoreCallingIdentity(token); |
| 4565 | } |
| 4566 | } |
| 4567 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4568 | /** |
| 4569 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4570 | * @param subId The subscription to use to check the configuration. |
| 4571 | * @param c The callback that will be used to send the result. |
| 4572 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4573 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4574 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4575 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4576 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4577 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4578 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4579 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4580 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4581 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4582 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4583 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4584 | if (controller != null) { |
| 4585 | ImsManager imsManager = controller.getImsManager(subId); |
| 4586 | if (imsManager != null) { |
| 4587 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4588 | } else { |
| 4589 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4590 | + "is inactive, ignoring unregister."); |
| 4591 | // If the ImsManager is not valid, just return, since the callback |
| 4592 | // will already have been removed internally. |
| 4593 | } |
| 4594 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(token); |
| 4597 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4600 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4601 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4602 | * @param subId The subscription to use to check the configuration. |
| 4603 | * @param c The callback that will be used to send the result. |
| 4604 | */ |
| 4605 | @Override |
| 4606 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4607 | throws RemoteException { |
| 4608 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4609 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4610 | |
| 4611 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4612 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4613 | "IMS not available on device."); |
| 4614 | } |
| 4615 | final long token = Binder.clearCallingIdentity(); |
| 4616 | try { |
| 4617 | int slotId = getSlotIndexOrException(subId); |
| 4618 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4619 | |
| 4620 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4621 | if (controller != null) { |
| 4622 | ImsManager imsManager = controller.getImsManager(subId); |
| 4623 | if (imsManager != null) { |
| 4624 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4625 | } else { |
| 4626 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4627 | } |
| 4628 | } else { |
| 4629 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4630 | } |
| 4631 | } catch (ImsException e) { |
| 4632 | throw new ServiceSpecificException(e.getCode()); |
| 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(token); |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | /** |
| 4639 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4640 | * @param subId The subscription to use to check the configuration. |
| 4641 | * @param c The callback that will be used to send the result. |
| 4642 | */ |
| 4643 | @Override |
| 4644 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4645 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4646 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4647 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4648 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4649 | } |
| 4650 | final long token = Binder.clearCallingIdentity(); |
| 4651 | |
| 4652 | try { |
| 4653 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4654 | if (controller != null) { |
| 4655 | ImsManager imsManager = controller.getImsManager(subId); |
| 4656 | if (imsManager != null) { |
| 4657 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4658 | } else { |
| 4659 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4660 | + "is inactive, ignoring unregister."); |
| 4661 | // If the ImsManager is not valid, just return, since the callback |
| 4662 | // will already have been removed internally. |
| 4663 | } |
| 4664 | } |
| 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(token); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4671 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4672 | */ |
| 4673 | @Override |
| 4674 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4675 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4676 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4677 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4678 | "IMS not available on device."); |
| 4679 | } |
| 4680 | final long token = Binder.clearCallingIdentity(); |
| 4681 | try { |
| 4682 | Phone phone = getPhone(subId); |
| 4683 | if (phone == null) { |
| 4684 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4685 | + subId + "'"); |
| 4686 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4687 | } |
| 4688 | phone.getImsRegistrationState(regState -> { |
| 4689 | try { |
| 4690 | consumer.accept((regState == null) |
| 4691 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4692 | } catch (RemoteException e) { |
| 4693 | // Ignore if the remote process is no longer available to call back. |
| 4694 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4695 | } |
| 4696 | }); |
| 4697 | } finally { |
| 4698 | Binder.restoreCallingIdentity(token); |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | /** |
| 4703 | * Get the transport type for the IMS service registration state. |
| 4704 | */ |
| 4705 | @Override |
| 4706 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4707 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4708 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4709 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4710 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4711 | "IMS not available on device."); |
| 4712 | } |
| 4713 | final long token = Binder.clearCallingIdentity(); |
| 4714 | try { |
| 4715 | Phone phone = getPhone(subId); |
| 4716 | if (phone == null) { |
| 4717 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4718 | + subId + "'"); |
| 4719 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4720 | } |
| 4721 | phone.getImsRegistrationTech(regTech -> { |
| 4722 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4723 | int regTechConverted = (regTech == null) |
| 4724 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4725 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4726 | regTechConverted); |
| 4727 | try { |
| 4728 | consumer.accept(regTechConverted); |
| 4729 | } catch (RemoteException e) { |
| 4730 | // Ignore if the remote process is no longer available to call back. |
| 4731 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4732 | } |
| 4733 | }); |
| 4734 | } finally { |
| 4735 | Binder.restoreCallingIdentity(token); |
| 4736 | } |
| 4737 | } |
| 4738 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4739 | /** |
| 4740 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4741 | * @param subId The subscription to use to check the configuration. |
| 4742 | * @param c The callback that will be used to send the result. |
| 4743 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4744 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4745 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4746 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4747 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4748 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4749 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4751 | "IMS not available on device."); |
| 4752 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4753 | final long token = Binder.clearCallingIdentity(); |
| 4754 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4755 | int slotId = getSlotIndexOrException(subId); |
| 4756 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4757 | |
| 4758 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4759 | if (controller != null) { |
| 4760 | ImsManager imsManager = controller.getImsManager(subId); |
| 4761 | if (imsManager != null) { |
| 4762 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4763 | } else { |
| 4764 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4765 | } |
| 4766 | } else { |
| 4767 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4768 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4769 | } catch (ImsException e) { |
| 4770 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(token); |
| 4773 | } |
| 4774 | } |
| 4775 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4778 | * @param subId The subscription to use to check the configuration. |
| 4779 | * @param c The callback that will be used to send the result. |
| 4780 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4781 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4782 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4783 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4784 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4786 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4787 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4788 | |
| 4789 | final long token = Binder.clearCallingIdentity(); |
| 4790 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4791 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4792 | if (controller != null) { |
| 4793 | ImsManager imsManager = controller.getImsManager(subId); |
| 4794 | if (imsManager != null) { |
| 4795 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4796 | } else { |
| 4797 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4798 | + " is inactive, ignoring unregister."); |
| 4799 | // If the ImsManager is not valid, just return, since the callback |
| 4800 | // will already have been removed internally. |
| 4801 | } |
| 4802 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4803 | } finally { |
| 4804 | Binder.restoreCallingIdentity(token); |
| 4805 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4809 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4810 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4811 | |
| 4812 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4813 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4814 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4815 | final long token = Binder.clearCallingIdentity(); |
| 4816 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4817 | int slotId = getSlotIndexOrException(subId); |
| 4818 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4819 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4820 | } catch (com.android.ims.ImsException e) { |
| 4821 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4822 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4823 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4824 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4825 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4826 | } finally { |
| 4827 | Binder.restoreCallingIdentity(token); |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4832 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4833 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4834 | |
| 4835 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4836 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4837 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4838 | final long token = Binder.clearCallingIdentity(); |
| 4839 | try { |
| 4840 | Phone phone = getPhone(subId); |
| 4841 | if (phone == null) return false; |
| 4842 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4843 | } catch (com.android.ims.ImsException e) { |
| 4844 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4845 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4846 | } finally { |
| 4847 | Binder.restoreCallingIdentity(token); |
| 4848 | } |
| 4849 | } |
| 4850 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4851 | /** |
| 4852 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4853 | * subscription. |
| 4854 | * @param subId The subscription to use to check the configuration. |
| 4855 | * @param callback The callback that will be used to send the result. |
| 4856 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4857 | * @param transportType The transport type of the MmTelFeature capability. |
| 4858 | */ |
| 4859 | @Override |
| 4860 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4861 | int transportType) { |
| 4862 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4863 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4864 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4865 | "IMS not available on device."); |
| 4866 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4867 | final long token = Binder.clearCallingIdentity(); |
| 4868 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4869 | int slotId = getSlotIndex(subId); |
| 4870 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4871 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4872 | + subId + "'"); |
| 4873 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4874 | } |
| 4875 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4876 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4877 | transportType, aBoolean -> { |
| 4878 | try { |
| 4879 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4880 | } catch (RemoteException e) { |
| 4881 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4882 | + "running. Ignore"); |
| 4883 | } |
| 4884 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4885 | } catch (ImsException e) { |
| 4886 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4887 | } finally { |
| 4888 | Binder.restoreCallingIdentity(token); |
| 4889 | } |
| 4890 | } |
| 4891 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4892 | /** |
| 4893 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4894 | * @param subId The subscription to use to check the configuration. |
| 4895 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4896 | @Override |
| 4897 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4898 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4899 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4900 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4901 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4902 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4903 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4904 | final long token = Binder.clearCallingIdentity(); |
| 4905 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4906 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4907 | // 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] | 4908 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4909 | } catch (ImsException e) { |
| 4910 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(token); |
| 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4917 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4919 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4920 | |
| 4921 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4922 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4923 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4926 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4927 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4928 | // 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] | 4929 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4930 | } catch (ImsException e) { |
| 4931 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4937 | /** |
| 4938 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4939 | * @param subId The subscription to use to check the configuration. |
| 4940 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4941 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4942 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4943 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4944 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4945 | |
| 4946 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4947 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4948 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4949 | final long identity = Binder.clearCallingIdentity(); |
| 4950 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4951 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4952 | // 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] | 4953 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4954 | } catch (ImsException e) { |
| 4955 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4962 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4964 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4965 | |
| 4966 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4967 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4968 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4969 | final long identity = Binder.clearCallingIdentity(); |
| 4970 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4971 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4972 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4973 | // 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] | 4974 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4975 | } catch (ImsException e) { |
| 4976 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
| 4980 | } |
| 4981 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4982 | /** |
| 4983 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4984 | * @param subId The subscription to use to check the configuration. |
| 4985 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4986 | @Override |
| 4987 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4988 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4989 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4990 | |
| 4991 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4992 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4993 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4996 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4997 | // 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] | 4998 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4999 | } catch (ImsException e) { |
| 5000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5001 | } finally { |
| 5002 | Binder.restoreCallingIdentity(identity); |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5007 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5009 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5010 | |
| 5011 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5012 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5013 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5014 | final long identity = Binder.clearCallingIdentity(); |
| 5015 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5016 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5017 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5018 | // 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] | 5019 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5020 | } catch (ImsException e) { |
| 5021 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
| 5024 | } |
| 5025 | } |
| 5026 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5027 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5028 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5029 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5030 | * @param subId The subscription to use to check the configuration. |
| 5031 | */ |
| 5032 | @Override |
| 5033 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5034 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5035 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5036 | |
| 5037 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5038 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5039 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5040 | final long identity = Binder.clearCallingIdentity(); |
| 5041 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5042 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5043 | // 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] | 5044 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5045 | } catch (ImsException e) { |
| 5046 | throw new ServiceSpecificException(e.getCode()); |
| 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | /** |
| 5053 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5054 | * Requires MODIFY_PHONE_STATE permission. |
| 5055 | * @param subId The subscription to use to check the configuration. |
| 5056 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5057 | * false otherwise |
| 5058 | */ |
| 5059 | @Override |
| 5060 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5062 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5063 | |
| 5064 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5065 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5066 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5067 | final long identity = Binder.clearCallingIdentity(); |
| 5068 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5069 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5070 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5071 | // 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] | 5072 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5073 | } catch (ImsException e) { |
| 5074 | throw new ServiceSpecificException(e.getCode()); |
| 5075 | } finally { |
| 5076 | Binder.restoreCallingIdentity(identity); |
| 5077 | } |
| 5078 | } |
| 5079 | |
| 5080 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5081 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5082 | * @param subId The subscription to use to check the configuration. |
| 5083 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5084 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5085 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5086 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5087 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5088 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5089 | |
| 5090 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5091 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5092 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5095 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5096 | // 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] | 5097 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5098 | } catch (ImsException e) { |
| 5099 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
| 5102 | } |
| 5103 | } |
| 5104 | |
| 5105 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5106 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5108 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5109 | |
| 5110 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5111 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5112 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5115 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5116 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5117 | // 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] | 5118 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5119 | } catch (ImsException e) { |
| 5120 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5121 | } finally { |
| 5122 | Binder.restoreCallingIdentity(identity); |
| 5123 | } |
| 5124 | } |
| 5125 | |
| 5126 | @Override |
| 5127 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5129 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5130 | |
| 5131 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5132 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5133 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5134 | final long identity = Binder.clearCallingIdentity(); |
| 5135 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5136 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5137 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5138 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5139 | } catch (ImsException e) { |
| 5140 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5141 | } finally { |
| 5142 | Binder.restoreCallingIdentity(identity); |
| 5143 | } |
| 5144 | } |
| 5145 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5146 | /** |
| 5147 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5148 | * @param subId The subscription to use to check the configuration. |
| 5149 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5150 | @Override |
| 5151 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5152 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5153 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5154 | |
| 5155 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5156 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5157 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5160 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5161 | // 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] | 5162 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5163 | } catch (ImsException e) { |
| 5164 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5165 | } finally { |
| 5166 | Binder.restoreCallingIdentity(identity); |
| 5167 | } |
| 5168 | } |
| 5169 | |
| 5170 | @Override |
| 5171 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5173 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5174 | |
| 5175 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5176 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5177 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5178 | final long identity = Binder.clearCallingIdentity(); |
| 5179 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5180 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5181 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5182 | // 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] | 5183 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5184 | } catch (ImsException e) { |
| 5185 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5186 | } finally { |
| 5187 | Binder.restoreCallingIdentity(identity); |
| 5188 | } |
| 5189 | } |
| 5190 | |
| 5191 | @Override |
| 5192 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5193 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5194 | |
| 5195 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5196 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5197 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5200 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5201 | // 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] | 5202 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5203 | } catch (ImsException e) { |
| 5204 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | @Override |
| 5211 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5213 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5214 | |
| 5215 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5216 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5217 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5220 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5221 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5222 | // 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] | 5223 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5224 | } catch (ImsException e) { |
| 5225 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(identity); |
| 5228 | } |
| 5229 | } |
| 5230 | |
| 5231 | @Override |
| 5232 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5234 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5235 | |
| 5236 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5237 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5238 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5241 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5242 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5243 | // 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] | 5244 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5245 | } catch (ImsException e) { |
| 5246 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
| 5249 | } |
| 5250 | } |
| 5251 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5252 | /** |
| 5253 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5254 | * @param subId The subscription to use to check the configuration. |
| 5255 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5256 | @Override |
| 5257 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5258 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5259 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5260 | |
| 5261 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5262 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5263 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5264 | final long identity = Binder.clearCallingIdentity(); |
| 5265 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5266 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5267 | // 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] | 5268 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5269 | } catch (ImsException e) { |
| 5270 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5271 | } finally { |
| 5272 | Binder.restoreCallingIdentity(identity); |
| 5273 | } |
| 5274 | } |
| 5275 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5276 | @Override |
| 5277 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5278 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5279 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5280 | final long identity = Binder.clearCallingIdentity(); |
| 5281 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5282 | if (!isImsAvailableOnDevice()) { |
| 5283 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5284 | "IMS not available on device."); |
| 5285 | } |
| 5286 | int slotId = getSlotIndexOrException(subId); |
| 5287 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5288 | |
| 5289 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5290 | if (controller != null) { |
| 5291 | ImsManager imsManager = controller.getImsManager(subId); |
| 5292 | if (imsManager != null) { |
| 5293 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5294 | } else { |
| 5295 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5296 | } |
| 5297 | } else { |
| 5298 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5299 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5300 | } catch (ImsException e) { |
| 5301 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
| 5305 | } |
| 5306 | |
| 5307 | @Override |
| 5308 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5309 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
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(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5312 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5313 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5314 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5315 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5316 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5317 | if (controller != null) { |
| 5318 | ImsManager imsManager = controller.getImsManager(subId); |
| 5319 | if (imsManager != null) { |
| 5320 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5321 | } else { |
| 5322 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5323 | + " is inactive, ignoring unregister."); |
| 5324 | // If the ImsManager is not valid, just return, since the callback will already |
| 5325 | // have been removed internally. |
| 5326 | } |
| 5327 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
| 5330 | } |
| 5331 | } |
| 5332 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5333 | @Override |
| 5334 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5335 | IFeatureProvisioningCallback callback) { |
| 5336 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5337 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5338 | |
| 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5341 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5342 | } |
| 5343 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5344 | try { |
| 5345 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5346 | if (controller == null) { |
| 5347 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5348 | "Device does not support IMS"); |
| 5349 | } |
| 5350 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | @Override |
| 5357 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5358 | IFeatureProvisioningCallback callback) { |
| 5359 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5360 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5361 | |
| 5362 | final long identity = Binder.clearCallingIdentity(); |
| 5363 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5364 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5365 | } |
| 5366 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5367 | try { |
| 5368 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5369 | if (controller == null) { |
| 5370 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5371 | return; |
| 5372 | } |
| 5373 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5377 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5378 | |
| 5379 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5381 | message); |
| 5382 | } |
| 5383 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5384 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5385 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5386 | boolean isProvisioned) { |
| 5387 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5388 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5389 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5390 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5391 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5392 | final long identity = Binder.clearCallingIdentity(); |
| 5393 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5394 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5395 | if (controller == null) { |
| 5396 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5397 | return; |
| 5398 | } |
| 5399 | controller.setRcsProvisioningStatusForCapability( |
| 5400 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
| 5403 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | |
| 5407 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5408 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5409 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5410 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5411 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5412 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5413 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5414 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5415 | final long identity = Binder.clearCallingIdentity(); |
| 5416 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5417 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5418 | if (controller == null) { |
| 5419 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5420 | |
| 5421 | // device does not support IMS, this method will return true always. |
| 5422 | return true; |
| 5423 | } |
| 5424 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
| 5428 | } |
| 5429 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5430 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5431 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5432 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5433 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5434 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5435 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5436 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5437 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5438 | final long identity = Binder.clearCallingIdentity(); |
| 5439 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5440 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5441 | if (controller == null) { |
| 5442 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5443 | return; |
| 5444 | } |
| 5445 | controller.setImsProvisioningStatusForCapability( |
| 5446 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | @Override |
| 5453 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5454 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5455 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5456 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5457 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5458 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5459 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5460 | final long identity = Binder.clearCallingIdentity(); |
| 5461 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5462 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5463 | if (controller == null) { |
| 5464 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5465 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5466 | // device does not support IMS, this method will return true always. |
| 5467 | return true; |
| 5468 | } |
| 5469 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5470 | } finally { |
| 5471 | Binder.restoreCallingIdentity(identity); |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5476 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5477 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5478 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5479 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5480 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5481 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5482 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5485 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5486 | if (controller == null) { |
| 5487 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5488 | |
| 5489 | // device does not support IMS, this method will return false |
| 5490 | return false; |
| 5491 | } |
| 5492 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5495 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5499 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5500 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5501 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5502 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5503 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5504 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5505 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5506 | final long identity = Binder.clearCallingIdentity(); |
| 5507 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5508 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5509 | if (controller == null) { |
| 5510 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5511 | |
| 5512 | // device does not support IMS, this method will return false |
| 5513 | return false; |
| 5514 | } |
| 5515 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5516 | } finally { |
| 5517 | Binder.restoreCallingIdentity(identity); |
| 5518 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5519 | } |
| 5520 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5521 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5522 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5523 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5524 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5525 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5526 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5527 | mApp, subId, "getImsProvisioningInt"); |
| 5528 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5529 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5530 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5531 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5532 | final long identity = Binder.clearCallingIdentity(); |
| 5533 | try { |
| 5534 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5535 | int slotId = getSlotIndex(subId); |
| 5536 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5537 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5538 | + subId + "' for key:" + key); |
| 5539 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5540 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5541 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5542 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5543 | if (controller == null) { |
| 5544 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5545 | |
| 5546 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5547 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5548 | } |
| 5549 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5550 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5551 | return retVal; |
| 5552 | } |
| 5553 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5554 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5555 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5556 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5557 | + subId + "' for key:" + key); |
| 5558 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5559 | } finally { |
| 5560 | Binder.restoreCallingIdentity(identity); |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | @Override |
| 5565 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5566 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5567 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5568 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5569 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5570 | mApp, subId, "getImsProvisioningString"); |
| 5571 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5572 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5573 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5574 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | try { |
| 5577 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5578 | int slotId = getSlotIndex(subId); |
| 5579 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5580 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5581 | + subId + "' for key:" + key); |
| 5582 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5583 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5584 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5585 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5586 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5587 | + subId + "' for key:" + key); |
| 5588 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5589 | } finally { |
| 5590 | Binder.restoreCallingIdentity(identity); |
| 5591 | } |
| 5592 | } |
| 5593 | |
| 5594 | @Override |
| 5595 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5596 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5597 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5598 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5600 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5601 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5602 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5603 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5604 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5605 | final long identity = Binder.clearCallingIdentity(); |
| 5606 | try { |
| 5607 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5608 | int slotId = getSlotIndex(subId); |
| 5609 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5610 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5611 | + subId + "' for key:" + key); |
| 5612 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5613 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5614 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5615 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5616 | if (controller == null) { |
| 5617 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5618 | |
| 5619 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5620 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5621 | } |
| 5622 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5623 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5624 | return retVal; |
| 5625 | } |
| 5626 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5627 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5628 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5629 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5630 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5631 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | @Override |
| 5638 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5639 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5640 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5641 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5643 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5644 | |
| 5645 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5646 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5647 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5648 | final long identity = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5651 | int slotId = getSlotIndex(subId); |
| 5652 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5653 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5654 | + subId + "' for key:" + key); |
| 5655 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5656 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5657 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5658 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5659 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5660 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5661 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
| 5664 | } |
| 5665 | } |
| 5666 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5667 | /** |
| 5668 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5669 | * for the given slot ID or no ImsResolver instance has been created. |
| 5670 | * @param slotId The slot ID that the IMS service is created for. |
| 5671 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5672 | */ |
| 5673 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5674 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5675 | ImsFeature.FEATURE_MMTEL)) { |
| 5676 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5677 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5678 | } |
| 5679 | } |
| 5680 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5681 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5682 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5683 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5684 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5685 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5686 | } |
| 5687 | return slotId; |
| 5688 | } |
| 5689 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5690 | private int getSlotIndex(int subId) { |
| 5691 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5692 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5693 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5694 | } |
| 5695 | return slotId; |
| 5696 | } |
| 5697 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5698 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5699 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5700 | */ |
| 5701 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5702 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5703 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5704 | try { |
| 5705 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5706 | } catch (SecurityException se) { |
| 5707 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5708 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5709 | + Binder.getCallingUid()); |
| 5710 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5711 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5712 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5713 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5714 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5715 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5716 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5717 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5718 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5719 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5720 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5721 | enforceTelephonyFeatureWithException(callingPackage, |
| 5722 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | final long identity = Binder.clearCallingIdentity(); |
| 5725 | try { |
| 5726 | final Phone phone = getPhone(subId); |
| 5727 | if (phone != null) { |
| 5728 | return phone.getServiceState().getDataNetworkType(); |
| 5729 | } else { |
| 5730 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5731 | } |
| 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5734 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | /** |
| 5738 | * Returns the data network type |
| 5739 | */ |
| 5740 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5741 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5742 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5743 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * Returns the data network type for a subId |
| 5748 | */ |
| 5749 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5750 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5751 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5752 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5753 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5754 | mApp, functionName)) { |
| 5755 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5756 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5757 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5758 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5761 | enforceTelephonyFeatureWithException(callingPackage, |
| 5762 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | final long identity = Binder.clearCallingIdentity(); |
| 5765 | try { |
| 5766 | final Phone phone = getPhone(subId); |
| 5767 | if (phone != null) { |
| 5768 | return phone.getServiceState().getDataNetworkType(); |
| 5769 | } else { |
| 5770 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5771 | } |
| 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5774 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5778 | * Returns the Voice network type for a subId |
| 5779 | */ |
| 5780 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5781 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5782 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5783 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5784 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5785 | mApp, functionName)) { |
| 5786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5787 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5788 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5789 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5792 | enforceTelephonyFeatureWithException(callingPackage, |
| 5793 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5794 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5795 | final long identity = Binder.clearCallingIdentity(); |
| 5796 | try { |
| 5797 | final Phone phone = getPhone(subId); |
| 5798 | if (phone != null) { |
| 5799 | return phone.getServiceState().getVoiceNetworkType(); |
| 5800 | } else { |
| 5801 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5802 | } |
| 5803 | } finally { |
| 5804 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5805 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * @return true if a ICC card is present |
| 5810 | */ |
| 5811 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5812 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5813 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5814 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5818 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5819 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5820 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5821 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5822 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5823 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5825 | final long identity = Binder.clearCallingIdentity(); |
| 5826 | try { |
| 5827 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5828 | if (phone != null) { |
| 5829 | return phone.getIccCard().hasIccCard(); |
| 5830 | } else { |
| 5831 | return false; |
| 5832 | } |
| 5833 | } finally { |
| 5834 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5835 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * Return if the current radio is LTE on CDMA. This |
| 5840 | * is a tri-state return value as for a period of time |
| 5841 | * the mode may be unknown. |
| 5842 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5843 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5844 | * @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] | 5845 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5846 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5847 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5848 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5849 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5850 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5851 | } |
| 5852 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5853 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5854 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5855 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5856 | try { |
| 5857 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5858 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5859 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5860 | } |
| 5861 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5862 | enforceTelephonyFeatureWithException(callingPackage, |
| 5863 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5865 | final long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
| 5867 | final Phone phone = getPhone(subId); |
| 5868 | if (phone == null) { |
| 5869 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5870 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5871 | return TelephonyProperties.lte_on_cdma_device() |
| 5872 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | } |
| 5874 | } finally { |
| 5875 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5876 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5877 | } |
| 5878 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5879 | /** |
| 5880 | * {@hide} |
| 5881 | * Returns Default subId, 0 in the case of single standby. |
| 5882 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5883 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5884 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5885 | } |
| 5886 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5887 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5888 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5891 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5892 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5893 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5894 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5895 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5896 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5897 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5900 | /** |
| 5901 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5902 | */ |
| 5903 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5904 | final long identity = Binder.clearCallingIdentity(); |
| 5905 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5906 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5908 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
| 5911 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | /** |
| 5915 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5916 | */ |
| 5917 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
| 5920 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5921 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5923 | } finally { |
| 5924 | Binder.restoreCallingIdentity(identity); |
| 5925 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5926 | } |
| 5927 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5928 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5929 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5930 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5931 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5932 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5933 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5934 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5935 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5936 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5937 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5938 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5939 | } |
| 5940 | return PhoneFactory.getPhone(phoneId); |
| 5941 | } |
| 5942 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5943 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5944 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5945 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5946 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5947 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5948 | /*message=*/ "iccOpenLogicalChannel"); |
| 5949 | |
| 5950 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5951 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5952 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5953 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5954 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5955 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5956 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5957 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5958 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5959 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5960 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5961 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5962 | Phone phone; |
| 5963 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5964 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5965 | mApp, request.subId, message); |
| 5966 | phone = getPhoneFromSubId(request.subId); |
| 5967 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5968 | enforceModifyPermission(); |
| 5969 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5970 | } else { |
| 5971 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5972 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5973 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5977 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5980 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5982 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5983 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5984 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5985 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | loge("The calling package is not allowed to access ISD-R."); |
| 5987 | throw new SecurityException( |
| 5988 | "The calling package is not allowed to access ISD-R."); |
| 5989 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5990 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5991 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5994 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | return response; |
| 5996 | } finally { |
| 5997 | Binder.restoreCallingIdentity(identity); |
| 5998 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6002 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6003 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6004 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6005 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6006 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6007 | /*message=*/"iccCloseLogicalChannel"); |
| 6008 | |
| 6009 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6010 | |
| 6011 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6012 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6013 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6014 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6015 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6016 | // before this feature is enabled, this API should only return false if |
| 6017 | // the operation fails instead of throwing runtime exception for |
| 6018 | // backward-compatibility. |
| 6019 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6020 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6023 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6024 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6026 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6027 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6028 | Boolean success = false; |
| 6029 | if (result instanceof RuntimeException) { |
| 6030 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6031 | if (shouldThrowExceptionOnFailure) { |
| 6032 | throw (RuntimeException) result; |
| 6033 | } else { |
| 6034 | return false; |
| 6035 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6036 | } else if (result instanceof Boolean) { |
| 6037 | success = (Boolean) result; |
| 6038 | } else { |
| 6039 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6040 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6041 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | return success; |
| 6043 | } finally { |
| 6044 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6045 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6049 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6050 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6052 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6053 | |
| 6054 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6055 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6056 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6057 | if (DBG) { |
| 6058 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6059 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6060 | + p3 + " data=" + data); |
| 6061 | } |
| 6062 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6063 | command, p1, p2, p3, data); |
| 6064 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6065 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6066 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6067 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6068 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6069 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6070 | |
| 6071 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6072 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6073 | "iccTransmitApduLogicalChannelBySlot"); |
| 6074 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6075 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6076 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6077 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6078 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6079 | } |
| 6080 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6081 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6082 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6086 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | final long identity = Binder.clearCallingIdentity(); |
| 6088 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6089 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | return ""; |
| 6091 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6092 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6093 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6094 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6095 | null /* workSource */); |
| 6096 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | // Append the returned status code to the end of the response payload. |
| 6099 | String s = Integer.toHexString( |
| 6100 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6101 | if (response.payload != null) { |
| 6102 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6103 | } |
| 6104 | return s; |
| 6105 | } finally { |
| 6106 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6107 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6108 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6109 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6110 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6111 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6112 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6114 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6116 | |
| 6117 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6118 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6119 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6120 | if (DBG) { |
| 6121 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6122 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6123 | } |
| 6124 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6125 | cla, command, p1, p2, p3, data); |
| 6126 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6127 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6128 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6129 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6130 | 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] | 6131 | enforceModifyPermission(); |
| 6132 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6133 | |
| 6134 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6135 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6136 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6137 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6138 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6139 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6140 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6144 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6145 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6149 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6150 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | final long identity = Binder.clearCallingIdentity(); |
| 6152 | try { |
| 6153 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6154 | && TextUtils.equals(ISDR_AID, data)) { |
| 6155 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6156 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6157 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | if (bestComponent == null |
| 6159 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6160 | loge("The calling package is not allowed to select ISD-R."); |
| 6161 | throw new SecurityException( |
| 6162 | "The calling package is not allowed to select ISD-R."); |
| 6163 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6164 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6167 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6168 | null /* workSource */); |
| 6169 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | // Append the returned status code to the end of the response payload. |
| 6172 | String s = Integer.toHexString( |
| 6173 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6174 | if (response.payload != null) { |
| 6175 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6176 | } |
| 6177 | return s; |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6180 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6184 | 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] | 6185 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6186 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6187 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6188 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6189 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6190 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
| 6194 | if (DBG) { |
| 6195 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6196 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6197 | } |
| 6198 | |
| 6199 | IccIoResult response = |
| 6200 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6201 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6202 | subId); |
| 6203 | |
| 6204 | if (DBG) { |
| 6205 | log("Exchange SIM_IO [R]" + response); |
| 6206 | } |
| 6207 | |
| 6208 | byte[] result = null; |
| 6209 | int length = 2; |
| 6210 | if (response.payload != null) { |
| 6211 | length = 2 + response.payload.length; |
| 6212 | result = new byte[length]; |
| 6213 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6214 | } else { |
| 6215 | result = new byte[length]; |
| 6216 | } |
| 6217 | |
| 6218 | result[length - 1] = (byte) response.sw2; |
| 6219 | result[length - 2] = (byte) response.sw1; |
| 6220 | return result; |
| 6221 | } finally { |
| 6222 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6223 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6226 | /** |
| 6227 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6228 | * on a particular subscription |
| 6229 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6230 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6231 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6233 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6234 | return null; |
| 6235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6236 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6237 | enforceTelephonyFeatureWithException(callingPackage, |
| 6238 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | final long identity = Binder.clearCallingIdentity(); |
| 6241 | try { |
| 6242 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6243 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6244 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6245 | return null; |
| 6246 | } |
| 6247 | Object response = sendRequest( |
| 6248 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6249 | if (response instanceof String[]) { |
| 6250 | return (String[]) response; |
| 6251 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6252 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6253 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6254 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | } finally { |
| 6256 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6257 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6258 | } |
| 6259 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6260 | /** |
| 6261 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6262 | * subscription. |
| 6263 | * |
| 6264 | * @param subId the id of the subscription. |
| 6265 | * @param appType the uicc app type, must be USIM or SIM. |
| 6266 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6267 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6268 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6269 | * @return number of fplmns that is successfully written to the SIM. |
| 6270 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6271 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6272 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6274 | mApp, subId, "setForbiddenPlmns"); |
| 6275 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6276 | enforceTelephonyFeatureWithException(callingPackage, |
| 6277 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6278 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6279 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6280 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6281 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6282 | } |
| 6283 | if (fplmns == null) { |
| 6284 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6285 | } |
| 6286 | for (String fplmn : fplmns) { |
| 6287 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6288 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6289 | } |
| 6290 | } |
| 6291 | final long identity = Binder.clearCallingIdentity(); |
| 6292 | try { |
| 6293 | Object response = sendRequest( |
| 6294 | CMD_SET_FORBIDDEN_PLMNS, |
| 6295 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6296 | subId); |
| 6297 | return (int) response; |
| 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
| 6300 | } |
| 6301 | } |
| 6302 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6303 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6304 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6306 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6307 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6308 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6309 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | final long identity = Binder.clearCallingIdentity(); |
| 6312 | try { |
| 6313 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6314 | if (response.payload == null) { |
| 6315 | return ""; |
| 6316 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | // Append the returned status code to the end of the response payload. |
| 6319 | String s = Integer.toHexString( |
| 6320 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6321 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6322 | return s; |
| 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
| 6325 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6328 | /** |
| 6329 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6330 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6331 | * |
| 6332 | * @param itemID the ID of the item to read |
| 6333 | * @return the NV item as a String, or null on error. |
| 6334 | */ |
| 6335 | @Override |
| 6336 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6337 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6339 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6340 | |
| 6341 | final long identity = Binder.clearCallingIdentity(); |
| 6342 | try { |
| 6343 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6344 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6346 | return value; |
| 6347 | } finally { |
| 6348 | Binder.restoreCallingIdentity(identity); |
| 6349 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | /** |
| 6353 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6354 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6355 | * |
| 6356 | * @param itemID the ID of the item to read |
| 6357 | * @param itemValue the value to write, as a String |
| 6358 | * @return true on success; false on any failure |
| 6359 | */ |
| 6360 | @Override |
| 6361 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6362 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6363 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6364 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | |
| 6366 | final long identity = Binder.clearCallingIdentity(); |
| 6367 | try { |
| 6368 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6369 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6370 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6372 | return success; |
| 6373 | } finally { |
| 6374 | Binder.restoreCallingIdentity(identity); |
| 6375 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | /** |
| 6379 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6380 | * Used for device configuration by some CDMA operators. |
| 6381 | * |
| 6382 | * @param preferredRoamingList byte array containing the new PRL |
| 6383 | * @return true on success; false on any failure |
| 6384 | */ |
| 6385 | @Override |
| 6386 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6388 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | |
| 6390 | final long identity = Binder.clearCallingIdentity(); |
| 6391 | try { |
| 6392 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6393 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6394 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6395 | return success; |
| 6396 | } finally { |
| 6397 | Binder.restoreCallingIdentity(identity); |
| 6398 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6402 | * 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] | 6403 | * Used for device configuration by some CDMA operators. |
| 6404 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6405 | * @param slotIndex - device slot. |
| 6406 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6407 | * @return true on success; false on any failure |
| 6408 | */ |
| 6409 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6410 | public boolean resetModemConfig(int slotIndex) { |
| 6411 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6412 | if (phone != null) { |
| 6413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6414 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6416 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6417 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6418 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6419 | final long identity = Binder.clearCallingIdentity(); |
| 6420 | try { |
| 6421 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6422 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6423 | return success; |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6428 | return false; |
| 6429 | } |
| 6430 | |
| 6431 | /** |
| 6432 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6433 | * |
| 6434 | * @param slotIndex - device slot. |
| 6435 | * |
| 6436 | * @return true on success; false on any failure |
| 6437 | */ |
| 6438 | @Override |
| 6439 | public boolean rebootModem(int slotIndex) { |
| 6440 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6441 | if (phone != null) { |
| 6442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6443 | mApp, phone.getSubId(), "rebootModem"); |
| 6444 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6445 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6446 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6447 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6451 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6452 | return success; |
| 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
| 6455 | } |
| 6456 | } |
| 6457 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6458 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6459 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6460 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6461 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6462 | * {@link #disableIms(int)}. |
| 6463 | * @param slotIndex device slot. |
| 6464 | */ |
| 6465 | public void resetIms(int slotIndex) { |
| 6466 | enforceModifyPermission(); |
| 6467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6469 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6470 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6471 | final long identity = Binder.clearCallingIdentity(); |
| 6472 | try { |
| 6473 | if (mImsResolver == null) { |
| 6474 | // may happen if the does not support IMS. |
| 6475 | return; |
| 6476 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6477 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6478 | } finally { |
| 6479 | Binder.restoreCallingIdentity(identity); |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6484 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6485 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6486 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6487 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6488 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6489 | |
| 6490 | final long identity = Binder.clearCallingIdentity(); |
| 6491 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6492 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6493 | // may happen if the device does not support IMS. |
| 6494 | return; |
| 6495 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6496 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6497 | } finally { |
| 6498 | Binder.restoreCallingIdentity(identity); |
| 6499 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6503 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6504 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6505 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6506 | public void disableIms(int slotId) { |
| 6507 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6508 | |
| 6509 | final long identity = Binder.clearCallingIdentity(); |
| 6510 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6511 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6512 | // may happen if the device does not support IMS. |
| 6513 | return; |
| 6514 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6515 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | } finally { |
| 6517 | Binder.restoreCallingIdentity(identity); |
| 6518 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6519 | } |
| 6520 | |
| 6521 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6522 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6523 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6524 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6525 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6526 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6527 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6528 | |
| 6529 | final long identity = Binder.clearCallingIdentity(); |
| 6530 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6531 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6532 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6533 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6534 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6535 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6536 | } finally { |
| 6537 | Binder.restoreCallingIdentity(identity); |
| 6538 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6539 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6540 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6541 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6542 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6543 | @Override |
| 6544 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6545 | enforceModifyPermission(); |
| 6546 | |
| 6547 | final long identity = Binder.clearCallingIdentity(); |
| 6548 | try { |
| 6549 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6550 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
| 6553 | } |
| 6554 | } |
| 6555 | |
| 6556 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6557 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6558 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6559 | */ |
| 6560 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6561 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6562 | |
| 6563 | final long identity = Binder.clearCallingIdentity(); |
| 6564 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6565 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6566 | // may happen if the device does not support IMS. |
| 6567 | return null; |
| 6568 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6569 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6570 | } finally { |
| 6571 | Binder.restoreCallingIdentity(identity); |
| 6572 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6573 | } |
| 6574 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6575 | /** |
| 6576 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6577 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6578 | */ |
| 6579 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6580 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6581 | |
| 6582 | final long identity = Binder.clearCallingIdentity(); |
| 6583 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6584 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6585 | // may happen if the device does not support IMS. |
| 6586 | return null; |
| 6587 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6588 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | } finally { |
| 6590 | Binder.restoreCallingIdentity(identity); |
| 6591 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6592 | } |
| 6593 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6594 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6595 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6596 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6597 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6598 | * @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] | 6599 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6600 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6601 | * @param packageName The name of the package that the current configuration will be replaced |
| 6602 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6603 | * @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] | 6604 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6605 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6606 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6607 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6609 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | final long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6613 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6614 | // may happen if the device does not support IMS. |
| 6615 | return false; |
| 6616 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6617 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6618 | for (int featureType : featureTypes) { |
| 6619 | featureConfig.put(featureType, packageName); |
| 6620 | } |
| 6621 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6622 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
| 6625 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6629 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6630 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6631 | * |
| 6632 | * This should only be used for testing. |
| 6633 | * |
| 6634 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6635 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6636 | */ |
| 6637 | @Override |
| 6638 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6639 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6640 | "clearCarrierImsServiceOverride"); |
| 6641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6642 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6643 | |
| 6644 | final long identity = Binder.clearCallingIdentity(); |
| 6645 | try { |
| 6646 | if (mImsResolver == null) { |
| 6647 | // may happen if the device does not support IMS. |
| 6648 | return false; |
| 6649 | } |
| 6650 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(identity); |
| 6653 | } |
| 6654 | } |
| 6655 | |
| 6656 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6657 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6658 | * |
| 6659 | * @param slotId The slot that the ImsService is associated with. |
| 6660 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6661 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6662 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6663 | * @return the package name of the ImsService configuration. |
| 6664 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6665 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6666 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6667 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6668 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6669 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6670 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6671 | final long identity = Binder.clearCallingIdentity(); |
| 6672 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6673 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6674 | // may happen if the device does not support IMS. |
| 6675 | return ""; |
| 6676 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6677 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6678 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6679 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6680 | } finally { |
| 6681 | Binder.restoreCallingIdentity(identity); |
| 6682 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6683 | } |
| 6684 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6685 | /** |
| 6686 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6687 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6688 | * @param callback A callback with an integer containing the |
| 6689 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6690 | */ |
| 6691 | @Override |
| 6692 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6693 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6694 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6695 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6696 | "IMS not available on device."); |
| 6697 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6698 | final long token = Binder.clearCallingIdentity(); |
| 6699 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6700 | int slotId = getSlotIndex(subId); |
| 6701 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6702 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6703 | + subId + "'"); |
| 6704 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6705 | } |
| 6706 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6707 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6708 | try { |
| 6709 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6710 | } catch (RemoteException e) { |
| 6711 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6712 | + "Ignore"); |
| 6713 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6714 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6715 | } catch (ImsException e) { |
| 6716 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6717 | } finally { |
| 6718 | Binder.restoreCallingIdentity(token); |
| 6719 | } |
| 6720 | } |
| 6721 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6722 | /** |
| 6723 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6724 | */ |
| 6725 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6726 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | |
| 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6730 | // NOTE: Before S, this method only set the default phone. |
| 6731 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6732 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6733 | phone.setImsRegistrationState(registered); |
| 6734 | } |
| 6735 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | } finally { |
| 6737 | Binder.restoreCallingIdentity(identity); |
| 6738 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6742 | * Set the network selection mode to automatic. |
| 6743 | * |
| 6744 | */ |
| 6745 | @Override |
| 6746 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6748 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6749 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6750 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6751 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6753 | final long identity = Binder.clearCallingIdentity(); |
| 6754 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6755 | if (!isActiveSubscription(subId)) { |
| 6756 | return; |
| 6757 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6758 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6759 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6760 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(identity); |
| 6763 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6764 | } |
| 6765 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6766 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6767 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6768 | * |
| 6769 | * @param subId the id of the subscription. |
| 6770 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6771 | * the operator to attach to. |
| 6772 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6773 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6774 | * normal network selection next time. |
| 6775 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6776 | */ |
| 6777 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6778 | public boolean setNetworkSelectionModeManual( |
| 6779 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6781 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6782 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6783 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6784 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6785 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6786 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6787 | if (!isActiveSubscription(subId)) { |
| 6788 | return false; |
| 6789 | } |
| 6790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6791 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6792 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6793 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6794 | if (DBG) { |
| 6795 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6796 | + " operator: " + operatorInfo); |
| 6797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6798 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6799 | } finally { |
| 6800 | Binder.restoreCallingIdentity(identity); |
| 6801 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6802 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6803 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6804 | * Get the manual network selection |
| 6805 | * |
| 6806 | * @param subId the id of the subscription. |
| 6807 | * |
| 6808 | * @return the previously saved user selected PLMN |
| 6809 | */ |
| 6810 | @Override |
| 6811 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6812 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6813 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6814 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6815 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6816 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6817 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6818 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6819 | final long identity = Binder.clearCallingIdentity(); |
| 6820 | try { |
| 6821 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6822 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | final Phone phone = getPhone(subId); |
| 6826 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6827 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6828 | } |
| 6829 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6830 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6831 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6832 | } finally { |
| 6833 | Binder.restoreCallingIdentity(identity); |
| 6834 | } |
| 6835 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6836 | |
| 6837 | /** |
| 6838 | * Scans for available networks. |
| 6839 | */ |
| 6840 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6841 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6842 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6844 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6845 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6846 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6847 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6848 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6849 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6850 | .setCallingPid(Binder.getCallingPid()) |
| 6851 | .setCallingUid(Binder.getCallingUid()) |
| 6852 | .setMethod("getCellNetworkScanResults") |
| 6853 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6854 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6855 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6856 | .build()); |
| 6857 | switch (locationResult) { |
| 6858 | case DENIED_HARD: |
| 6859 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6860 | case DENIED_SOFT: |
| 6861 | return null; |
| 6862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6864 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 | try { |
| 6866 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6867 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6869 | } finally { |
| 6870 | Binder.restoreCallingIdentity(identity); |
| 6871 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6872 | } |
| 6873 | |
| 6874 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6875 | * Get the call forwarding info, given the call forwarding reason. |
| 6876 | */ |
| 6877 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6878 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6879 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6880 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6881 | |
| 6882 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6883 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6884 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6885 | long identity = Binder.clearCallingIdentity(); |
| 6886 | try { |
| 6887 | if (DBG) { |
| 6888 | log("getCallForwarding: subId " + subId |
| 6889 | + " callForwardingReason" + callForwardingReason); |
| 6890 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6891 | |
| 6892 | Phone phone = getPhone(subId); |
| 6893 | if (phone == null) { |
| 6894 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6895 | callback.onError( |
| 6896 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6897 | } catch (RemoteException e) { |
| 6898 | // ignore |
| 6899 | } |
| 6900 | return; |
| 6901 | } |
| 6902 | |
| 6903 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6904 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6905 | @Override |
| 6906 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6907 | try { |
| 6908 | callback.onCallForwardingInfoAvailable(info); |
| 6909 | } catch (RemoteException e) { |
| 6910 | // ignore |
| 6911 | } |
| 6912 | } |
| 6913 | |
| 6914 | @Override |
| 6915 | public void onError(int error) { |
| 6916 | try { |
| 6917 | callback.onError(error); |
| 6918 | } catch (RemoteException e) { |
| 6919 | // ignore |
| 6920 | } |
| 6921 | } |
| 6922 | }); |
| 6923 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6924 | } finally { |
| 6925 | Binder.restoreCallingIdentity(identity); |
| 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | /** |
| 6930 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6931 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6932 | */ |
| 6933 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6934 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6935 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6936 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6937 | |
| 6938 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6939 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6940 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6941 | long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
| 6943 | if (DBG) { |
| 6944 | log("setCallForwarding: subId " + subId |
| 6945 | + " callForwardingInfo" + callForwardingInfo); |
| 6946 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6947 | |
| 6948 | Phone phone = getPhone(subId); |
| 6949 | if (phone == null) { |
| 6950 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6951 | callback.accept( |
| 6952 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6953 | } catch (RemoteException e) { |
| 6954 | // ignore |
| 6955 | } |
| 6956 | return; |
| 6957 | } |
| 6958 | |
| 6959 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6960 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6961 | |
| 6962 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6963 | } finally { |
| 6964 | Binder.restoreCallingIdentity(identity); |
| 6965 | } |
| 6966 | } |
| 6967 | |
| 6968 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6969 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6970 | */ |
| 6971 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6972 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6973 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6974 | |
| 6975 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6976 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6977 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6978 | long identity = Binder.clearCallingIdentity(); |
| 6979 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6980 | Phone phone = getPhone(subId); |
| 6981 | if (phone == null) { |
| 6982 | try { |
| 6983 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6984 | } catch (RemoteException e) { |
| 6985 | // ignore |
| 6986 | } |
| 6987 | return; |
| 6988 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6989 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6990 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6991 | boolean requireUssd = c.getBoolean( |
| 6992 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6993 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6994 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6995 | if (requireUssd) { |
| 6996 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6997 | getSubscriptionCarrierId(subId)); |
| 6998 | String newUssdCommand = ""; |
| 6999 | try { |
| 7000 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7001 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7002 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7003 | } catch (NullPointerException e) { |
| 7004 | loge("Failed to generate USSD number" + e); |
| 7005 | } |
| 7006 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7007 | mMainThreadHandler, callback, carrierXmlParser, |
| 7008 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7009 | final String ussdCommand = newUssdCommand; |
| 7010 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7011 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7012 | }); |
| 7013 | } else { |
| 7014 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7015 | callback::accept); |
| 7016 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7017 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7018 | } finally { |
| 7019 | Binder.restoreCallingIdentity(identity); |
| 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7024 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7025 | */ |
| 7026 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7027 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7028 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7029 | |
| 7030 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7031 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7032 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7033 | long identity = Binder.clearCallingIdentity(); |
| 7034 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7035 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7036 | |
| 7037 | Phone phone = getPhone(subId); |
| 7038 | if (phone == null) { |
| 7039 | try { |
| 7040 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7041 | } catch (RemoteException e) { |
| 7042 | // ignore |
| 7043 | } |
| 7044 | return; |
| 7045 | } |
| 7046 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7047 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7048 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7049 | boolean requireUssd = c.getBoolean( |
| 7050 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7051 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7052 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7053 | if (requireUssd) { |
| 7054 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7055 | getSubscriptionCarrierId(subId)); |
| 7056 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7057 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7058 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7059 | String newUssdCommand = ""; |
| 7060 | try { |
| 7061 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7062 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7063 | .makeCommand(ssAction, null); |
| 7064 | } catch (NullPointerException e) { |
| 7065 | loge("Failed to generate USSD number" + e); |
| 7066 | } |
| 7067 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7068 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7069 | final String ussdCommand = newUssdCommand; |
| 7070 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7071 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7072 | }); |
| 7073 | } else { |
| 7074 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7075 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7076 | |
| 7077 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7078 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7079 | } finally { |
| 7080 | Binder.restoreCallingIdentity(identity); |
| 7081 | } |
| 7082 | } |
| 7083 | |
| 7084 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7085 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7086 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7087 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7088 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7089 | * location related information which will be sent if the caller already possess |
| 7090 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7091 | * @param request contains the radio access networks with bands/channels to scan |
| 7092 | * @param messenger callback messenger for scan results or errors |
| 7093 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7094 | * @return the id of the requested scan which can be used to stop the scan. |
| 7095 | */ |
| 7096 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7097 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7098 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7099 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7101 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7102 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7103 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7104 | if (!renounceFineLocationAccess) { |
| 7105 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7106 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7107 | .setCallingPackage(callingPackage) |
| 7108 | .setCallingFeatureId(callingFeatureId) |
| 7109 | .setCallingPid(Binder.getCallingPid()) |
| 7110 | .setCallingUid(Binder.getCallingUid()) |
| 7111 | .setMethod("requestNetworkScan") |
| 7112 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7113 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7114 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7115 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7116 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7117 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7118 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7119 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7120 | if (e != null) { |
| 7121 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7122 | throw e; |
| 7123 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7124 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7125 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7126 | } |
| 7127 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7129 | |
| 7130 | enforceTelephonyFeatureWithException(callingPackage, |
| 7131 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7132 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7133 | int callingUid = Binder.getCallingUid(); |
| 7134 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7135 | final long identity = Binder.clearCallingIdentity(); |
| 7136 | try { |
| 7137 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7138 | renounceFineLocationAccess, request, messenger, binder, |
| 7139 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7140 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7141 | } finally { |
| 7142 | Binder.restoreCallingIdentity(identity); |
| 7143 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7144 | } |
| 7145 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7146 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7147 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7148 | boolean hasCarrierPriv; |
| 7149 | final long identity = Binder.clearCallingIdentity(); |
| 7150 | try { |
| 7151 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7152 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7156 | boolean hasNetworkScanPermission = |
| 7157 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7158 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7159 | |
| 7160 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7161 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7162 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7166 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7167 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7168 | return new SecurityException("Specific channels must not be" |
| 7169 | + " scanned without location access."); |
| 7170 | } |
| 7171 | } |
| 7172 | } |
| 7173 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7174 | return null; |
| 7175 | } |
| 7176 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7177 | /** |
| 7178 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7179 | * |
| 7180 | * @param subId id of the subscription |
| 7181 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7182 | */ |
| 7183 | @Override |
| 7184 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7185 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7186 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7188 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7189 | final long identity = Binder.clearCallingIdentity(); |
| 7190 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7191 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7192 | } finally { |
| 7193 | Binder.restoreCallingIdentity(identity); |
| 7194 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7195 | } |
| 7196 | |
| 7197 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7198 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7199 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7200 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7201 | */ |
| 7202 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7203 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7204 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7205 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7206 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7207 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7208 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7209 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7211 | final long identity = Binder.clearCallingIdentity(); |
| 7212 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7213 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7214 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7215 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7216 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7217 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
| 7220 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7224 | * Get the allowed network types for certain reason. |
| 7225 | * |
| 7226 | * @param subId the id of the subscription. |
| 7227 | * @param reason the reason the allowed network type change is taking place |
| 7228 | * @return the allowed network types. |
| 7229 | */ |
| 7230 | @Override |
| 7231 | public long getAllowedNetworkTypesForReason(int subId, |
| 7232 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7233 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7234 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7235 | |
| 7236 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7237 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7238 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7241 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
| 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7248 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7249 | * @param subId subscription id of the sim card |
| 7250 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7251 | * This can be passed following states |
| 7252 | * <ol> |
| 7253 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7254 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7255 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7256 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7257 | * </ol> |
| 7258 | * @return operation result. |
| 7259 | */ |
| 7260 | @Override |
| 7261 | public int setNrDualConnectivityState(int subId, |
| 7262 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7264 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7265 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7266 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7267 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7268 | } |
| 7269 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7270 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7271 | final long identity = Binder.clearCallingIdentity(); |
| 7272 | try { |
| 7273 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7274 | nrDualConnectivityState, subId, |
| 7275 | workSource); |
| 7276 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7277 | return result; |
| 7278 | } finally { |
| 7279 | Binder.restoreCallingIdentity(identity); |
| 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | /** |
| 7284 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7285 | * @return true if dual connectivity is enabled else false |
| 7286 | */ |
| 7287 | @Override |
| 7288 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7289 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7290 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7291 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7292 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7293 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7294 | return false; |
| 7295 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7296 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7297 | final long identity = Binder.clearCallingIdentity(); |
| 7298 | try { |
| 7299 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7300 | null, subId, workSource); |
| 7301 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7302 | return isEnabled; |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
| 7305 | } |
| 7306 | } |
| 7307 | |
| 7308 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7309 | * Set the allowed network types of the device and |
| 7310 | * provide the reason triggering the allowed network change. |
| 7311 | * |
| 7312 | * @param subId the id of the subscription. |
| 7313 | * @param reason the reason the allowed network type change is taking place |
| 7314 | * @param allowedNetworkTypes the allowed network types. |
| 7315 | * @return true on success; false on any failure. |
| 7316 | */ |
| 7317 | @Override |
| 7318 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7319 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7320 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7322 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7323 | // If the caller only has carrier privileges, then they should not be able to override |
| 7324 | // any network types which were set for security reasons. |
| 7325 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7326 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7327 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7328 | throw new SecurityException( |
| 7329 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7330 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7331 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7332 | |
| 7333 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7334 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7335 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7336 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7337 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7338 | return false; |
| 7339 | } |
| 7340 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7341 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7342 | return false; |
| 7343 | } |
| 7344 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7345 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7346 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7347 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7348 | Phone phone = getPhone(subId); |
| 7349 | if (phone == null) { |
| 7350 | return false; |
| 7351 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7352 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7353 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7354 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7355 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7356 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7357 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7358 | final long identity = Binder.clearCallingIdentity(); |
| 7359 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7360 | Boolean success = (Boolean) sendRequest( |
| 7361 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7362 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7363 | |
| 7364 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7365 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | } |
| 7369 | } |
| 7370 | |
| 7371 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7372 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7373 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7374 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7375 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7376 | * @hide |
| 7377 | */ |
| 7378 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7379 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7380 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7381 | |
| 7382 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7383 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7384 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7386 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7387 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7388 | if (phone != null) { |
| 7389 | return phone.hasMatchedTetherApnSetting(); |
| 7390 | } else { |
| 7391 | return false; |
| 7392 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7395 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7396 | } |
| 7397 | |
| 7398 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7399 | * Get the user enabled state of Mobile Data. |
| 7400 | * |
| 7401 | * TODO: remove and use isUserDataEnabled. |
| 7402 | * This can't be removed now because some vendor codes |
| 7403 | * calls through ITelephony directly while they should |
| 7404 | * use TelephonyManager. |
| 7405 | * |
| 7406 | * @return true on enabled |
| 7407 | */ |
| 7408 | @Override |
| 7409 | public boolean getDataEnabled(int subId) { |
| 7410 | return isUserDataEnabled(subId); |
| 7411 | } |
| 7412 | |
| 7413 | /** |
| 7414 | * Get whether mobile data is enabled per user setting. |
| 7415 | * |
| 7416 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7417 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7418 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7419 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7420 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7421 | * |
| 7422 | * @return {@code true} if data is enabled else {@code false} |
| 7423 | */ |
| 7424 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7425 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7426 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7427 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7428 | try { |
| 7429 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7430 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7431 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7432 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7433 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7434 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7435 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7436 | mApp, subId, functionName); |
| 7437 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7438 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | |
| 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7442 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7444 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7445 | if (phone != null) { |
| 7446 | boolean retVal = phone.isUserDataEnabled(); |
| 7447 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7448 | return retVal; |
| 7449 | } else { |
| 7450 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7451 | return false; |
| 7452 | } |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7455 | } |
| 7456 | } |
| 7457 | |
| 7458 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7459 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7460 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7461 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7462 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7463 | * @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] | 7464 | */ |
| 7465 | @Override |
| 7466 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7467 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7468 | try { |
| 7469 | try { |
| 7470 | mApp.enforceCallingOrSelfPermission( |
| 7471 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7472 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7473 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7474 | try { |
| 7475 | mApp.enforceCallingOrSelfPermission( |
| 7476 | android.Manifest.permission.READ_PHONE_STATE, |
| 7477 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7478 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7479 | mApp.enforceCallingOrSelfPermission( |
| 7480 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7481 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7482 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7483 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7484 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7485 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7487 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7488 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | final long identity = Binder.clearCallingIdentity(); |
| 7491 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7492 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7494 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7495 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7496 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | return retVal; |
| 7498 | } else { |
| 7499 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7500 | return false; |
| 7501 | } |
| 7502 | } finally { |
| 7503 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7504 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7505 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7506 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7507 | /** |
| 7508 | * Check if data is enabled for a specific reason |
| 7509 | * @param subId Subscription index |
| 7510 | * @param reason the reason the data enable change is taking place |
| 7511 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7512 | */ |
| 7513 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7514 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7515 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7516 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7517 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7518 | try { |
| 7519 | mApp.enforceCallingOrSelfPermission( |
| 7520 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7521 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7522 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7523 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7524 | functionName); |
| 7525 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7526 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7527 | try { |
| 7528 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7529 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7530 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7532 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7533 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7534 | } |
| 7535 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7536 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7537 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7538 | |
| 7539 | final long identity = Binder.clearCallingIdentity(); |
| 7540 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7541 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7542 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7543 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7544 | + " reason=" + reason); |
| 7545 | } |
| 7546 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7547 | if (phone != null) { |
| 7548 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7549 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7550 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7551 | return retVal; |
| 7552 | } else { |
| 7553 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7554 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7555 | + subId + " retVal=false"); |
| 7556 | } |
| 7557 | return false; |
| 7558 | } |
| 7559 | } finally { |
| 7560 | Binder.restoreCallingIdentity(identity); |
| 7561 | } |
| 7562 | } |
| 7563 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7564 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7565 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7566 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7567 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7568 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7569 | // No permission needed; this only lets the caller inspect their own status. |
| 7570 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7571 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7572 | |
| 7573 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7574 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7575 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7576 | |
| 7577 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7578 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7579 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7580 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7581 | } |
| 7582 | |
| 7583 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7584 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7585 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7586 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7587 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7588 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7589 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7590 | if (cpt == null) { |
| 7591 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7592 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7593 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7594 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7598 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7599 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7600 | |
| 7601 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7602 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7603 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7604 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7605 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7606 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7607 | Phone phone = getPhone(subId); |
| 7608 | if (phone == null) { |
| 7609 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7610 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7611 | } |
| 7612 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7613 | if (cpt == null) { |
| 7614 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7615 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7616 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7617 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | @Override |
| 7621 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7622 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7623 | |
| 7624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7625 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7626 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7627 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7628 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7629 | } |
| 7630 | |
| 7631 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7632 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7633 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7634 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7635 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7636 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7637 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7638 | if (phone == null) { |
| 7639 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7640 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7641 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7642 | if (cpt == null) { |
| 7643 | continue; |
| 7644 | } |
| 7645 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7646 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7647 | break; |
| 7648 | } |
| 7649 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7650 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7651 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7652 | |
| 7653 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7654 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7655 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7656 | |
| 7657 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7658 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7659 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7660 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7661 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7662 | if (phone == null) { |
| 7663 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7664 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7665 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7666 | if (cpt == null) { |
| 7667 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7668 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7669 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7672 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7673 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7674 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7675 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7676 | if (phone == null) { |
| 7677 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7678 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7679 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7680 | if (cpt == null) { |
| 7681 | return Collections.emptyList(); |
| 7682 | } |
| 7683 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7684 | } |
| 7685 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7686 | @Override |
| 7687 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7688 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7689 | |
| 7690 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7691 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7692 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7693 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7694 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7695 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7696 | try { |
| 7697 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7698 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7699 | } |
| 7700 | } finally { |
| 7701 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7702 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7703 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7704 | } |
| 7705 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7706 | @Override |
| 7707 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7708 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7709 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7710 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7711 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7712 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7713 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7714 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7715 | if (phone == null) { |
| 7716 | return null; |
| 7717 | } |
| 7718 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7719 | if (cpt == null) { |
| 7720 | return null; |
| 7721 | } |
| 7722 | return cpt.getCarrierServicePackageName(); |
| 7723 | } |
| 7724 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7725 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7726 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7727 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7728 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7729 | return null; |
| 7730 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7731 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7732 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7733 | return null; |
| 7734 | } |
| 7735 | return iccId; |
| 7736 | } |
| 7737 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7738 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7739 | public void setCallComposerStatus(int subId, int status) { |
| 7740 | enforceModifyPermission(); |
| 7741 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7742 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7743 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7744 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7745 | final long identity = Binder.clearCallingIdentity(); |
| 7746 | try { |
| 7747 | Phone phone = getPhone(subId); |
| 7748 | if (phone != null) { |
| 7749 | Phone defaultPhone = phone.getImsPhone(); |
| 7750 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7751 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7752 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7753 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7754 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7755 | } |
| 7756 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7757 | } catch (ImsException e) { |
| 7758 | throw new ServiceSpecificException(e.getCode()); |
| 7759 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7760 | Binder.restoreCallingIdentity(identity); |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | @Override |
| 7765 | public int getCallComposerStatus(int subId) { |
| 7766 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7767 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7768 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7769 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7770 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7771 | final long identity = Binder.clearCallingIdentity(); |
| 7772 | try { |
| 7773 | Phone phone = getPhone(subId); |
| 7774 | if (phone != null) { |
| 7775 | Phone defaultPhone = phone.getImsPhone(); |
| 7776 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7777 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7778 | return imsPhone.getCallComposerStatus(); |
| 7779 | } |
| 7780 | } |
| 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
| 7783 | } |
| 7784 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7785 | } |
| 7786 | |
| 7787 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7788 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7789 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7790 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7791 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7793 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7794 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7795 | "setLine1NumberForDisplayForSubscriber"); |
| 7796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | final long identity = Binder.clearCallingIdentity(); |
| 7798 | try { |
| 7799 | final String iccId = getIccId(subId); |
| 7800 | final Phone phone = getPhone(subId); |
| 7801 | if (phone == null) { |
| 7802 | return false; |
| 7803 | } |
| 7804 | final String subscriberId = phone.getSubscriberId(); |
| 7805 | |
| 7806 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7807 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | + subscriberId + " to " + number); |
| 7809 | } |
| 7810 | |
| 7811 | if (TextUtils.isEmpty(iccId)) { |
| 7812 | return false; |
| 7813 | } |
| 7814 | |
| 7815 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7816 | |
| 7817 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7818 | if (alphaTag == null) { |
| 7819 | editor.remove(alphaTagPrefKey); |
| 7820 | } else { |
| 7821 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7822 | } |
| 7823 | |
| 7824 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7825 | // track all merged IMSIs based on line number |
| 7826 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7827 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7828 | if (number == null) { |
| 7829 | editor.remove(numberPrefKey); |
| 7830 | editor.remove(subscriberPrefKey); |
| 7831 | } else { |
| 7832 | editor.putString(numberPrefKey, number); |
| 7833 | editor.putString(subscriberPrefKey, subscriberId); |
| 7834 | } |
| 7835 | |
| 7836 | editor.commit(); |
| 7837 | return true; |
| 7838 | } finally { |
| 7839 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7840 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7841 | } |
| 7842 | |
| 7843 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7844 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7845 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7846 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7847 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7848 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7849 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7850 | return null; |
| 7851 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7852 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7853 | enforceTelephonyFeatureWithException(callingPackage, |
| 7854 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7855 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | String iccId = getIccId(subId); |
| 7859 | if (iccId != null) { |
| 7860 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7861 | if (DBG_MERGE) { |
| 7862 | log("getLine1NumberForDisplay returning " |
| 7863 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7864 | } |
| 7865 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7866 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7867 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7868 | return null; |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7871 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
| 7874 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7875 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7876 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7878 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7879 | return null; |
| 7880 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7882 | final long identity = Binder.clearCallingIdentity(); |
| 7883 | try { |
| 7884 | String iccId = getIccId(subId); |
| 7885 | if (iccId != null) { |
| 7886 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7887 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7888 | } |
| 7889 | return null; |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7892 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7893 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7894 | |
| 7895 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7896 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7897 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7898 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7899 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7900 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7901 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7902 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7903 | return null; |
| 7904 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7905 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7906 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7907 | // the process, where TelephonyManager was instantiated. |
| 7908 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7909 | final long identity = Binder.clearCallingIdentity(); |
| 7910 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7911 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7912 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7913 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7914 | |
| 7915 | // Figure out what subscribers are currently active |
| 7916 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7917 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7918 | // Only consider subs which match the current subId |
| 7919 | // This logic can be simplified. See b/131189269 for progress. |
| 7920 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7921 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7922 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7923 | |
| 7924 | // First pass, find a number override for an active subscriber |
| 7925 | String mergeNumber = null; |
| 7926 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7927 | for (String key : prefs.keySet()) { |
| 7928 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7929 | final String subscriberId = (String) prefs.get(key); |
| 7930 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7931 | final String iccId = key.substring( |
| 7932 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7933 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7934 | mergeNumber = (String) prefs.get(numberKey); |
| 7935 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7936 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7937 | + " for active subscriber " + subscriberId); |
| 7938 | } |
| 7939 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7940 | break; |
| 7941 | } |
| 7942 | } |
| 7943 | } |
| 7944 | } |
| 7945 | |
| 7946 | // Shortcut when no active merged subscribers |
| 7947 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7948 | return null; |
| 7949 | } |
| 7950 | |
| 7951 | // Second pass, find all subscribers under that line override |
| 7952 | final ArraySet<String> result = new ArraySet<>(); |
| 7953 | for (String key : prefs.keySet()) { |
| 7954 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7955 | final String number = (String) prefs.get(key); |
| 7956 | if (mergeNumber.equals(number)) { |
| 7957 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7958 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7959 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7960 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7961 | result.add(subscriberId); |
| 7962 | } |
| 7963 | } |
| 7964 | } |
| 7965 | } |
| 7966 | |
| 7967 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7968 | Arrays.sort(resultArray); |
| 7969 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7970 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7971 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7972 | } |
| 7973 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7976 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7977 | } |
| 7978 | |
| 7979 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7980 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7981 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7982 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7983 | enforceTelephonyFeatureWithException(callingPackage, |
| 7984 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7985 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7986 | final long identity = Binder.clearCallingIdentity(); |
| 7987 | try { |
| 7988 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7989 | TelephonyManager.class); |
| 7990 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7991 | if (subscriberId == null) { |
| 7992 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7993 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7994 | + subId); |
| 7995 | } |
| 7996 | return null; |
| 7997 | } |
| 7998 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7999 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8000 | .getSubscriptionInfo(subId); |
| 8001 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8002 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8003 | if (groupUuid == null) { |
| 8004 | return new String[]{subscriberId}; |
| 8005 | } |
| 8006 | |
| 8007 | // Get all subscriberIds from the group. |
| 8008 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8009 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8010 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8011 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8012 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8013 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8014 | if (subscriberId != null) { |
| 8015 | mergedSubscriberIds.add(subscriberId); |
| 8016 | } |
| 8017 | } |
| 8018 | |
| 8019 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8020 | } finally { |
| 8021 | Binder.restoreCallingIdentity(identity); |
| 8022 | |
| 8023 | } |
| 8024 | } |
| 8025 | |
| 8026 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8027 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8028 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8029 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8030 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8031 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8032 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8034 | final long identity = Binder.clearCallingIdentity(); |
| 8035 | try { |
| 8036 | final Phone phone = getPhone(subId); |
| 8037 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8038 | } finally { |
| 8039 | Binder.restoreCallingIdentity(identity); |
| 8040 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8041 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8042 | |
| 8043 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8044 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8045 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8046 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8047 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8048 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | |
| 8050 | final long identity = Binder.clearCallingIdentity(); |
| 8051 | try { |
| 8052 | final Phone phone = getPhone(subId); |
| 8053 | if (phone == null) { |
| 8054 | return false; |
| 8055 | } |
| 8056 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8057 | cdmaNonRoamingList); |
| 8058 | } finally { |
| 8059 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8060 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8061 | } |
| 8062 | |
| 8063 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8064 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8065 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8066 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8067 | if (phone == null) { |
| 8068 | return raf; |
| 8069 | } |
| 8070 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8071 | try { |
| 8072 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8073 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8074 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8075 | } catch (SecurityException e) { |
| 8076 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8077 | throw e; |
| 8078 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8079 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8080 | enforceTelephonyFeatureWithException(callingPackage, |
| 8081 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | final long identity = Binder.clearCallingIdentity(); |
| 8084 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8085 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
| 8088 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8089 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8090 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8091 | |
| 8092 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8093 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8094 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8095 | try { |
| 8096 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8097 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8098 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8099 | } |
| 8100 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8101 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8102 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8103 | |
| 8104 | enforceTelephonyFeatureWithException(callingPackage, |
| 8105 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8106 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8107 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8108 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8109 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8110 | throw new SecurityException("App must be the dialer role holder to" |
| 8111 | + " upload a call composer pic"); |
| 8112 | } |
| 8113 | |
| 8114 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8115 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8116 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8117 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8118 | boolean readUntilEnd = false; |
| 8119 | int totalBytesRead = 0; |
| 8120 | byte[] buffer = new byte[16 * 1024]; |
| 8121 | while (true) { |
| 8122 | int numRead; |
| 8123 | try { |
| 8124 | numRead = input.read(buffer); |
| 8125 | } catch (IOException e) { |
| 8126 | try { |
| 8127 | fd.checkError(); |
| 8128 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8129 | null); |
| 8130 | } catch (IOException e1) { |
| 8131 | // This means that the other side closed explicitly with an error. If this |
| 8132 | // happens, log and ignore. |
| 8133 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8134 | } |
| 8135 | break; |
| 8136 | } |
| 8137 | if (numRead == -1) { |
| 8138 | readUntilEnd = true; |
| 8139 | break; |
| 8140 | } |
| 8141 | totalBytesRead += numRead; |
| 8142 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8143 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8144 | try { |
| 8145 | input.close(); |
| 8146 | } catch (IOException e) { |
| 8147 | // ignore |
| 8148 | } |
| 8149 | break; |
| 8150 | } |
| 8151 | output.write(buffer, 0, numRead); |
| 8152 | } |
| 8153 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8154 | // close is above, where the picture size is too big. |
| 8155 | |
| 8156 | try { |
| 8157 | fd.checkError(); |
| 8158 | } catch (IOException e) { |
| 8159 | loge("Remote end for call composer closed with an error: " + e); |
| 8160 | return; |
| 8161 | } |
| 8162 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8163 | if (!readUntilEnd) { |
| 8164 | loge("Did not finish reading entire image; aborting"); |
| 8165 | return; |
| 8166 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8167 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8168 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8169 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8170 | new CallComposerPictureTransfer.Factory() {}, |
| 8171 | imageData, |
| 8172 | (result) -> { |
| 8173 | if (result.first != null) { |
| 8174 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8175 | Bundle outputResult = new Bundle(); |
| 8176 | outputResult.putParcelable( |
| 8177 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8178 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8179 | outputResult); |
| 8180 | } else { |
| 8181 | callback.send(result.second, null); |
| 8182 | } |
| 8183 | } |
| 8184 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8185 | }); |
| 8186 | } |
| 8187 | |
| 8188 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8189 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8190 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8191 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8193 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8194 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8198 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8199 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8203 | } |
| 8204 | |
| 8205 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8206 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8207 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8208 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8209 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8210 | return false; |
| 8211 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8212 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8213 | enforceTelephonyFeatureWithException(callingPackage, |
| 8214 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8216 | final long identity = Binder.clearCallingIdentity(); |
| 8217 | try { |
| 8218 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8219 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8220 | // In the long run, we may instead need to check if there exists a connection service |
| 8221 | // which can support video calling. |
| 8222 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8223 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | return imsManager.isVtEnabledByPlatform() |
| 8225 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8226 | && imsManager.isVtEnabledByUser(); |
| 8227 | } finally { |
| 8228 | Binder.restoreCallingIdentity(identity); |
| 8229 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8230 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8231 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8232 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8233 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8234 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8236 | mApp, subId, callingPackage, callingFeatureId, |
| 8237 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | return false; |
| 8239 | } |
| 8240 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8241 | enforceTelephonyFeatureWithException(callingPackage, |
| 8242 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | final long identity = Binder.clearCallingIdentity(); |
| 8245 | try { |
| 8246 | CarrierConfigManager configManager = |
| 8247 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8248 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8249 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8250 | } finally { |
| 8251 | Binder.restoreCallingIdentity(identity); |
| 8252 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8253 | } |
| 8254 | |
| 8255 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8256 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8258 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8259 | return false; |
| 8260 | } |
| 8261 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8262 | enforceTelephonyFeatureWithException(callingPackage, |
| 8263 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8265 | final long identity = Binder.clearCallingIdentity(); |
| 8266 | try { |
| 8267 | CarrierConfigManager configManager = |
| 8268 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8269 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8270 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8271 | } finally { |
| 8272 | Binder.restoreCallingIdentity(identity); |
| 8273 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8274 | } |
| 8275 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8276 | @Override |
| 8277 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8278 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8279 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
| 8282 | @Override |
| 8283 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8284 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8285 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8289 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
| 8292 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8293 | } |
| 8294 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8295 | /** |
| 8296 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8297 | * support for the feature and device firmware support. |
| 8298 | * |
| 8299 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8300 | */ |
| 8301 | @Override |
| 8302 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8303 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8304 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8305 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8307 | final Phone phone = getPhone(subscriptionId); |
| 8308 | if (phone == null) { |
| 8309 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8310 | return false; |
| 8311 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8313 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8314 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8315 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8316 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8317 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8318 | return isCarrierSupported && isDeviceSupported; |
| 8319 | } finally { |
| 8320 | Binder.restoreCallingIdentity(identity); |
| 8321 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8322 | } |
| 8323 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8324 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8325 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8326 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8327 | * 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] | 8328 | */ |
| 8329 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8332 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8333 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8334 | return false; |
| 8335 | } |
| 8336 | } |
| 8337 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8338 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8339 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8340 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8341 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8342 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8343 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8347 | } |
| 8348 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8349 | @Deprecated |
| 8350 | @Override |
| 8351 | public String getDeviceId(String callingPackage) { |
| 8352 | return getDeviceIdWithFeature(callingPackage, null); |
| 8353 | } |
| 8354 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8355 | /** |
| 8356 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8357 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8358 | * |
| 8359 | * <p>Requires Permission: |
| 8360 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8361 | */ |
| 8362 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8363 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8364 | try { |
| 8365 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8366 | } catch (SecurityException se) { |
| 8367 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8368 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8369 | + Binder.getCallingUid()); |
| 8370 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8371 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8372 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8373 | return null; |
| 8374 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8375 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8376 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8377 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8378 | return null; |
| 8379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8380 | |
| 8381 | final long identity = Binder.clearCallingIdentity(); |
| 8382 | try { |
| 8383 | return phone.getDeviceId(); |
| 8384 | } finally { |
| 8385 | Binder.restoreCallingIdentity(identity); |
| 8386 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8387 | } |
| 8388 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8389 | /** |
| 8390 | * {@hide} |
| 8391 | * Returns the IMS Registration Status on a particular subid |
| 8392 | * |
| 8393 | * @param subId |
| 8394 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8395 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8396 | Phone phone = getPhone(subId); |
| 8397 | if (phone != null) { |
| 8398 | return phone.isImsRegistered(); |
| 8399 | } else { |
| 8400 | return false; |
| 8401 | } |
| 8402 | } |
| 8403 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8404 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8405 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8406 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8407 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8408 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8409 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8410 | } |
| 8411 | final long identity = Binder.clearCallingIdentity(); |
| 8412 | try { |
| 8413 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8414 | } finally { |
| 8415 | Binder.restoreCallingIdentity(identity); |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8420 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8421 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8422 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8423 | mApp, |
| 8424 | subscriptionId, |
| 8425 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8426 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8427 | |
| 8428 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8429 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8430 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8431 | final long identity = Binder.clearCallingIdentity(); |
| 8432 | try { |
| 8433 | Phone phone = getPhone(subscriptionId); |
| 8434 | if (phone == null) { |
| 8435 | return null; |
| 8436 | } |
| 8437 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
| 8440 | } |
| 8441 | } |
| 8442 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8443 | /** |
| 8444 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8445 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8446 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | final long identity = Binder.clearCallingIdentity(); |
| 8448 | try { |
| 8449 | Phone phone = getPhone(subId); |
| 8450 | if (phone != null) { |
| 8451 | return phone.isWifiCallingEnabled(); |
| 8452 | } else { |
| 8453 | return false; |
| 8454 | } |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8457 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8458 | } |
| 8459 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8460 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8461 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8462 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8463 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8464 | final long identity = Binder.clearCallingIdentity(); |
| 8465 | try { |
| 8466 | Phone phone = getPhone(subId); |
| 8467 | if (phone != null) { |
| 8468 | return phone.isVideoEnabled(); |
| 8469 | } else { |
| 8470 | return false; |
| 8471 | } |
| 8472 | } finally { |
| 8473 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8474 | } |
| 8475 | } |
| 8476 | |
| 8477 | /** |
| 8478 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8479 | * defined in {@link ImsRegistrationImplBase}. |
| 8480 | */ |
| 8481 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8482 | final long identity = Binder.clearCallingIdentity(); |
| 8483 | try { |
| 8484 | Phone phone = getPhone(subId); |
| 8485 | if (phone != null) { |
| 8486 | return phone.getImsRegistrationTech(); |
| 8487 | } else { |
| 8488 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8489 | } |
| 8490 | } finally { |
| 8491 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8492 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8493 | } |
| 8494 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8495 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8496 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8497 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8498 | |
| 8499 | enforceTelephonyFeatureWithException(callingPackage, |
| 8500 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8501 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8502 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8503 | return; |
| 8504 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8505 | Phone defaultPhone = getDefaultPhone(); |
| 8506 | if (defaultPhone != null) { |
| 8507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8508 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8509 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8510 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8511 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8512 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8513 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8514 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8515 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8516 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8517 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8518 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8519 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8520 | setDataRoamingEnabled(subId, phone == null ? false |
| 8521 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8522 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8523 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8524 | // There has been issues when Sms raw table somehow stores orphan |
| 8525 | // fragments. They lead to garbled message when new fragments come |
| 8526 | // in and combined with those stale ones. In case this happens again, |
| 8527 | // user can reset all network settings which will clean up this table. |
| 8528 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8529 | // Clean up IMS settings as well here. |
| 8530 | int slotId = getSlotIndex(subId); |
| 8531 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8532 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8533 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8534 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8535 | if (defaultPhone == null) { |
| 8536 | return; |
| 8537 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8538 | // Erase modem config if erase modem on network setting is enabled. |
| 8539 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8540 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8541 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8542 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8543 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8544 | |
| 8545 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8548 | } |
| 8549 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8550 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8551 | @VisibleForTesting |
| 8552 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8553 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8554 | return; |
| 8555 | } |
| 8556 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8557 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8558 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8559 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8560 | "user=" + defaultNetworkType); |
| 8561 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8562 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8563 | defaultNetworkType, null); |
| 8564 | } |
| 8565 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8566 | private void cleanUpSmsRawTable(Context context) { |
| 8567 | ContentResolver resolver = context.getContentResolver(); |
| 8568 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8569 | resolver.delete(uri, null, null); |
| 8570 | } |
| 8571 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8572 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8573 | public String getSimLocaleForSubscriber(int subId) { |
| 8574 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8575 | |
| 8576 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8577 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8578 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8579 | final Phone phone = getPhone(subId); |
| 8580 | if (phone == null) { |
| 8581 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8582 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8583 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8584 | final long identity = Binder.clearCallingIdentity(); |
| 8585 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8586 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8587 | phone.getContext().getOpPackageName(), |
| 8588 | phone.getContext().getAttributionTag()); |
| 8589 | if (info == null) { |
| 8590 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8591 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8593 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8594 | // preferences (EF-PL and EF-LI)... |
| 8595 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8596 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8597 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8598 | if (localeFromDefaultSim != null) { |
| 8599 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8600 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8601 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8602 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8603 | } else { |
| 8604 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8605 | } |
| 8606 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8608 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8609 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8610 | // the SIM and carrier preferences does not include a country we add the country |
| 8611 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8612 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8613 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8614 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8615 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | if (DBG) log("No locale found - returning null"); |
| 8619 | return null; |
| 8620 | } finally { |
| 8621 | Binder.restoreCallingIdentity(identity); |
| 8622 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8623 | } |
| 8624 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8625 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8626 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8627 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8628 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8629 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8630 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8631 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8632 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8633 | return localeTag; |
| 8634 | } |
| 8635 | } |
| 8636 | return inputLocale.toLanguageTag(); |
| 8637 | } |
| 8638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8639 | /** |
| 8640 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8641 | */ |
| 8642 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8643 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8644 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8645 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8646 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8647 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8648 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8649 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8650 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8651 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8652 | * representing the state of the modem. |
| 8653 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8654 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8655 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8656 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8657 | */ |
| 8658 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8659 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8660 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8661 | |
| 8662 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8663 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8664 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8665 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8666 | |
| 8667 | final long identity = Binder.clearCallingIdentity(); |
| 8668 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8669 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8670 | } finally { |
| 8671 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8672 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8673 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8674 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8675 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8676 | // less than total activity duration. |
| 8677 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8678 | if (info == null) { |
| 8679 | return false; |
| 8680 | } |
| 8681 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8682 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8683 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8684 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8685 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8686 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8687 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8688 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8689 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8690 | } |
| 8691 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8692 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8693 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8694 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8695 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8696 | |
| 8697 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8698 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8699 | } |
| 8700 | |
| 8701 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8702 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8703 | rat, |
| 8704 | freq, |
| 8705 | info.getReceiveTimeMillis(rat, freq) |
| 8706 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8707 | } |
| 8708 | |
| 8709 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8710 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8711 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8712 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8713 | |
| 8714 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8715 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8716 | } |
| 8717 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8718 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8719 | rat, |
| 8720 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8721 | } |
| 8722 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8723 | /** |
| 8724 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8725 | * @param info recent ModemActivityInfo |
| 8726 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8727 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8728 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8729 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8730 | boolean matched; |
| 8731 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8732 | matched = false; |
| 8733 | int rat = info.getSpecificInfoRat(i); |
| 8734 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8735 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8736 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8737 | //if it already exists |
| 8738 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8739 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8740 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8741 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8742 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8743 | updateLastModemActivityInfo(info, rat, freq); |
| 8744 | matched = true; |
| 8745 | } |
| 8746 | } else { |
| 8747 | updateLastModemActivityInfo(info, rat); |
| 8748 | matched = true; |
| 8749 | } |
| 8750 | } |
| 8751 | } |
| 8752 | |
| 8753 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8754 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8755 | new ActivityStatsTechSpecificInfo( |
| 8756 | rat, |
| 8757 | freq, |
| 8758 | info.getTransmitTimeMillis(rat, freq), |
| 8759 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8760 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8761 | } |
| 8762 | } |
| 8763 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8764 | mLastModemActivitySpecificInfo = |
| 8765 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8766 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8767 | |
| 8768 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8769 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8770 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8771 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8772 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8773 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8774 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8775 | |
| 8776 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8777 | new ModemActivityInfo( |
| 8778 | mLastModemActivityInfo.getTimestampMillis(), |
| 8779 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8780 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8781 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8785 | ActivityStatsTechSpecificInfo[] info) { |
| 8786 | int infoSize = info.length; |
| 8787 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8788 | for (int i = 0; i < infoSize; i++) { |
| 8789 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8790 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8791 | info[i].getTransmitTimeMillis(), |
| 8792 | (int) info[i].getReceiveTimeMillis()); |
| 8793 | } |
| 8794 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8795 | } |
| 8796 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8797 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8798 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8799 | */ |
| 8800 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8801 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8802 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8803 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8804 | if (phone == null) { |
| 8805 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8806 | return null; |
| 8807 | } |
| 8808 | |
| 8809 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8811 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8812 | return null; |
| 8813 | } |
| 8814 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8815 | enforceTelephonyFeatureWithException(callingPackage, |
| 8816 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8817 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8818 | boolean hasFinePermission = false; |
| 8819 | boolean hasCoarsePermission = false; |
| 8820 | if (!renounceFineLocationAccess) { |
| 8821 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8822 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8823 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8824 | .setCallingPackage(callingPackage) |
| 8825 | .setCallingFeatureId(callingFeatureId) |
| 8826 | .setCallingPid(Binder.getCallingPid()) |
| 8827 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8828 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8829 | .setLogAsInfo(true) |
| 8830 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8831 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8832 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8833 | .build()); |
| 8834 | hasFinePermission = |
| 8835 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8836 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8837 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8838 | if (!renounceCoarseLocationAccess) { |
| 8839 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8840 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8841 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8842 | .setCallingPackage(callingPackage) |
| 8843 | .setCallingFeatureId(callingFeatureId) |
| 8844 | .setCallingPid(Binder.getCallingPid()) |
| 8845 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8846 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8847 | .setLogAsInfo(true) |
| 8848 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8849 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8850 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8851 | .build()); |
| 8852 | hasCoarsePermission = |
| 8853 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8854 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8855 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8856 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8857 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8858 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8859 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8860 | if (subInfo != null && !subInfo.isActive()) { |
| 8861 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8862 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8863 | } |
| 8864 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8865 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8866 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8867 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8868 | |
| 8869 | // Scrub out the location info in ServiceState depending on what level of access |
| 8870 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8871 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8872 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8873 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8874 | } finally { |
| 8875 | Binder.restoreCallingIdentity(identity); |
| 8876 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8877 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8878 | |
| 8879 | /** |
| 8880 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8881 | * |
| 8882 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8883 | * voicemail ringtone. |
| 8884 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8885 | * PhoneAccount. |
| 8886 | */ |
| 8887 | @Override |
| 8888 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8889 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8890 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8892 | final long identity = Binder.clearCallingIdentity(); |
| 8893 | try { |
| 8894 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8895 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8896 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8897 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8898 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8900 | } finally { |
| 8901 | Binder.restoreCallingIdentity(identity); |
| 8902 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8903 | } |
| 8904 | |
| 8905 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8906 | * Sets the per-account voicemail ringtone. |
| 8907 | * |
| 8908 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8909 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8910 | * |
| 8911 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8912 | * voicemail ringtone. |
| 8913 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8914 | * PhoneAccount. |
| 8915 | */ |
| 8916 | @Override |
| 8917 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8918 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8919 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8921 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8922 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8924 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8925 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8927 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8928 | enforceTelephonyFeatureWithException(callingPackage, |
| 8929 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8930 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8931 | final long identity = Binder.clearCallingIdentity(); |
| 8932 | try { |
| 8933 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8934 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8935 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8936 | } |
| 8937 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8938 | } finally { |
| 8939 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8940 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8944 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8945 | * |
| 8946 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8947 | * voicemail vibration setting. |
| 8948 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8949 | */ |
| 8950 | @Override |
| 8951 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8952 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8953 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8955 | final long identity = Binder.clearCallingIdentity(); |
| 8956 | try { |
| 8957 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8958 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8959 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8960 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8962 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8963 | } finally { |
| 8964 | Binder.restoreCallingIdentity(identity); |
| 8965 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8966 | } |
| 8967 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8968 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8969 | * Sets the per-account voicemail vibration. |
| 8970 | * |
| 8971 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8972 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8973 | * |
| 8974 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8975 | * voicemail vibration setting. |
| 8976 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8977 | * specific PhoneAccount. |
| 8978 | */ |
| 8979 | @Override |
| 8980 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8981 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8982 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8983 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8984 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8985 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8987 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8988 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8989 | } |
| 8990 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8991 | enforceTelephonyFeatureWithException(callingPackage, |
| 8992 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8994 | final long identity = Binder.clearCallingIdentity(); |
| 8995 | try { |
| 8996 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8997 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8998 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8999 | } |
| 9000 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9001 | } finally { |
| 9002 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9003 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9004 | } |
| 9005 | |
| 9006 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9007 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9008 | * |
| 9009 | * @throws SecurityException if the caller does not have the required permission |
| 9010 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9011 | @VisibleForTesting |
| 9012 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9013 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9014 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9018 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9019 | * permission. |
| 9020 | * |
| 9021 | * @throws SecurityException if the caller does not have the required permission |
| 9022 | */ |
| 9023 | private void enforceSendSmsPermission() { |
| 9024 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9025 | } |
| 9026 | |
| 9027 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9028 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9029 | * users permission. |
| 9030 | * |
| 9031 | * @throws SecurityException if the caller does not have the required permission |
| 9032 | */ |
| 9033 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9034 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9035 | } |
| 9036 | |
| 9037 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9038 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9039 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9040 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9041 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9042 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9043 | final long identity = Binder.clearCallingIdentity(); |
| 9044 | try { |
| 9045 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9046 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9047 | if (componentName == null) { |
| 9048 | throw new SecurityException( |
| 9049 | "Caller not current active visual voicemail package[null]"); |
| 9050 | } |
| 9051 | String vvmPackage = componentName.getPackageName(); |
| 9052 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9053 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9054 | } |
| 9055 | } finally { |
| 9056 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9057 | } |
| 9058 | } |
| 9059 | |
| 9060 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9061 | * Return the application ID for the app type. |
| 9062 | * |
| 9063 | * @param subId the subscription ID that this request applies to. |
| 9064 | * @param appType the uicc app type. |
| 9065 | * @return Application ID for specificied app type, or null if no uicc. |
| 9066 | */ |
| 9067 | @Override |
| 9068 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9069 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9070 | |
| 9071 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9072 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9073 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9074 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9075 | |
| 9076 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9077 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9078 | if (phone == null) { |
| 9079 | return null; |
| 9080 | } |
| 9081 | String aid = null; |
| 9082 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9083 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9084 | .getApplicationByType(appType).getAid(); |
| 9085 | } catch (Exception e) { |
| 9086 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9087 | } |
| 9088 | return aid; |
| 9089 | } finally { |
| 9090 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9091 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9092 | } |
| 9093 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9094 | /** |
| 9095 | * Return the Electronic Serial Number. |
| 9096 | * |
| 9097 | * @param subId the subscription ID that this request applies to. |
| 9098 | * @return ESN or null if error. |
| 9099 | */ |
| 9100 | @Override |
| 9101 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9102 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9103 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9104 | |
| 9105 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9106 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9107 | if (phone == null) { |
| 9108 | return null; |
| 9109 | } |
| 9110 | String esn = null; |
| 9111 | try { |
| 9112 | esn = phone.getEsn(); |
| 9113 | } catch (Exception e) { |
| 9114 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9115 | } |
| 9116 | return esn; |
| 9117 | } finally { |
| 9118 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9119 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9120 | } |
| 9121 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9122 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9123 | * Return the Preferred Roaming List Version. |
| 9124 | * |
| 9125 | * @param subId the subscription ID that this request applies to. |
| 9126 | * @return PRLVersion or null if error. |
| 9127 | */ |
| 9128 | @Override |
| 9129 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9130 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9131 | |
| 9132 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9133 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9134 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9135 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9136 | |
| 9137 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9138 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9139 | if (phone == null) { |
| 9140 | return null; |
| 9141 | } |
| 9142 | String cdmaPrlVersion = null; |
| 9143 | try { |
| 9144 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9145 | } catch (Exception e) { |
| 9146 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9147 | } |
| 9148 | return cdmaPrlVersion; |
| 9149 | } finally { |
| 9150 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9151 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9152 | } |
| 9153 | |
| 9154 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9155 | * Get snapshot of Telephony histograms |
| 9156 | * @return List of Telephony histograms |
| 9157 | * @hide |
| 9158 | */ |
| 9159 | @Override |
| 9160 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9162 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9163 | |
| 9164 | final long identity = Binder.clearCallingIdentity(); |
| 9165 | try { |
| 9166 | return RIL.getTelephonyRILTimingHistograms(); |
| 9167 | } finally { |
| 9168 | Binder.restoreCallingIdentity(identity); |
| 9169 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9170 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9171 | |
| 9172 | /** |
| 9173 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9174 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9175 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9176 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9177 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9178 | * @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] | 9179 | */ |
| 9180 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9181 | @TelephonyManager.SetCarrierRestrictionResult |
| 9182 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9183 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9184 | |
| 9185 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9186 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9187 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9188 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9189 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9190 | if (carrierRestrictionRules == null) { |
| 9191 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9192 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9194 | final long identity = Binder.clearCallingIdentity(); |
| 9195 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9196 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9197 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9198 | } finally { |
| 9199 | Binder.restoreCallingIdentity(identity); |
| 9200 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9201 | } |
| 9202 | |
| 9203 | /** |
| 9204 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9205 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9206 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9207 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9208 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9209 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9210 | */ |
| 9211 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9212 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9213 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9214 | |
| 9215 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9216 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9217 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9218 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9219 | |
| 9220 | final long identity = Binder.clearCallingIdentity(); |
| 9221 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9222 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9223 | if (response instanceof CarrierRestrictionRules) { |
| 9224 | return (CarrierRestrictionRules) response; |
| 9225 | } |
| 9226 | // Response is an Exception of some kind, |
| 9227 | // which is signalled to the user as a NULL retval |
| 9228 | return null; |
| 9229 | } catch (Exception e) { |
| 9230 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9231 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9232 | } finally { |
| 9233 | Binder.restoreCallingIdentity(identity); |
| 9234 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9235 | } |
| 9236 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9237 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9238 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9239 | * through the callback. |
| 9240 | * |
| 9241 | * @param callback The callback that will be used to send the result. |
| 9242 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9243 | * the caller is not allowlisted. |
| 9244 | */ |
| 9245 | @Override |
| 9246 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9247 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9248 | |
| 9249 | enforceTelephonyFeatureWithException(packageName, |
| 9250 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9251 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9252 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9253 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9254 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9255 | throw new SecurityException("Not an authorized caller"); |
| 9256 | } |
| 9257 | final long identity = Binder.clearCallingIdentity(); |
| 9258 | try { |
| 9259 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9260 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9261 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9262 | } finally { |
| 9263 | Binder.restoreCallingIdentity(identity); |
| 9264 | } |
| 9265 | } |
| 9266 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9267 | @Override |
| 9268 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9269 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9270 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9271 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9272 | } |
| 9273 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9274 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9275 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9276 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9277 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9278 | } |
| 9279 | |
| 9280 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9281 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9282 | * @param subId the subscription ID that this action applies to. |
| 9283 | * @param enabled control enable or disable radio. |
| 9284 | * {@hide} |
| 9285 | */ |
| 9286 | @Override |
| 9287 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9288 | enforceModifyPermission(); |
| 9289 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9290 | |
| 9291 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9292 | if (phone == null) { |
| 9293 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9294 | return; |
| 9295 | } |
| 9296 | try { |
| 9297 | phone.carrierActionSetRadioEnabled(enabled); |
| 9298 | } catch (Exception e) { |
| 9299 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9300 | } finally { |
| 9301 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9302 | } |
| 9303 | } |
| 9304 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9305 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9306 | * Enable or disable Voice over NR (VoNR) |
| 9307 | * @param subId the subscription ID that this action applies to. |
| 9308 | * @param enabled enable or disable VoNR. |
| 9309 | * @return operation result. |
| 9310 | */ |
| 9311 | @Override |
| 9312 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9313 | enforceModifyPermission(); |
| 9314 | final Phone phone = getPhone(subId); |
| 9315 | |
| 9316 | final long identity = Binder.clearCallingIdentity(); |
| 9317 | if (phone == null) { |
| 9318 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9319 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9320 | } |
| 9321 | |
| 9322 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9323 | try { |
| 9324 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9325 | workSource); |
| 9326 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9327 | |
| 9328 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9329 | if (DBG) { |
| 9330 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9331 | } |
| 9332 | SubscriptionManager.setSubscriptionProperty( |
| 9333 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9334 | (enabled ? "1" : "0")); |
| 9335 | } |
| 9336 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9337 | return result; |
| 9338 | } finally { |
| 9339 | Binder.restoreCallingIdentity(identity); |
| 9340 | } |
| 9341 | } |
| 9342 | |
| 9343 | /** |
| 9344 | * Is voice over NR enabled |
| 9345 | * @return true if VoNR is enabled else false |
| 9346 | */ |
| 9347 | @Override |
| 9348 | public boolean isVoNrEnabled(int subId) { |
| 9349 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9350 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9351 | final long identity = Binder.clearCallingIdentity(); |
| 9352 | try { |
| 9353 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9354 | null, subId, workSource); |
| 9355 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9356 | return isEnabled; |
| 9357 | } finally { |
| 9358 | Binder.restoreCallingIdentity(identity); |
| 9359 | } |
| 9360 | } |
| 9361 | |
| 9362 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9363 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9364 | * network status based on which carrier apps could apply actions accordingly, |
| 9365 | * enable/disable default url handler for example. |
| 9366 | * |
| 9367 | * @param subId the subscription ID that this action applies to. |
| 9368 | * @param report control start/stop reporting the default network status. |
| 9369 | * {@hide} |
| 9370 | */ |
| 9371 | @Override |
| 9372 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9373 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9374 | |
| 9375 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9376 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9377 | "carrierActionReportDefaultNetworkStatus"); |
| 9378 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9379 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9380 | |
| 9381 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9382 | if (phone == null) { |
| 9383 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9384 | return; |
| 9385 | } |
| 9386 | try { |
| 9387 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9388 | } catch (Exception e) { |
| 9389 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | } finally { |
| 9391 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9392 | } |
| 9393 | } |
| 9394 | |
| 9395 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9396 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9397 | * @param subId the subscription ID that this action applies to. |
| 9398 | * {@hide} |
| 9399 | */ |
| 9400 | @Override |
| 9401 | public void carrierActionResetAll(int subId) { |
| 9402 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9403 | |
| 9404 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9405 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9406 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9407 | final Phone phone = getPhone(subId); |
| 9408 | if (phone == null) { |
| 9409 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9410 | return; |
| 9411 | } |
| 9412 | try { |
| 9413 | phone.carrierActionResetAll(); |
| 9414 | } catch (Exception e) { |
| 9415 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9416 | } |
| 9417 | } |
| 9418 | |
| 9419 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9420 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9421 | * bug report is being generated. |
| 9422 | */ |
| 9423 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9424 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9425 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9426 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9427 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9428 | + Binder.getCallingPid() |
| 9429 | + ", uid=" + Binder.getCallingUid() |
| 9430 | + "without permission " |
| 9431 | + android.Manifest.permission.DUMP); |
| 9432 | return; |
| 9433 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9434 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9435 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9436 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9437 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9438 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9439 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9440 | @NonNull String[] args) { |
| 9441 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9442 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9443 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9444 | } |
| 9445 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9446 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9447 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9448 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9449 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9450 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9451 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9452 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9453 | */ |
| 9454 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9455 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9456 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9457 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9458 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9459 | try { |
| 9460 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9461 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9462 | } catch (SecurityException se) { |
| 9463 | enforceModifyPermission(); |
| 9464 | } |
| 9465 | } else { |
| 9466 | enforceModifyPermission(); |
| 9467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9468 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9469 | enforceTelephonyFeatureWithException(callingPackage, |
| 9470 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9471 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9472 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9473 | final long identity = Binder.clearCallingIdentity(); |
| 9474 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9475 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9476 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9477 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9478 | callingUid, callingPackage, null, null); |
| 9479 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9480 | Phone phone = getPhone(subId); |
| 9481 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9482 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9483 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9484 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9485 | phone.getDataSettingsManager().setDataEnabled( |
| 9486 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9488 | } |
| 9489 | } finally { |
| 9490 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9491 | } |
| 9492 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9493 | |
| 9494 | /** |
| 9495 | * Get Client request stats |
| 9496 | * @return List of Client Request Stats |
| 9497 | * @hide |
| 9498 | */ |
| 9499 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9500 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9501 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9503 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9504 | return null; |
| 9505 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9506 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9507 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9508 | final long identity = Binder.clearCallingIdentity(); |
| 9509 | try { |
| 9510 | if (phone != null) { |
| 9511 | return phone.getClientRequestStats(); |
| 9512 | } |
| 9513 | |
| 9514 | return null; |
| 9515 | } finally { |
| 9516 | Binder.restoreCallingIdentity(identity); |
| 9517 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9518 | } |
| 9519 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9520 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9521 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9522 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9523 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9524 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9525 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9526 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9527 | // commands that plumb through the RIL as root, like so: |
| 9528 | // $ adb root |
| 9529 | // $ adb shell cmd phone ... |
| 9530 | packageName = "root"; |
| 9531 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9532 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9533 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9534 | |
| 9535 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9536 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9537 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9538 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9539 | * @param state State of SIM (power down, power up, pass through) |
| 9540 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9541 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9542 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9543 | * |
| 9544 | **/ |
| 9545 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9546 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9547 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9548 | |
| 9549 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9550 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9551 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9552 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9553 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9554 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9556 | final long identity = Binder.clearCallingIdentity(); |
| 9557 | try { |
| 9558 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9559 | phone.setSimPowerState(state, null, workSource); |
| 9560 | } |
| 9561 | } finally { |
| 9562 | Binder.restoreCallingIdentity(identity); |
| 9563 | } |
| 9564 | } |
| 9565 | |
| 9566 | /** |
| 9567 | * Set SIM card power state. |
| 9568 | * |
| 9569 | * @param slotIndex SIM slot id. |
| 9570 | * @param state State of SIM (power down, power up, pass through) |
| 9571 | * @param callback callback to trigger after success or failure |
| 9572 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9573 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9574 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9575 | * |
| 9576 | **/ |
| 9577 | @Override |
| 9578 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9579 | IIntegerConsumer callback) { |
| 9580 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9581 | |
| 9582 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9583 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9584 | "setSimPowerStateForSlotWithCallback"); |
| 9585 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9586 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9587 | |
| 9588 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9589 | |
| 9590 | final long identity = Binder.clearCallingIdentity(); |
| 9591 | try { |
| 9592 | if (phone != null) { |
| 9593 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9594 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9595 | } |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9598 | } |
| 9599 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9600 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9601 | private boolean isUssdApiAllowed(int subId) { |
| 9602 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9603 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9604 | if (configManager == null) { |
| 9605 | return false; |
| 9606 | } |
| 9607 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9608 | if (pb == null) { |
| 9609 | return false; |
| 9610 | } |
| 9611 | return pb.getBoolean( |
| 9612 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9613 | } |
| 9614 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9615 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9616 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9617 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9618 | * @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] | 9619 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9620 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9621 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9622 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9623 | |
| 9624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9625 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9627 | final long identity = Binder.clearCallingIdentity(); |
| 9628 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9629 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9630 | } finally { |
| 9631 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9632 | } |
| 9633 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9634 | |
| 9635 | /** |
| 9636 | * Get the current signal strength information for the given subscription. |
| 9637 | * Because this information is not updated when the device is in a low power state |
| 9638 | * it should not be relied-upon to be current. |
| 9639 | * @param subId Subscription index |
| 9640 | * @return the most recent cached signal strength info from the modem |
| 9641 | */ |
| 9642 | @Override |
| 9643 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9644 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9645 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9647 | final long identity = Binder.clearCallingIdentity(); |
| 9648 | try { |
| 9649 | Phone p = getPhone(subId); |
| 9650 | if (p == null) { |
| 9651 | return null; |
| 9652 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9654 | return p.getSignalStrength(); |
| 9655 | } finally { |
| 9656 | Binder.restoreCallingIdentity(identity); |
| 9657 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9658 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9659 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9660 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9661 | * Get the current modem radio state for the given slot. |
| 9662 | * @param slotIndex slot index. |
| 9663 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9664 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9665 | * @return the current radio power state from the modem |
| 9666 | */ |
| 9667 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9668 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9669 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9670 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9671 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9672 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9673 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9674 | } |
| 9675 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9676 | enforceTelephonyFeatureWithException(callingPackage, |
| 9677 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9678 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9679 | final long identity = Binder.clearCallingIdentity(); |
| 9680 | try { |
| 9681 | return phone.getRadioPowerState(); |
| 9682 | } finally { |
| 9683 | Binder.restoreCallingIdentity(identity); |
| 9684 | } |
| 9685 | } |
| 9686 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9687 | } |
| 9688 | |
| 9689 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9690 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9691 | * |
| 9692 | * <p>Requires one of the following permissions: |
| 9693 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9694 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9695 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9696 | * privileges. |
| 9697 | * |
| 9698 | * @param subId subscription id |
| 9699 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9700 | * {@code false}. |
| 9701 | */ |
| 9702 | @Override |
| 9703 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9704 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9705 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9706 | try { |
| 9707 | mApp.enforceCallingOrSelfPermission( |
| 9708 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9709 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9710 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9711 | mApp.enforceCallingOrSelfPermission( |
| 9712 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9713 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9714 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9715 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9716 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9717 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9718 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9719 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9720 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9721 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9722 | boolean isEnabled = false; |
| 9723 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9724 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9725 | Phone phone = getPhone(subId); |
| 9726 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9727 | } finally { |
| 9728 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9729 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9730 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9731 | } |
| 9732 | |
| 9733 | |
| 9734 | /** |
| 9735 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9736 | * |
| 9737 | * <p> Requires permission: |
| 9738 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9739 | * privileges. |
| 9740 | * |
| 9741 | * @param subId subscription id |
| 9742 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9743 | */ |
| 9744 | @Override |
| 9745 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9747 | mApp, subId, "setDataRoamingEnabled"); |
| 9748 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9749 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9750 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9751 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9752 | final long identity = Binder.clearCallingIdentity(); |
| 9753 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9754 | Phone phone = getPhone(subId); |
| 9755 | if (phone != null) { |
| 9756 | phone.setDataRoamingEnabled(isEnabled); |
| 9757 | } |
| 9758 | } finally { |
| 9759 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9760 | } |
| 9761 | } |
| 9762 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9763 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9764 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9765 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9766 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9767 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9768 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9769 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9770 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9771 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9772 | boolean isAllowed = true; |
| 9773 | final long identity = Binder.clearCallingIdentity(); |
| 9774 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9775 | Phone phone = getPhone(subId); |
| 9776 | if (phone != null) { |
| 9777 | isAllowed = phone.isCspPlmnEnabled(); |
| 9778 | } |
| 9779 | } finally { |
| 9780 | Binder.restoreCallingIdentity(identity); |
| 9781 | } |
| 9782 | return isAllowed; |
| 9783 | } |
| 9784 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9785 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9786 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9787 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9788 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9789 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9790 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9791 | if (phone == null) { |
| 9792 | return false; |
| 9793 | } |
| 9794 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9795 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9796 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9797 | } |
| 9798 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9799 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9800 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9801 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9802 | mApp.getSystemService(AppOpsManager.class) |
| 9803 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9804 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9805 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9806 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9807 | try { |
| 9808 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9809 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9810 | } catch (SecurityException e) { |
| 9811 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9812 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9813 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9814 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9815 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9816 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9817 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9818 | |
| 9819 | enforceTelephonyFeatureWithException(callingPackage, |
| 9820 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9821 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9822 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9823 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9824 | Binder.getCallingUid())) { |
| 9825 | isIccIdAccessRestricted = true; |
| 9826 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9827 | final long identity = Binder.clearCallingIdentity(); |
| 9828 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9829 | UiccController uiccController = UiccController.getInstance(); |
| 9830 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9831 | if (hasReadPermission) { |
| 9832 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9833 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9834 | |
| 9835 | // Remove private info if the caller doesn't have access |
| 9836 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9837 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9838 | //setting the value after compatibility check |
| 9839 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9840 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9841 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9842 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9843 | if (card == null) { |
| 9844 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9845 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9846 | continue; |
| 9847 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9848 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9849 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9850 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9851 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9852 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9853 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9854 | for (UiccPortInfo portInfo : portInfos) { |
| 9855 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9856 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9857 | if (port == null) { |
| 9858 | // assume no access if port is null |
| 9859 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9860 | continue; |
| 9861 | } |
| 9862 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9863 | uiccPortInfos.add(portInfo); |
| 9864 | } else { |
| 9865 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9866 | } |
| 9867 | } |
| 9868 | filteredInfos.add(new UiccCardInfo( |
| 9869 | cardInfo.isEuicc(), |
| 9870 | cardInfo.getCardId(), |
| 9871 | null, |
| 9872 | cardInfo.getPhysicalSlotIndex(), |
| 9873 | cardInfo.isRemovable(), |
| 9874 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9875 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9876 | } |
| 9877 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | } |
| 9882 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9883 | /** |
| 9884 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9885 | * generally private and require carrier privileges to view. |
| 9886 | * |
| 9887 | * @hide |
| 9888 | */ |
| 9889 | @NonNull |
| 9890 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9891 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9892 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9893 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9894 | } |
| 9895 | return new UiccCardInfo( |
| 9896 | cardInfo.isEuicc(), |
| 9897 | cardInfo.getCardId(), |
| 9898 | null, |
| 9899 | cardInfo.getPhysicalSlotIndex(), |
| 9900 | cardInfo.isRemovable(), |
| 9901 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9902 | portinfo |
| 9903 | ); |
| 9904 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9905 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9906 | /** |
| 9907 | * @hide |
| 9908 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9909 | * These values are generally private and require carrier privileges to view. |
| 9910 | */ |
| 9911 | @NonNull |
| 9912 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9913 | return new UiccPortInfo( |
| 9914 | UiccPortInfo.ICCID_REDACTED, |
| 9915 | portInfo.getPortIndex(), |
| 9916 | portInfo.getLogicalSlotIndex(), |
| 9917 | portInfo.isActive() |
| 9918 | ); |
| 9919 | } |
| 9920 | @Override |
| 9921 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9922 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9923 | mApp.getSystemService(AppOpsManager.class) |
| 9924 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9925 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9926 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9927 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9928 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9929 | // we are reading iccId which is PII data. |
| 9930 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9931 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9932 | enforceTelephonyFeatureWithException(callingPackage, |
| 9933 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9934 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9935 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9936 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9937 | Binder.getCallingUid())) { |
| 9938 | isLogicalSlotAccessRestricted = true; |
| 9939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9940 | final long identity = Binder.clearCallingIdentity(); |
| 9941 | try { |
| 9942 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9943 | if (slots == null || slots.length == 0) { |
| 9944 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9945 | return null; |
| 9946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9947 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9948 | for (int i = 0; i < slots.length; i++) { |
| 9949 | UiccSlot slot = slots[i]; |
| 9950 | if (slot == null) { |
| 9951 | continue; |
| 9952 | } |
| 9953 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9954 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9955 | UiccCard card = slot.getUiccCard(); |
| 9956 | if (card != null) { |
| 9957 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9958 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9959 | cardId = slot.getEid(); |
| 9960 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9961 | // If cardId is null, use iccId of default port as cardId. |
| 9962 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9963 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9964 | } |
| 9965 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9966 | if (cardId != null) { |
| 9967 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9968 | // if cardId is an EID, it's all digits so this is fine |
| 9969 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9970 | } |
| 9971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9972 | int cardState = 0; |
| 9973 | switch (slot.getCardState()) { |
| 9974 | case CARDSTATE_ABSENT: |
| 9975 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9976 | break; |
| 9977 | case CARDSTATE_PRESENT: |
| 9978 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9979 | break; |
| 9980 | case CARDSTATE_ERROR: |
| 9981 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9982 | break; |
| 9983 | case CARDSTATE_RESTRICTED: |
| 9984 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9985 | break; |
| 9986 | default: |
| 9987 | break; |
| 9988 | |
| 9989 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9990 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9991 | int[] portIndexes = slot.getPortList(); |
| 9992 | for (int portIdx : portIndexes) { |
| 9993 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9994 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9995 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9996 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9998 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9999 | slot.isEuicc(), |
| 10000 | cardId, |
| 10001 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10002 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10003 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10004 | //setting the value after compatibility check |
| 10005 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10006 | } |
| 10007 | return infos; |
| 10008 | } finally { |
| 10009 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10010 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10011 | } |
| 10012 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10013 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10014 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10015 | boolean hasReadPermission) { |
| 10016 | String iccId = slot.getIccId(portIndex); |
| 10017 | if (hasReadPermission) { // if has read permission |
| 10018 | return iccId; |
| 10019 | } else { |
| 10020 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10021 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10022 | // if no read permission, checking carrier privilege access |
| 10023 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10024 | return iccId; |
| 10025 | } |
| 10026 | } |
| 10027 | } |
| 10028 | // No read permission or carrier privilege access. |
| 10029 | return UiccPortInfo.ICCID_REDACTED; |
| 10030 | } |
| 10031 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10032 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10033 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10034 | public boolean switchSlots(int[] physicalSlots) { |
| 10035 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10036 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10037 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10038 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10039 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10040 | final long identity = Binder.clearCallingIdentity(); |
| 10041 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10042 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10043 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10044 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10045 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10046 | physicalSlots[i], i)); |
| 10047 | } |
| 10048 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10049 | } finally { |
| 10050 | Binder.restoreCallingIdentity(identity); |
| 10051 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10052 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10053 | |
| 10054 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10055 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10056 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10057 | enforceModifyPermission(); |
| 10058 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10059 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10060 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10061 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10062 | final long identity = Binder.clearCallingIdentity(); |
| 10063 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10064 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10065 | } finally { |
| 10066 | Binder.restoreCallingIdentity(identity); |
| 10067 | } |
| 10068 | } |
| 10069 | |
| 10070 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10071 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10072 | enforceTelephonyFeatureWithException(callingPackage, |
| 10073 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10074 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10075 | final long identity = Binder.clearCallingIdentity(); |
| 10076 | try { |
| 10077 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10078 | } finally { |
| 10079 | Binder.restoreCallingIdentity(identity); |
| 10080 | } |
| 10081 | } |
| 10082 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10083 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10084 | * A test API to reload the UICC profile. |
| 10085 | * |
| 10086 | * <p>Requires that the calling app has permission |
| 10087 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10088 | * @hide |
| 10089 | */ |
| 10090 | @Override |
| 10091 | public void refreshUiccProfile(int subId) { |
| 10092 | enforceModifyPermission(); |
| 10093 | |
| 10094 | final long identity = Binder.clearCallingIdentity(); |
| 10095 | try { |
| 10096 | Phone phone = getPhone(subId); |
| 10097 | if (phone == null) { |
| 10098 | return; |
| 10099 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10100 | UiccPort uiccPort = phone.getUiccPort(); |
| 10101 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10102 | return; |
| 10103 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10104 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10105 | if (uiccProfile == null) { |
| 10106 | return; |
| 10107 | } |
| 10108 | uiccProfile.refresh(); |
| 10109 | } finally { |
| 10110 | Binder.restoreCallingIdentity(identity); |
| 10111 | } |
| 10112 | } |
| 10113 | |
| 10114 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10115 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10116 | */ |
| 10117 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10118 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10119 | } |
| 10120 | |
| 10121 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10122 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10123 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10124 | */ |
| 10125 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10126 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10127 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10128 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10129 | return list.get(phoneId); |
| 10130 | } |
| 10131 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10132 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10133 | |
| 10134 | @Override |
| 10135 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10136 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10137 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10138 | |
| 10139 | final long identity = Binder.clearCallingIdentity(); |
| 10140 | try { |
| 10141 | final Phone phone = getPhone(subId); |
| 10142 | if (phone == null) { |
| 10143 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10144 | return; |
| 10145 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10146 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10147 | if (cpt != null) { |
| 10148 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10149 | } |
| 10150 | // 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] | 10151 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10152 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10153 | if (carrierPrivilegeRules == null) { |
| 10154 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10155 | } else { |
| 10156 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10157 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10158 | } finally { |
| 10159 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10160 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10161 | } |
| 10162 | |
| 10163 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10164 | public void setCarrierServicePackageOverride( |
| 10165 | int subId, String carrierServicePackage, String callingPackage) { |
| 10166 | TelephonyPermissions.enforceShellOnly( |
| 10167 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10168 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10169 | final long identity = Binder.clearCallingIdentity(); |
| 10170 | try { |
| 10171 | final Phone phone = getPhone(subId); |
| 10172 | if (phone == null || phone.getSubId() != subId) { |
| 10173 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10174 | throw new IllegalArgumentException("No phone for subid"); |
| 10175 | } |
| 10176 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10177 | if (cpt == null) { |
| 10178 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10179 | throw new IllegalStateException("No CPT for phone"); |
| 10180 | } |
| 10181 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10182 | } finally { |
| 10183 | Binder.restoreCallingIdentity(identity); |
| 10184 | } |
| 10185 | } |
| 10186 | |
| 10187 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10188 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10189 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10190 | |
| 10191 | final long identity = Binder.clearCallingIdentity(); |
| 10192 | try { |
| 10193 | final Phone phone = getPhone(subId); |
| 10194 | if (phone == null) { |
| 10195 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10196 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10197 | } |
| 10198 | return phone.getCarrierIdListVersion(); |
| 10199 | } finally { |
| 10200 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10201 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10202 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10203 | |
| 10204 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10205 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10206 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10207 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10208 | mApp, subId, callingPackage, callingFeatureId, |
| 10209 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10210 | return -1; |
| 10211 | } |
| 10212 | |
| 10213 | final long identity = Binder.clearCallingIdentity(); |
| 10214 | try { |
| 10215 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10216 | } finally { |
| 10217 | Binder.restoreCallingIdentity(identity); |
| 10218 | } |
| 10219 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10220 | |
| 10221 | @Override |
| 10222 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10223 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10224 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10225 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10226 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10227 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10228 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10229 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10230 | final long identity = Binder.clearCallingIdentity(); |
| 10231 | try { |
| 10232 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10233 | } finally { |
| 10234 | Binder.restoreCallingIdentity(identity); |
| 10235 | } |
| 10236 | } |
| 10237 | |
| 10238 | @Override |
| 10239 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10241 | mApp, subId, "setCdmaRoamingMode"); |
| 10242 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10243 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10244 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10245 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10246 | final long identity = Binder.clearCallingIdentity(); |
| 10247 | try { |
| 10248 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10255 | public int getCdmaSubscriptionMode(int subId) { |
| 10256 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10257 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10258 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10259 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10260 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10261 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10262 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10263 | final long identity = Binder.clearCallingIdentity(); |
| 10264 | try { |
| 10265 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10266 | } finally { |
| 10267 | Binder.restoreCallingIdentity(identity); |
| 10268 | } |
| 10269 | } |
| 10270 | |
| 10271 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10272 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10274 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10275 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10276 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10277 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10278 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10279 | final long identity = Binder.clearCallingIdentity(); |
| 10280 | try { |
| 10281 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10282 | } finally { |
| 10283 | Binder.restoreCallingIdentity(identity); |
| 10284 | } |
| 10285 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10286 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10287 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10288 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10289 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10291 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10292 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10293 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10294 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10295 | |
| 10296 | enforceTelephonyFeatureWithException(callingPackage, |
| 10297 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10298 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10299 | final long identity = Binder.clearCallingIdentity(); |
| 10300 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10301 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10302 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10303 | if (phone.getEmergencyNumberTracker() != null |
| 10304 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10305 | emergencyNumberListInternal.put( |
| 10306 | phone.getSubId(), |
| 10307 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10308 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10309 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10310 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10311 | } finally { |
| 10312 | Binder.restoreCallingIdentity(identity); |
| 10313 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10314 | } |
| 10315 | |
| 10316 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10317 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10318 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10319 | if (!exactMatch) { |
| 10320 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10321 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10322 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10323 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10324 | |
| 10325 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10326 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10327 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10328 | final long identity = Binder.clearCallingIdentity(); |
| 10329 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10330 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10331 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10332 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10333 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10334 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10335 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10336 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10337 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10338 | } |
| 10339 | return false; |
| 10340 | } finally { |
| 10341 | Binder.restoreCallingIdentity(identity); |
| 10342 | } |
| 10343 | } |
| 10344 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10345 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10346 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10347 | */ |
| 10348 | @Override |
| 10349 | public void startEmergencyCallbackMode() { |
| 10350 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10351 | "startEmergencyCallbackMode"); |
| 10352 | enforceModifyPermission(); |
| 10353 | final long identity = Binder.clearCallingIdentity(); |
| 10354 | try { |
| 10355 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10356 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10357 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10358 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10359 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10360 | gsmCdmaPhone.obtainMessage( |
| 10361 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10362 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10363 | } |
| 10364 | } |
| 10365 | } finally { |
| 10366 | Binder.restoreCallingIdentity(identity); |
| 10367 | } |
| 10368 | } |
| 10369 | |
| 10370 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10371 | * Update emergency number list for test mode. |
| 10372 | */ |
| 10373 | @Override |
| 10374 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10375 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10376 | "updateEmergencyNumberListTestMode"); |
| 10377 | |
| 10378 | final long identity = Binder.clearCallingIdentity(); |
| 10379 | try { |
| 10380 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10381 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10382 | if (tracker != null) { |
| 10383 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10384 | } |
| 10385 | } |
| 10386 | } finally { |
| 10387 | Binder.restoreCallingIdentity(identity); |
| 10388 | } |
| 10389 | } |
| 10390 | |
| 10391 | /** |
| 10392 | * Get the full emergency number list for test mode. |
| 10393 | */ |
| 10394 | @Override |
| 10395 | public List<String> getEmergencyNumberListTestMode() { |
| 10396 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10397 | "getEmergencyNumberListTestMode"); |
| 10398 | |
| 10399 | final long identity = Binder.clearCallingIdentity(); |
| 10400 | try { |
| 10401 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10402 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10403 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10404 | if (tracker != null) { |
| 10405 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10406 | emergencyNumbers.add(num.getNumber()); |
| 10407 | } |
| 10408 | } |
| 10409 | } |
| 10410 | return new ArrayList<>(emergencyNumbers); |
| 10411 | } finally { |
| 10412 | Binder.restoreCallingIdentity(identity); |
| 10413 | } |
| 10414 | } |
| 10415 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10416 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10417 | public int getEmergencyNumberDbVersion(int subId) { |
| 10418 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10419 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10420 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10421 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10422 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10423 | final long identity = Binder.clearCallingIdentity(); |
| 10424 | try { |
| 10425 | final Phone phone = getPhone(subId); |
| 10426 | if (phone == null) { |
| 10427 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10428 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10429 | } |
| 10430 | return phone.getEmergencyNumberDbVersion(); |
| 10431 | } finally { |
| 10432 | Binder.restoreCallingIdentity(identity); |
| 10433 | } |
| 10434 | } |
| 10435 | |
| 10436 | @Override |
| 10437 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10438 | enforceModifyPermission(); |
| 10439 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10440 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10441 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10442 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10443 | final long identity = Binder.clearCallingIdentity(); |
| 10444 | try { |
| 10445 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10446 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10447 | if (tracker != null) { |
| 10448 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10449 | } |
| 10450 | } |
| 10451 | } finally { |
| 10452 | Binder.restoreCallingIdentity(identity); |
| 10453 | } |
| 10454 | } |
| 10455 | |
| 10456 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10457 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10458 | enforceActiveEmergencySessionPermission(); |
| 10459 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10460 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10461 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10462 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10463 | final long identity = Binder.clearCallingIdentity(); |
| 10464 | try { |
| 10465 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10466 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10467 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10468 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10469 | } |
| 10470 | } |
| 10471 | } finally { |
| 10472 | Binder.restoreCallingIdentity(identity); |
| 10473 | } |
| 10474 | } |
| 10475 | |
| 10476 | @Override |
| 10477 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10478 | enforceActiveEmergencySessionPermission(); |
| 10479 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10480 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10481 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10482 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10483 | final long identity = Binder.clearCallingIdentity(); |
| 10484 | try { |
| 10485 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10486 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10487 | if (tracker != null) { |
| 10488 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10489 | } |
| 10490 | } |
| 10491 | } finally { |
| 10492 | Binder.restoreCallingIdentity(identity); |
| 10493 | } |
| 10494 | } |
| 10495 | |
| 10496 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10497 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10498 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10499 | Phone phone = getPhone(subId); |
| 10500 | if (phone == null) { |
| 10501 | return null; |
| 10502 | } |
| 10503 | final long identity = Binder.clearCallingIdentity(); |
| 10504 | try { |
| 10505 | UiccProfile profile = UiccController.getInstance() |
| 10506 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10507 | if (profile != null) { |
| 10508 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10509 | } |
| 10510 | } finally { |
| 10511 | Binder.restoreCallingIdentity(identity); |
| 10512 | } |
| 10513 | return null; |
| 10514 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10515 | |
| 10516 | /** |
| 10517 | * Enable or disable a modem stack. |
| 10518 | */ |
| 10519 | @Override |
| 10520 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10521 | enforceModifyPermission(); |
| 10522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10524 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10525 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10526 | final long identity = Binder.clearCallingIdentity(); |
| 10527 | try { |
| 10528 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10529 | if (phone == null) { |
| 10530 | return false; |
| 10531 | } else { |
| 10532 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10533 | } |
| 10534 | } finally { |
| 10535 | Binder.restoreCallingIdentity(identity); |
| 10536 | } |
| 10537 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10538 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10539 | /** |
| 10540 | * Whether a modem stack is enabled or not. |
| 10541 | */ |
| 10542 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10543 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10544 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10545 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10546 | if (phone == null) return false; |
| 10547 | |
| 10548 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10549 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10550 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10551 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10552 | } |
| 10553 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10554 | enforceTelephonyFeatureWithException(callingPackage, |
| 10555 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10556 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10557 | final long identity = Binder.clearCallingIdentity(); |
| 10558 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10559 | try { |
| 10560 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10561 | } catch (NoSuchElementException ex) { |
| 10562 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10563 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10564 | } finally { |
| 10565 | Binder.restoreCallingIdentity(identity); |
| 10566 | } |
| 10567 | } |
| 10568 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10569 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10570 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10571 | enforceModifyPermission(); |
| 10572 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10573 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10574 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10575 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10576 | final long identity = Binder.clearCallingIdentity(); |
| 10577 | try { |
| 10578 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10579 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10580 | .commit(); |
| 10581 | } finally { |
| 10582 | Binder.restoreCallingIdentity(identity); |
| 10583 | } |
| 10584 | } |
| 10585 | |
| 10586 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10587 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10588 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10590 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10591 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10592 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10593 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10594 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10595 | enforceTelephonyFeatureWithException(callingPackage, |
| 10596 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10597 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10598 | final long identity = Binder.clearCallingIdentity(); |
| 10599 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10600 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10601 | } finally { |
| 10602 | Binder.restoreCallingIdentity(identity); |
| 10603 | } |
| 10604 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10605 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10606 | @TelephonyManager.IsMultiSimSupportedResult |
| 10607 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10608 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10609 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10610 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10611 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10612 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10613 | } |
| 10614 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10615 | // supported by the modem, indicate that it is restricted. |
| 10616 | PhoneCapability staticCapability = |
| 10617 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10618 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10619 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10620 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10621 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10622 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10623 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10624 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10625 | } |
| 10626 | // Check if support of multiple SIMs is restricted by carrier |
| 10627 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10628 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10629 | } |
| 10630 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10631 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10632 | } |
| 10633 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10634 | /** |
| 10635 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10636 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10637 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10638 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10639 | * @param numOfSims number of active sims we want to switch to |
| 10640 | */ |
| 10641 | @Override |
| 10642 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10643 | if (numOfSims == 1) { |
| 10644 | enforceModifyPermission(); |
| 10645 | } else { |
| 10646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10647 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10648 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10649 | |
| 10650 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10651 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10652 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10653 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10654 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10655 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10656 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10657 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10658 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10659 | return; |
| 10660 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10661 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10662 | } finally { |
| 10663 | Binder.restoreCallingIdentity(identity); |
| 10664 | } |
| 10665 | } |
| 10666 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10667 | @Override |
| 10668 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10669 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10670 | |
| 10671 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10672 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10673 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10674 | Phone phone = getPhone(subId); |
| 10675 | if (phone == null) { |
| 10676 | return false; |
| 10677 | } |
| 10678 | final long identity = Binder.clearCallingIdentity(); |
| 10679 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10680 | UiccPort uiccPort = phone.getUiccPort(); |
| 10681 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10682 | return false; |
| 10683 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10684 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10685 | if (uiccProfile == null) { |
| 10686 | return false; |
| 10687 | } |
| 10688 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10689 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10690 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10691 | } |
| 10692 | return false; |
| 10693 | } finally { |
| 10694 | Binder.restoreCallingIdentity(identity); |
| 10695 | } |
| 10696 | } |
| 10697 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10698 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10699 | * Get whether making changes to modem configurations will trigger reboot. |
| 10700 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10701 | */ |
| 10702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10703 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10704 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10706 | mApp, subId, callingPackage, callingFeatureId, |
| 10707 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10708 | return false; |
| 10709 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10710 | |
| 10711 | enforceTelephonyFeatureWithException(callingPackage, |
| 10712 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10713 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10714 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10715 | final long identity = Binder.clearCallingIdentity(); |
| 10716 | try { |
| 10717 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10718 | } finally { |
| 10719 | Binder.restoreCallingIdentity(identity); |
| 10720 | } |
| 10721 | } |
| 10722 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10723 | private void updateModemStateMetrics() { |
| 10724 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10725 | // TODO: check the state for each modem if the api is ready. |
| 10726 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10727 | } |
| 10728 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10729 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10730 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10731 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10732 | // Verify that the callingPackage belongs to the calling UID |
| 10733 | mApp.getSystemService(AppOpsManager.class) |
| 10734 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10735 | |
| 10736 | enforceTelephonyFeatureWithException(callingPackage, |
| 10737 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10738 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10739 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10740 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10741 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10742 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10743 | if (slotInfos != null) { |
| 10744 | for (int i = 0; i < slotInfos.length; i++) { |
| 10745 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10746 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10747 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10748 | portInfo.getLogicalSlotIndex())); |
| 10749 | } |
| 10750 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10751 | } |
| 10752 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10753 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10754 | } finally { |
| 10755 | Binder.restoreCallingIdentity(identity); |
| 10756 | } |
| 10757 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10758 | |
| 10759 | /** |
| 10760 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10761 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10762 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10763 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10764 | @Override |
| 10765 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10766 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10767 | } |
| 10768 | |
| 10769 | /** |
| 10770 | * Get the HAL Version of a specific service |
| 10771 | */ |
| 10772 | @Override |
| 10773 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10774 | Phone phone = getDefaultPhone(); |
| 10775 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10776 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10777 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10778 | return hv.major * 100 + hv.minor; |
| 10779 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10780 | |
| 10781 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10782 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10783 | * |
| 10784 | * @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] | 10785 | */ |
| 10786 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10787 | public @Nullable String getCurrentPackageName() { |
| 10788 | PackageManager pm = mApp.getPackageManager(); |
| 10789 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10790 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10791 | } |
| 10792 | |
| 10793 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10794 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10795 | * corresponding network requests on a subId. |
| 10796 | * |
| 10797 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10798 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10799 | * 2) APN is un-metered for this subscription, or |
| 10800 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10801 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10802 | * |
| 10803 | * @return whether data is allowed for a apn type. |
| 10804 | * |
| 10805 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10806 | */ |
| 10807 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10808 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10809 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10810 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10811 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10812 | enforceTelephonyFeatureWithException(callingPackage, |
| 10813 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10814 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10815 | // Now that all security checks passes, perform the operation as ourselves. |
| 10816 | final long identity = Binder.clearCallingIdentity(); |
| 10817 | try { |
| 10818 | Phone phone = getPhone(subId); |
| 10819 | if (phone == null) return false; |
| 10820 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10821 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10822 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10823 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10824 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10825 | phone.getServiceState().getDataRoaming()); |
| 10826 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10827 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10828 | } finally { |
| 10829 | Binder.restoreCallingIdentity(identity); |
| 10830 | } |
| 10831 | } |
| 10832 | |
| 10833 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10834 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10835 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10836 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10837 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10838 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10839 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10840 | // Now that all security checks passes, perform the operation as ourselves. |
| 10841 | final long identity = Binder.clearCallingIdentity(); |
| 10842 | try { |
| 10843 | Phone phone = getPhone(subId); |
| 10844 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10845 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10846 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10847 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10848 | } finally { |
| 10849 | Binder.restoreCallingIdentity(identity); |
| 10850 | } |
| 10851 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10852 | |
| 10853 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10854 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10855 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10856 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10857 | |
| 10858 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10859 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10860 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10861 | long token = Binder.clearCallingIdentity(); |
| 10862 | try { |
| 10863 | Phone phone = getPhone(subscriptionId); |
| 10864 | if (phone == null) { |
| 10865 | try { |
| 10866 | if (resultCallback != null) { |
| 10867 | resultCallback.accept(false); |
| 10868 | } |
| 10869 | } catch (RemoteException e) { |
| 10870 | // ignore |
| 10871 | } |
| 10872 | return; |
| 10873 | } |
| 10874 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10875 | Pair.create(specifiers, (x) -> { |
| 10876 | try { |
| 10877 | if (resultCallback != null) { |
| 10878 | resultCallback.accept(x); |
| 10879 | } |
| 10880 | } catch (RemoteException e) { |
| 10881 | // ignore |
| 10882 | } |
| 10883 | }); |
| 10884 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10885 | } finally { |
| 10886 | Binder.restoreCallingIdentity(token); |
| 10887 | } |
| 10888 | } |
| 10889 | |
| 10890 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10891 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10892 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10893 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10894 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10895 | |
| 10896 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10897 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10898 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10899 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10900 | final long identity = Binder.clearCallingIdentity(); |
| 10901 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10902 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10903 | if (result instanceof IllegalStateException) { |
| 10904 | throw (IllegalStateException) result; |
| 10905 | } |
| 10906 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10907 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10908 | return specifiers; |
| 10909 | } finally { |
| 10910 | Binder.restoreCallingIdentity(identity); |
| 10911 | } |
| 10912 | } |
| 10913 | |
| 10914 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10915 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10916 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10917 | |
| 10918 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10919 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10920 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10921 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10922 | } |
| 10923 | |
| 10924 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10925 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10926 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10927 | if (callingPackage == null) { |
| 10928 | callingPackage = getCurrentPackageName(); |
| 10929 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10930 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10931 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10932 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10933 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10934 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10935 | } |
| 10936 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10937 | Intent intent = new Intent(); |
| 10938 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10939 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10940 | // Bring up choose default SMS subscription dialog right now |
| 10941 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10942 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10943 | mApp.startActivity(intent); |
| 10944 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10945 | |
| 10946 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10947 | public void showSwitchToManagedProfileDialog() { |
| 10948 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10949 | try { |
| 10950 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10951 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10952 | // for work telephony. |
| 10953 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10954 | intent.setData(Uri.parse("smsto:")); |
| 10955 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10956 | mApp.startActivity(intent); |
| 10957 | } catch (ActivityNotFoundException e) { |
| 10958 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10959 | Intent intent = new Intent(); |
| 10960 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10961 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10962 | mApp.startActivity(intent); |
| 10963 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10964 | } |
| 10965 | |
| 10966 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10967 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10968 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10969 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10970 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10971 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10972 | final long identity = Binder.clearCallingIdentity(); |
| 10973 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10974 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10975 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10976 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10977 | return carrierUAProfUrl; |
| 10978 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10979 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10980 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10981 | } finally { |
| 10982 | Binder.restoreCallingIdentity(identity); |
| 10983 | } |
| 10984 | } |
| 10985 | |
| 10986 | @Override |
| 10987 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10988 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10989 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10990 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10991 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10992 | final long identity = Binder.clearCallingIdentity(); |
| 10993 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10994 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10995 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10996 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10997 | return carrierUserAgent; |
| 10998 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10999 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11000 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11001 | } finally { |
| 11002 | Binder.restoreCallingIdentity(identity); |
| 11003 | } |
| 11004 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11005 | |
| 11006 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11007 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11008 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11009 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11010 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11011 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11012 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11013 | final long identity = Binder.clearCallingIdentity(); |
| 11014 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11015 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11016 | if (phone == null) return false; |
| 11017 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11018 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11019 | } finally { |
| 11020 | Binder.restoreCallingIdentity(identity); |
| 11021 | } |
| 11022 | } |
| 11023 | |
| 11024 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11025 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11026 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11027 | enforceModifyPermission(); |
| 11028 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11029 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11030 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11031 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11032 | final long identity = Binder.clearCallingIdentity(); |
| 11033 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11034 | Phone phone = getPhone(subscriptionId); |
| 11035 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11036 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11037 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11038 | } finally { |
| 11039 | Binder.restoreCallingIdentity(identity); |
| 11040 | } |
| 11041 | } |
| 11042 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11043 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11044 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11045 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11046 | * otherwise. |
| 11047 | */ |
| 11048 | @Override |
| 11049 | public void setCepEnabled(boolean isCepEnabled) { |
| 11050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11051 | |
| 11052 | final long identity = Binder.clearCallingIdentity(); |
| 11053 | try { |
| 11054 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11055 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11056 | Phone defaultPhone = phone.getImsPhone(); |
| 11057 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11058 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11059 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11060 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11061 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11062 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11063 | + imsPhone.getMsisdn()); |
| 11064 | } |
| 11065 | } |
| 11066 | } finally { |
| 11067 | Binder.restoreCallingIdentity(identity); |
| 11068 | } |
| 11069 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11070 | |
| 11071 | /** |
| 11072 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11073 | * |
| 11074 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11075 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11076 | * before being read. |
| 11077 | */ |
| 11078 | @Override |
| 11079 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11080 | isCompressed) { |
| 11081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11082 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11083 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11084 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11085 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11086 | |
| 11087 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11088 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11089 | Binder.getCallingUserHandle())) { |
| 11090 | if (!isImsAvailableOnDevice()) { |
| 11091 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11092 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11093 | throw new IllegalStateException("IMS not available on device."); |
| 11094 | } |
| 11095 | } else { |
| 11096 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11097 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11098 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11099 | } |
| 11100 | |
| 11101 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11102 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11103 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11106 | } |
| 11107 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11108 | |
| 11109 | @Override |
| 11110 | public boolean isIccLockEnabled(int subId) { |
| 11111 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11112 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11114 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11115 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11116 | // Now that all security checks passes, perform the operation as ourselves. |
| 11117 | final long identity = Binder.clearCallingIdentity(); |
| 11118 | try { |
| 11119 | Phone phone = getPhone(subId); |
| 11120 | if (phone != null && phone.getIccCard() != null) { |
| 11121 | return phone.getIccCard().getIccLockEnabled(); |
| 11122 | } else { |
| 11123 | return false; |
| 11124 | } |
| 11125 | } finally { |
| 11126 | Binder.restoreCallingIdentity(identity); |
| 11127 | } |
| 11128 | } |
| 11129 | |
| 11130 | /** |
| 11131 | * Set the ICC pin lock enabled or disabled. |
| 11132 | * |
| 11133 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11134 | * three cases: |
| 11135 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11136 | * successfully. |
| 11137 | * - Positive number and zero for remaining password attempts. |
| 11138 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11139 | * |
| 11140 | */ |
| 11141 | @Override |
| 11142 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11143 | enforceModifyPermission(); |
| 11144 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11145 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11146 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11147 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11148 | Phone phone = getPhone(subId); |
| 11149 | if (phone == null) { |
| 11150 | return 0; |
| 11151 | } |
| 11152 | // Now that all security checks passes, perform the operation as ourselves. |
| 11153 | final long identity = Binder.clearCallingIdentity(); |
| 11154 | try { |
| 11155 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11156 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11157 | return attemptsRemaining; |
| 11158 | |
| 11159 | } catch (Exception e) { |
| 11160 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11161 | } finally { |
| 11162 | Binder.restoreCallingIdentity(identity); |
| 11163 | } |
| 11164 | return 0; |
| 11165 | } |
| 11166 | |
| 11167 | /** |
| 11168 | * Change the ICC password used in ICC pin lock. |
| 11169 | * |
| 11170 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11171 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11172 | * - Positive number and zero for remaining password attempts. |
| 11173 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11174 | * |
| 11175 | */ |
| 11176 | @Override |
| 11177 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11178 | enforceModifyPermission(); |
| 11179 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11180 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11181 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11182 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11183 | Phone phone = getPhone(subId); |
| 11184 | if (phone == null) { |
| 11185 | return 0; |
| 11186 | } |
| 11187 | // Now that all security checks passes, perform the operation as ourselves. |
| 11188 | final long identity = Binder.clearCallingIdentity(); |
| 11189 | try { |
| 11190 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11191 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11192 | return attemptsRemaining; |
| 11193 | |
| 11194 | } catch (Exception e) { |
| 11195 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11196 | } finally { |
| 11197 | Binder.restoreCallingIdentity(identity); |
| 11198 | } |
| 11199 | return 0; |
| 11200 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11201 | |
| 11202 | /** |
| 11203 | * Request for receiving user activity notification |
| 11204 | */ |
| 11205 | @Override |
| 11206 | public void requestUserActivityNotification() { |
| 11207 | if (!mNotifyUserActivity.get() |
| 11208 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11209 | mNotifyUserActivity.set(true); |
| 11210 | } |
| 11211 | } |
| 11212 | |
| 11213 | /** |
| 11214 | * Called when userActivity is signalled in the power manager. |
| 11215 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11216 | */ |
| 11217 | @Override |
| 11218 | public void userActivity() { |
| 11219 | // *************************************** |
| 11220 | // * Inherited from PhoneWindowManager * |
| 11221 | // *************************************** |
| 11222 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11223 | // WITH ITS LOCKS HELD. |
| 11224 | // |
| 11225 | // This code must be VERY careful about the locks |
| 11226 | // it acquires. |
| 11227 | // In fact, the current code acquires way too many, |
| 11228 | // and probably has lurking deadlocks. |
| 11229 | |
| 11230 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11231 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11232 | } |
| 11233 | |
| 11234 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11235 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11236 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11237 | } |
| 11238 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11239 | |
| 11240 | @Override |
| 11241 | public boolean canConnectTo5GInDsdsMode() { |
| 11242 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11243 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11244 | |
| 11245 | @Override |
| 11246 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11247 | String callingFeatureId) { |
| 11248 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11249 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11250 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11251 | } |
| 11252 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11253 | enforceTelephonyFeatureWithException(callingPackage, |
| 11254 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11255 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11256 | Phone phone = getPhone(subId); |
| 11257 | if (phone == null) { |
| 11258 | throw new RuntimeException("phone is not available"); |
| 11259 | } |
| 11260 | // Now that all security checks passes, perform the operation as ourselves. |
| 11261 | final long identity = Binder.clearCallingIdentity(); |
| 11262 | try { |
| 11263 | return phone.getEquivalentHomePlmns(); |
| 11264 | } finally { |
| 11265 | Binder.restoreCallingIdentity(identity); |
| 11266 | } |
| 11267 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11268 | |
| 11269 | @Override |
| 11270 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11271 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11272 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11273 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11274 | "isRadioInterfaceCapabilitySupported"); |
| 11275 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11276 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11277 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11278 | if (radioInterfaceCapabilities == null) { |
| 11279 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11280 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11281 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11282 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11283 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11284 | @Override |
| 11285 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11286 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11287 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11288 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11289 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11290 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11291 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11292 | |
| 11293 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11294 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11295 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11296 | if (DBG) { |
| 11297 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11298 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11299 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11300 | } |
| 11301 | |
| 11302 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11303 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11304 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11305 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11306 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11307 | if (callback != null) { |
| 11308 | try { |
| 11309 | callback.onAuthenticationFailure( |
| 11310 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11311 | } catch (RemoteException exception) { |
| 11312 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11313 | } |
| 11314 | return; |
| 11315 | } |
| 11316 | } |
| 11317 | |
| 11318 | final long token = Binder.clearCallingIdentity(); |
| 11319 | try { |
| 11320 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11321 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11322 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11323 | } finally { |
| 11324 | Binder.restoreCallingIdentity(token); |
| 11325 | } |
| 11326 | } |
| 11327 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11328 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11329 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11330 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11331 | * requested radio power state will actually be set. See {@link |
| 11332 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11333 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11334 | * @param enable {@code true} if trying to turn radio on. |
| 11335 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11336 | * false}. |
| 11337 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11338 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11339 | boolean isPhoneAvailable = false; |
| 11340 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11341 | Phone phone = PhoneFactory.getPhone(i); |
| 11342 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11343 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11344 | isPhoneAvailable = true; |
| 11345 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11346 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11347 | |
| 11348 | // return true if successfully informed the phone object about the thermal radio power |
| 11349 | // request. |
| 11350 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11351 | } |
| 11352 | |
| 11353 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11354 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11355 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11356 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11357 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11358 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11359 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11360 | } |
| 11361 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11362 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11363 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11364 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11365 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11366 | } |
| 11367 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11368 | setDataEnabledForReason( |
| 11369 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11370 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11371 | if (isDataThrottlingSupported) { |
| 11372 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11373 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11374 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11375 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11376 | } else if (thermalMitigationResult |
| 11377 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11378 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11379 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11380 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11381 | } |
| 11382 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11383 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11384 | |
| 11385 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11386 | } |
| 11387 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11388 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11389 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11390 | for (String pckg : context.getResources() |
| 11391 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11392 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11393 | } |
| 11394 | } |
| 11395 | |
| 11396 | return sThermalMitigationAllowlistedPackages; |
| 11397 | } |
| 11398 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11399 | private boolean isAnyPhoneInEmergencyState() { |
| 11400 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11401 | if (tm.isInEmergencyCall()) { |
| 11402 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11403 | return true; |
| 11404 | } |
| 11405 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11406 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11407 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11408 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11409 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11410 | return true; |
| 11411 | } |
| 11412 | } |
| 11413 | |
| 11414 | return false; |
| 11415 | } |
| 11416 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11417 | /** |
| 11418 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11419 | * @param packageName name of package to be allowlisted |
| 11420 | * @param context |
| 11421 | */ |
| 11422 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11423 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11424 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11425 | } |
| 11426 | |
| 11427 | /** |
| 11428 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11429 | * @param packageName name of package to remove from allowlist |
| 11430 | * @param context |
| 11431 | */ |
| 11432 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11433 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11434 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11435 | } |
| 11436 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11437 | /** |
| 11438 | * Thermal mitigation request to control functionalities at modem. |
| 11439 | * |
| 11440 | * @param subId the id of the subscription. |
| 11441 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11442 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11443 | * |
| 11444 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11445 | */ |
| 11446 | @Override |
| 11447 | @ThermalMitigationResult |
| 11448 | public int sendThermalMitigationRequest( |
| 11449 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11450 | ThermalMitigationRequest thermalMitigationRequest, |
| 11451 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11452 | enforceModifyPermission(); |
| 11453 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11454 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11455 | |
| 11456 | enforceTelephonyFeatureWithException(callingPackage, |
| 11457 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11458 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11459 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11460 | .contains(callingPackage)) { |
| 11461 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11462 | + "calling package: " + callingPackage); |
| 11463 | } |
| 11464 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11465 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11466 | final long identity = Binder.clearCallingIdentity(); |
| 11467 | |
| 11468 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11469 | try { |
| 11470 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11471 | switch (thermalMitigationAction) { |
| 11472 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11473 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11474 | handleDataThrottlingRequest(subId, |
| 11475 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11476 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11477 | break; |
| 11478 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11479 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11480 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11481 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11482 | } |
| 11483 | |
| 11484 | // Ensure that radio is on. If not able to power on due to phone being |
| 11485 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11486 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11487 | thermalMitigationResult = |
| 11488 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11489 | break; |
| 11490 | } |
| 11491 | |
| 11492 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11493 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11494 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11495 | break; |
| 11496 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11497 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11498 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11499 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11500 | } |
| 11501 | |
| 11502 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11503 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11504 | Phone phone = getPhone(subId); |
| 11505 | if (phone == null) { |
| 11506 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11507 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11508 | break; |
| 11509 | } |
| 11510 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11511 | TelephonyConnectionService service = |
| 11512 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11513 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11514 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11515 | thermalMitigationResult = |
| 11516 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11517 | break; |
| 11518 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11519 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11520 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11521 | break; |
| 11522 | } |
| 11523 | } else { |
| 11524 | thermalMitigationResult = |
| 11525 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11526 | break; |
| 11527 | } |
| 11528 | |
| 11529 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11530 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11531 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11532 | thermalMitigationResult = |
| 11533 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11534 | break; |
| 11535 | } |
| 11536 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11537 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11538 | break; |
| 11539 | default: |
| 11540 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11541 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11542 | } |
| 11543 | } catch (IllegalArgumentException e) { |
| 11544 | throw e; |
| 11545 | } catch (Exception e) { |
| 11546 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11547 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11548 | } finally { |
| 11549 | Binder.restoreCallingIdentity(identity); |
| 11550 | } |
| 11551 | |
| 11552 | if (DBG) { |
| 11553 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11554 | + thermalMitigationResult); |
| 11555 | } |
| 11556 | |
| 11557 | return thermalMitigationResult; |
| 11558 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11559 | |
| 11560 | /** |
| 11561 | * Set the GbaService Package Name that Telephony will bind to. |
| 11562 | * |
| 11563 | * @param subId The sim that the GbaService is associated with. |
| 11564 | * @param packageName The name of the package to be replaced with. |
| 11565 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11566 | */ |
| 11567 | @Override |
| 11568 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11569 | enforceModifyPermission(); |
| 11570 | |
| 11571 | final long identity = Binder.clearCallingIdentity(); |
| 11572 | try { |
| 11573 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11574 | } finally { |
| 11575 | Binder.restoreCallingIdentity(identity); |
| 11576 | } |
| 11577 | } |
| 11578 | |
| 11579 | /** |
| 11580 | * Return the package name of the currently bound GbaService. |
| 11581 | * |
| 11582 | * @param subId The sim that the GbaService is associated with. |
| 11583 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11584 | */ |
| 11585 | @Override |
| 11586 | public String getBoundGbaService(int subId) { |
| 11587 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11588 | |
| 11589 | final long identity = Binder.clearCallingIdentity(); |
| 11590 | try { |
| 11591 | return getGbaManager(subId).getServicePackage(); |
| 11592 | } finally { |
| 11593 | Binder.restoreCallingIdentity(identity); |
| 11594 | } |
| 11595 | } |
| 11596 | |
| 11597 | /** |
| 11598 | * Set the release time for telephony to unbind GbaService. |
| 11599 | * |
| 11600 | * @param subId The sim that the GbaService is associated with. |
| 11601 | * @param interval The release time to unbind GbaService by millisecond. |
| 11602 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11603 | */ |
| 11604 | @Override |
| 11605 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11606 | enforceModifyPermission(); |
| 11607 | |
| 11608 | final long identity = Binder.clearCallingIdentity(); |
| 11609 | try { |
| 11610 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11611 | } finally { |
| 11612 | Binder.restoreCallingIdentity(identity); |
| 11613 | } |
| 11614 | } |
| 11615 | |
| 11616 | /** |
| 11617 | * Return the release time for telephony to unbind GbaService. |
| 11618 | * |
| 11619 | * @param subId The sim that the GbaService is associated with. |
| 11620 | * @return The release time to unbind GbaService by millisecond. |
| 11621 | */ |
| 11622 | @Override |
| 11623 | public int getGbaReleaseTime(int subId) { |
| 11624 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11625 | |
| 11626 | final long identity = Binder.clearCallingIdentity(); |
| 11627 | try { |
| 11628 | return getGbaManager(subId).getReleaseTime(); |
| 11629 | } finally { |
| 11630 | Binder.restoreCallingIdentity(identity); |
| 11631 | } |
| 11632 | } |
| 11633 | |
| 11634 | private GbaManager getGbaManager(int subId) { |
| 11635 | GbaManager instance = GbaManager.getInstance(subId); |
| 11636 | if (instance == null) { |
| 11637 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11638 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11639 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11640 | } |
| 11641 | return instance; |
| 11642 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11643 | |
| 11644 | /** |
| 11645 | * indicate whether the device and the carrier can support |
| 11646 | * RCS VoLTE single registration. |
| 11647 | */ |
| 11648 | @Override |
| 11649 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11650 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11651 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11652 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11653 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11654 | |
| 11655 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11656 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11657 | } |
| 11658 | |
| 11659 | final long identity = Binder.clearCallingIdentity(); |
| 11660 | try { |
| 11661 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11662 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11663 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11664 | if (isCapable != null) { |
| 11665 | return isCapable; |
| 11666 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11667 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11668 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11669 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11670 | } finally { |
| 11671 | Binder.restoreCallingIdentity(identity); |
| 11672 | } |
| 11673 | } |
| 11674 | |
| 11675 | /** |
| 11676 | * Register RCS provisioning callback. |
| 11677 | */ |
| 11678 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11679 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11680 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11681 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11682 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11683 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11684 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11685 | |
| 11686 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11687 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11688 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11689 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11690 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11691 | Binder.getCallingUserHandle())) { |
| 11692 | if (!isImsAvailableOnDevice()) { |
| 11693 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11694 | "IMS not available on device."); |
| 11695 | } |
| 11696 | } else { |
| 11697 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11698 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11699 | } |
| 11700 | |
| 11701 | final long identity = Binder.clearCallingIdentity(); |
| 11702 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11703 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11704 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11705 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11706 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11707 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11708 | } finally { |
| 11709 | Binder.restoreCallingIdentity(identity); |
| 11710 | } |
| 11711 | } |
| 11712 | |
| 11713 | /** |
| 11714 | * Unregister RCS provisioning callback. |
| 11715 | */ |
| 11716 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11717 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11718 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11719 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11720 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11721 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11722 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11723 | |
| 11724 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11725 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11726 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11727 | |
| 11728 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11729 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11730 | Binder.getCallingUserHandle())) { |
| 11731 | if (!isImsAvailableOnDevice()) { |
| 11732 | // operation failed silently |
| 11733 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11734 | return; |
| 11735 | } |
| 11736 | } else { |
| 11737 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11738 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11739 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11740 | } |
| 11741 | |
| 11742 | final long identity = Binder.clearCallingIdentity(); |
| 11743 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11744 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11745 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11746 | } finally { |
| 11747 | Binder.restoreCallingIdentity(identity); |
| 11748 | } |
| 11749 | } |
| 11750 | |
| 11751 | /** |
| 11752 | * trigger RCS reconfiguration. |
| 11753 | */ |
| 11754 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11755 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11756 | "triggerRcsReconfiguration", |
| 11757 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11758 | |
| 11759 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11760 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11761 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11762 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11763 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11764 | Binder.getCallingUserHandle())) { |
| 11765 | if (!isImsAvailableOnDevice()) { |
| 11766 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11767 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11768 | throw new IllegalStateException("IMS not available on device."); |
| 11769 | } |
| 11770 | } else { |
| 11771 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11772 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11773 | } |
| 11774 | |
| 11775 | final long identity = Binder.clearCallingIdentity(); |
| 11776 | try { |
| 11777 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11778 | } finally { |
| 11779 | Binder.restoreCallingIdentity(identity); |
| 11780 | } |
| 11781 | } |
| 11782 | |
| 11783 | /** |
| 11784 | * Provide the client configuration parameters of the RCS application. |
| 11785 | */ |
| 11786 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11787 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11788 | "setRcsClientConfiguration", |
| 11789 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11790 | |
| 11791 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11792 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11793 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11794 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11795 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11796 | Binder.getCallingUserHandle())) { |
| 11797 | if (!isImsAvailableOnDevice()) { |
| 11798 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11799 | "IMS not available on device."); |
| 11800 | } |
| 11801 | } else { |
| 11802 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11803 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11804 | } |
| 11805 | |
| 11806 | final long identity = Binder.clearCallingIdentity(); |
| 11807 | |
| 11808 | try { |
| 11809 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11810 | if (configBinder == null) { |
| 11811 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11813 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11814 | } else { |
| 11815 | configBinder.setRcsClientConfiguration(rcc); |
| 11816 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11817 | |
| 11818 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11819 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11820 | } catch (RemoteException e) { |
| 11821 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11822 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11823 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11824 | } finally { |
| 11825 | Binder.restoreCallingIdentity(identity); |
| 11826 | } |
| 11827 | } |
| 11828 | |
| 11829 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11830 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11831 | */ |
| 11832 | @Override |
| 11833 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11834 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11835 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11836 | |
| 11837 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11838 | } |
| 11839 | |
| 11840 | /** |
| 11841 | * Gets the test mode for RCS VoLTE single registration. |
| 11842 | */ |
| 11843 | @Override |
| 11844 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11845 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11846 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11847 | |
| 11848 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11849 | } |
| 11850 | |
| 11851 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11852 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11853 | */ |
| 11854 | @Override |
| 11855 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11856 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11857 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11858 | enforceModifyPermission(); |
| 11859 | |
| 11860 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11861 | : Boolean.parseBoolean(enabledStr); |
| 11862 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11863 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11864 | } |
| 11865 | |
| 11866 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11867 | * Sends a device to device communication message. Only usable via shell. |
| 11868 | * @param message message to send. |
| 11869 | * @param value message value. |
| 11870 | */ |
| 11871 | @Override |
| 11872 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11873 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11874 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11875 | enforceModifyPermission(); |
| 11876 | |
| 11877 | final long identity = Binder.clearCallingIdentity(); |
| 11878 | try { |
| 11879 | TelephonyConnectionService service = |
| 11880 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11881 | if (service == null) { |
| 11882 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11883 | return; |
| 11884 | } |
| 11885 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11886 | } finally { |
| 11887 | Binder.restoreCallingIdentity(identity); |
| 11888 | } |
| 11889 | } |
| 11890 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11891 | /** |
| 11892 | * Sets the specified device to device transport active. |
| 11893 | * @param transport The transport to set active. |
| 11894 | */ |
| 11895 | @Override |
| 11896 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11897 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11898 | "setActiveDeviceToDeviceTransport"); |
| 11899 | enforceModifyPermission(); |
| 11900 | |
| 11901 | final long identity = Binder.clearCallingIdentity(); |
| 11902 | try { |
| 11903 | TelephonyConnectionService service = |
| 11904 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11905 | if (service == null) { |
| 11906 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11907 | return; |
| 11908 | } |
| 11909 | service.setActiveDeviceToDeviceTransport(transport); |
| 11910 | } finally { |
| 11911 | Binder.restoreCallingIdentity(identity); |
| 11912 | } |
| 11913 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11914 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11915 | @Override |
| 11916 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11917 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11918 | "setDeviceToDeviceForceEnabled"); |
| 11919 | |
| 11920 | final long identity = Binder.clearCallingIdentity(); |
| 11921 | try { |
| 11922 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11923 | p -> { |
| 11924 | Phone thePhone = p.getImsPhone(); |
| 11925 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11926 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11927 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11928 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11929 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11930 | (ImsPhoneCallTracker) tracker; |
| 11931 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11932 | } |
| 11933 | } |
| 11934 | } |
| 11935 | ); |
| 11936 | } finally { |
| 11937 | Binder.restoreCallingIdentity(identity); |
| 11938 | } |
| 11939 | } |
| 11940 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11941 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11942 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11943 | */ |
| 11944 | @Override |
| 11945 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11946 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11947 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11948 | } |
| 11949 | |
| 11950 | /** |
| 11951 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11952 | */ |
| 11953 | @Override |
| 11954 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11955 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11956 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11957 | enforceModifyPermission(); |
| 11958 | |
| 11959 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11960 | : Boolean.parseBoolean(enabledStr); |
| 11961 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11962 | subId, enabled); |
| 11963 | } |
| 11964 | |
| 11965 | /** |
| 11966 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11967 | */ |
| 11968 | @Override |
| 11969 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11970 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11971 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11972 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11973 | |
| 11974 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11975 | * Overrides the ims feature validation result |
| 11976 | */ |
| 11977 | @Override |
| 11978 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11979 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11980 | "setImsFeatureValidationOverride"); |
| 11981 | |
| 11982 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11983 | : Boolean.parseBoolean(enabledStr); |
| 11984 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11985 | subId, enabled); |
| 11986 | } |
| 11987 | |
| 11988 | /** |
| 11989 | * Gets the ims feature validation override value |
| 11990 | */ |
| 11991 | @Override |
| 11992 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11993 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11994 | "getImsFeatureValidationOverride"); |
| 11995 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11996 | } |
| 11997 | |
| 11998 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11999 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12000 | * their mobile plan. |
| 12001 | */ |
| 12002 | @Override |
| 12003 | public String getMobileProvisioningUrl() { |
| 12004 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12005 | final long identity = Binder.clearCallingIdentity(); |
| 12006 | try { |
| 12007 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12008 | } finally { |
| 12009 | Binder.restoreCallingIdentity(identity); |
| 12010 | } |
| 12011 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12012 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12013 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12014 | * Get the EAB contact from the EAB database. |
| 12015 | */ |
| 12016 | @Override |
| 12017 | public String getContactFromEab(String contact) { |
| 12018 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12019 | enforceModifyPermission(); |
| 12020 | final long identity = Binder.clearCallingIdentity(); |
| 12021 | try { |
| 12022 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12023 | } finally { |
| 12024 | Binder.restoreCallingIdentity(identity); |
| 12025 | } |
| 12026 | } |
| 12027 | |
| 12028 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12029 | * Get the EAB capability from the EAB database. |
| 12030 | */ |
| 12031 | @Override |
| 12032 | public String getCapabilityFromEab(String contact) { |
| 12033 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12034 | enforceModifyPermission(); |
| 12035 | final long identity = Binder.clearCallingIdentity(); |
| 12036 | try { |
| 12037 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12038 | } finally { |
| 12039 | Binder.restoreCallingIdentity(identity); |
| 12040 | } |
| 12041 | } |
| 12042 | |
| 12043 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12044 | * Remove the EAB contacts from the EAB database. |
| 12045 | */ |
| 12046 | @Override |
| 12047 | public int removeContactFromEab(int subId, String contacts) { |
| 12048 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12049 | enforceModifyPermission(); |
| 12050 | final long identity = Binder.clearCallingIdentity(); |
| 12051 | try { |
| 12052 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12053 | } finally { |
| 12054 | Binder.restoreCallingIdentity(identity); |
| 12055 | } |
| 12056 | } |
| 12057 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12058 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12059 | public boolean getDeviceUceEnabled() { |
| 12060 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12061 | final long identity = Binder.clearCallingIdentity(); |
| 12062 | try { |
| 12063 | return mApp.getDeviceUceEnabled(); |
| 12064 | } finally { |
| 12065 | Binder.restoreCallingIdentity(identity); |
| 12066 | } |
| 12067 | } |
| 12068 | |
| 12069 | @Override |
| 12070 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12071 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12072 | final long identity = Binder.clearCallingIdentity(); |
| 12073 | try { |
| 12074 | mApp.setDeviceUceEnabled(isEnabled); |
| 12075 | } finally { |
| 12076 | Binder.restoreCallingIdentity(identity); |
| 12077 | } |
| 12078 | } |
| 12079 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12080 | /** |
| 12081 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12082 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12083 | */ |
| 12084 | // Used for SHELL command only right now. |
| 12085 | @Override |
| 12086 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12087 | List<String> featureTags) { |
| 12088 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12089 | "addUceRegistrationOverrideShell"); |
| 12090 | final long identity = Binder.clearCallingIdentity(); |
| 12091 | try { |
| 12092 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12093 | new ArraySet<>(featureTags)); |
| 12094 | } catch (ImsException e) { |
| 12095 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12096 | } finally { |
| 12097 | Binder.restoreCallingIdentity(identity); |
| 12098 | } |
| 12099 | } |
| 12100 | |
| 12101 | /** |
| 12102 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12103 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12104 | */ |
| 12105 | // Used for SHELL command only right now. |
| 12106 | @Override |
| 12107 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12108 | List<String> featureTags) { |
| 12109 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12110 | "removeUceRegistrationOverrideShell"); |
| 12111 | final long identity = Binder.clearCallingIdentity(); |
| 12112 | try { |
| 12113 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12114 | new ArraySet<>(featureTags)); |
| 12115 | } catch (ImsException e) { |
| 12116 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12117 | } finally { |
| 12118 | Binder.restoreCallingIdentity(identity); |
| 12119 | } |
| 12120 | } |
| 12121 | |
| 12122 | /** |
| 12123 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12124 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12125 | */ |
| 12126 | // Used for SHELL command only right now. |
| 12127 | @Override |
| 12128 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12129 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12130 | "clearUceRegistrationOverrideShell"); |
| 12131 | final long identity = Binder.clearCallingIdentity(); |
| 12132 | try { |
| 12133 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12134 | } catch (ImsException e) { |
| 12135 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12136 | } finally { |
| 12137 | Binder.restoreCallingIdentity(identity); |
| 12138 | } |
| 12139 | } |
| 12140 | |
| 12141 | /** |
| 12142 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12143 | */ |
| 12144 | // Used for SHELL command only right now. |
| 12145 | @Override |
| 12146 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12147 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12148 | "getLatestRcsContactUceCapabilityShell"); |
| 12149 | final long identity = Binder.clearCallingIdentity(); |
| 12150 | try { |
| 12151 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12152 | } catch (ImsException e) { |
| 12153 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12154 | } finally { |
| 12155 | Binder.restoreCallingIdentity(identity); |
| 12156 | } |
| 12157 | } |
| 12158 | |
| 12159 | /** |
| 12160 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12161 | * device does not have an active PUBLISH. |
| 12162 | */ |
| 12163 | // Used for SHELL command only right now. |
| 12164 | @Override |
| 12165 | public String getLastUcePidfXmlShell(int subId) { |
| 12166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12167 | final long identity = Binder.clearCallingIdentity(); |
| 12168 | try { |
| 12169 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12170 | } catch (ImsException e) { |
| 12171 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12172 | } finally { |
| 12173 | Binder.restoreCallingIdentity(identity); |
| 12174 | } |
| 12175 | } |
| 12176 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12177 | /** |
| 12178 | * Remove UCE requests cannot be sent to the network status. |
| 12179 | */ |
| 12180 | // Used for SHELL command only right now. |
| 12181 | @Override |
| 12182 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12183 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12184 | final long identity = Binder.clearCallingIdentity(); |
| 12185 | try { |
| 12186 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12187 | } catch (ImsException e) { |
| 12188 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12189 | } finally { |
| 12190 | Binder.restoreCallingIdentity(identity); |
| 12191 | } |
| 12192 | } |
| 12193 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12194 | /** |
| 12195 | * Remove UCE requests cannot be sent to the network status. |
| 12196 | */ |
| 12197 | // Used for SHELL command only. |
| 12198 | @Override |
| 12199 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12201 | final long identity = Binder.clearCallingIdentity(); |
| 12202 | try { |
| 12203 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12204 | } catch (ImsException e) { |
| 12205 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12206 | } finally { |
| 12207 | Binder.restoreCallingIdentity(identity); |
| 12208 | } |
| 12209 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12210 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12211 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12212 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12213 | String callingPackage) { |
| 12214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12215 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12216 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12217 | enforceTelephonyFeatureWithException(callingPackage, |
| 12218 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12219 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12220 | final int callingUid = Binder.getCallingUid(); |
| 12221 | // Verify that tha callingPackage belongs to the calling UID |
| 12222 | mApp.getSystemService(AppOpsManager.class) |
| 12223 | .checkPackage(callingUid, callingPackage); |
| 12224 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12225 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12226 | |
| 12227 | final long identity = Binder.clearCallingIdentity(); |
| 12228 | try { |
| 12229 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12230 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12231 | |
| 12232 | if (result instanceof IllegalStateException) { |
| 12233 | throw (IllegalStateException) result; |
| 12234 | } |
| 12235 | } finally { |
| 12236 | Binder.restoreCallingIdentity(identity); |
| 12237 | } |
| 12238 | } |
| 12239 | |
| 12240 | @Override |
| 12241 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12242 | String callingPackage) { |
| 12243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12244 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12245 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12246 | enforceTelephonyFeatureWithException(callingPackage, |
| 12247 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12248 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12249 | final int callingUid = Binder.getCallingUid(); |
| 12250 | // Verify that tha callingPackage belongs to the calling UID |
| 12251 | mApp.getSystemService(AppOpsManager.class) |
| 12252 | .checkPackage(callingUid, callingPackage); |
| 12253 | |
| 12254 | final long identity = Binder.clearCallingIdentity(); |
| 12255 | try { |
| 12256 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12257 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12258 | |
| 12259 | if (result instanceof IllegalStateException) { |
| 12260 | throw (IllegalStateException) result; |
| 12261 | } |
| 12262 | } finally { |
| 12263 | Binder.restoreCallingIdentity(identity); |
| 12264 | } |
| 12265 | } |
| 12266 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12267 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12268 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12269 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12270 | // phone/system process do not have further restriction on request |
| 12271 | return; |
| 12272 | } |
| 12273 | |
| 12274 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12275 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12276 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12277 | context.enforceCallingOrSelfPermission( |
| 12278 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12279 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12280 | } |
| 12281 | |
| 12282 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12283 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12284 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12285 | || info.isEnabled()) { |
| 12286 | throw new IllegalArgumentException( |
| 12287 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12288 | } |
| 12289 | |
| 12290 | // Thresholds length for each RAN need in range. This has been validated in |
| 12291 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12292 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12293 | final int[] thresholds = info.getThresholds(); |
| 12294 | Objects.requireNonNull(thresholds); |
| 12295 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12296 | || thresholds.length |
| 12297 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12298 | throw new IllegalArgumentException( |
| 12299 | "thresholds length is out of range: " + thresholds.length); |
| 12300 | } |
| 12301 | } |
| 12302 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12303 | |
| 12304 | /** |
| 12305 | * Gets the current phone capability. |
| 12306 | * |
| 12307 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12308 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12309 | * It's used to evaluate possible phone config change, for example from single |
| 12310 | * SIM device to multi-SIM device. |
| 12311 | */ |
| 12312 | @Override |
| 12313 | public PhoneCapability getPhoneCapability() { |
| 12314 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12315 | |
| 12316 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12317 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12318 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12319 | final long identity = Binder.clearCallingIdentity(); |
| 12320 | try { |
| 12321 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12322 | } finally { |
| 12323 | Binder.restoreCallingIdentity(identity); |
| 12324 | } |
| 12325 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12326 | |
| 12327 | /** |
| 12328 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12329 | * required to be done shortly after the API is invoked. |
| 12330 | */ |
| 12331 | @Override |
| 12332 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12333 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12334 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12335 | enforceRebootPermission(); |
| 12336 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12337 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12338 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12339 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12340 | final long identity = Binder.clearCallingIdentity(); |
| 12341 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12342 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12343 | } finally { |
| 12344 | Binder.restoreCallingIdentity(identity); |
| 12345 | } |
| 12346 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12347 | |
| 12348 | /** |
| 12349 | * Request to get the current slicing configuration including URSP rules and |
| 12350 | * NSSAIs (configured, allowed and rejected). |
| 12351 | * |
| 12352 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12353 | */ |
| 12354 | @Override |
| 12355 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12356 | TelephonyPermissions |
| 12357 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12358 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12359 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12360 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12361 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12362 | "getSlicingConfig"); |
| 12363 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12364 | final long identity = Binder.clearCallingIdentity(); |
| 12365 | try { |
| 12366 | Phone phone = getDefaultPhone(); |
| 12367 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12368 | } finally { |
| 12369 | Binder.restoreCallingIdentity(identity); |
| 12370 | } |
| 12371 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12372 | |
| 12373 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12374 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12375 | * |
| 12376 | * @param capability The premium capability to check. |
| 12377 | * @param subId The subId to check the premium capability for. |
| 12378 | * |
| 12379 | * @return Whether the given premium capability is available to purchase. |
| 12380 | */ |
| 12381 | @Override |
| 12382 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12383 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12384 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12385 | log("Premium capability " |
| 12386 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12387 | + " is not available for purchase due to missing permissions."); |
| 12388 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12389 | + "permission READ_BASIC_PHONE_STATE."); |
| 12390 | } |
| 12391 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12392 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12393 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12394 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12395 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12396 | if (phone == null) { |
| 12397 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12398 | return false; |
| 12399 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12400 | final long identity = Binder.clearCallingIdentity(); |
| 12401 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12402 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12403 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12404 | } finally { |
| 12405 | Binder.restoreCallingIdentity(identity); |
| 12406 | } |
| 12407 | } |
| 12408 | |
| 12409 | /** |
| 12410 | * Purchase the given premium capability from the carrier. |
| 12411 | * |
| 12412 | * @param capability The premium capability to purchase. |
| 12413 | * @param callback The result of the purchase request. |
| 12414 | * @param subId The subId to purchase the premium capability for. |
| 12415 | */ |
| 12416 | @Override |
| 12417 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12418 | log("purchasePremiumCapability: capability=" |
| 12419 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12420 | + getCurrentPackageName()); |
| 12421 | |
| 12422 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12423 | mApp, "purchasePremiumCapability")) { |
| 12424 | log("purchasePremiumCapability " |
| 12425 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12426 | + " failed due to missing permissions."); |
| 12427 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12428 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12429 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12430 | mApp, "purchasePremiumCapability")) { |
| 12431 | log("purchasePremiumCapability " |
| 12432 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12433 | + " failed due to missing permissions."); |
| 12434 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12435 | } |
| 12436 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12437 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12438 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12439 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12440 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12441 | if (phone == null) { |
| 12442 | try { |
| 12443 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12444 | callback.accept(result); |
| 12445 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12446 | } catch (RemoteException e) { |
| 12447 | String logStr = "Purchase premium capability " |
| 12448 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12449 | + " failed due to RemoteException handling null phone: " + e; |
| 12450 | if (DBG) log(logStr); |
| 12451 | AnomalyReporter.reportAnomaly( |
| 12452 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12453 | } |
| 12454 | return; |
| 12455 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12456 | |
| 12457 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12458 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12459 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12460 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12461 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12462 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12463 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12464 | |
| 12465 | boolean isVisible = false; |
| 12466 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12467 | if (am != null) { |
| 12468 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12469 | if (processes != null) { |
| 12470 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12471 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12472 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12473 | if (process.processName.equals(callingProcess) && process.importance |
| 12474 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12475 | isVisible = true; |
| 12476 | break; |
| 12477 | } |
| 12478 | } |
| 12479 | } |
| 12480 | } |
| 12481 | |
| 12482 | if (!isVisible) { |
| 12483 | try { |
| 12484 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12485 | callback.accept(result); |
| 12486 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12487 | } catch (RemoteException e) { |
| 12488 | String logStr = "Purchase premium capability " |
| 12489 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12490 | + " failed due to RemoteException handling background application: " + e; |
| 12491 | if (DBG) log(logStr); |
| 12492 | AnomalyReporter.reportAnomaly( |
| 12493 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12494 | } |
| 12495 | return; |
| 12496 | } |
| 12497 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12498 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12499 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12500 | } |
| 12501 | |
| 12502 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12503 | * Register an IMS connection state callback |
| 12504 | */ |
| 12505 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12506 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12507 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12508 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12509 | // ImsMmTelManager |
| 12510 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12511 | TelephonyPermissions |
| 12512 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12513 | mApp, subId, "registerImsStateCallback"); |
| 12514 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12515 | // ImsRcsManager or SipDelegateManager |
| 12516 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12517 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12518 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12519 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12520 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12521 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12522 | } |
| 12523 | |
| 12524 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12525 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12526 | "IMS not available on device."); |
| 12527 | } |
| 12528 | |
| 12529 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12531 | } |
| 12532 | |
| 12533 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12534 | if (controller == null) { |
| 12535 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12536 | "IMS not available on device."); |
| 12537 | } |
| 12538 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12539 | if (callingPackage == null) { |
| 12540 | callingPackage = getCurrentPackageName(); |
| 12541 | } |
| 12542 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12543 | final long token = Binder.clearCallingIdentity(); |
| 12544 | try { |
| 12545 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12546 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12547 | } catch (ImsException e) { |
| 12548 | throw new ServiceSpecificException(e.getCode()); |
| 12549 | } finally { |
| 12550 | Binder.restoreCallingIdentity(token); |
| 12551 | } |
| 12552 | } |
| 12553 | |
| 12554 | /** |
| 12555 | * Unregister an IMS connection state callback |
| 12556 | */ |
| 12557 | @Override |
| 12558 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12559 | final long token = Binder.clearCallingIdentity(); |
| 12560 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12561 | if (controller == null) { |
| 12562 | return; |
| 12563 | } |
| 12564 | try { |
| 12565 | controller.unregisterImsStateCallback(cb); |
| 12566 | } finally { |
| 12567 | Binder.restoreCallingIdentity(token); |
| 12568 | } |
| 12569 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12570 | |
| 12571 | /** |
| 12572 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12573 | * |
| 12574 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12575 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12576 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12577 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12578 | * If there is current registered network this value will be same as the registered cell |
| 12579 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12580 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12581 | * it will be cleared and null will be returned. |
| 12582 | * |
| 12583 | */ |
| 12584 | @Override |
| 12585 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12586 | String callingFeatureId) { |
| 12587 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12588 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12589 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12590 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12591 | .setCallingPackage(callingPackage) |
| 12592 | .setCallingFeatureId(callingFeatureId) |
| 12593 | .setCallingPid(Binder.getCallingPid()) |
| 12594 | .setCallingUid(Binder.getCallingUid()) |
| 12595 | .setMethod("getLastKnownCellIdentity") |
| 12596 | .setLogAsInfo(true) |
| 12597 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12598 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12599 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12600 | .build()); |
| 12601 | |
| 12602 | boolean hasFinePermission = |
| 12603 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12604 | if (!hasFinePermission |
| 12605 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12606 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12607 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12608 | } |
| 12609 | |
| 12610 | final long identity = Binder.clearCallingIdentity(); |
| 12611 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12612 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12613 | if (sst == null) return null; |
| 12614 | return sst.getLastKnownCellIdentity(); |
| 12615 | } finally { |
| 12616 | Binder.restoreCallingIdentity(identity); |
| 12617 | } |
| 12618 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12619 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12620 | /** |
| 12621 | * Sets the modem service class Name that Telephony will bind to. |
| 12622 | * |
| 12623 | * @param serviceName The class name of the modem service. |
| 12624 | * @return true if the operation is succeed, otherwise false. |
| 12625 | */ |
| 12626 | public boolean setModemService(String serviceName) { |
| 12627 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12630 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12631 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12632 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12633 | } |
| 12634 | |
| 12635 | /** |
| 12636 | * Return the class name of the currently bounded modem service. |
| 12637 | * |
| 12638 | * @return the class name of the modem service. |
| 12639 | */ |
| 12640 | public String getModemService() { |
| 12641 | String result; |
| 12642 | Log.d(LOG_TAG, "getModemService"); |
| 12643 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12644 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12645 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12646 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12647 | "getModemService"); |
| 12648 | result = mPhoneConfigurationManager.getModemService(); |
| 12649 | Log.d(LOG_TAG, "result = " + result); |
| 12650 | return result; |
| 12651 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12652 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12653 | /** |
| 12654 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12655 | * including carrier config, entitlement server, and config update. |
| 12656 | * |
| 12657 | * @param subId subId The subscription ID of the carrier. |
| 12658 | * |
| 12659 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12660 | * be returned. |
| 12661 | * |
| 12662 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12663 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12664 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12665 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12666 | final long identity = Binder.clearCallingIdentity(); |
| 12667 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12668 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12669 | } finally { |
| 12670 | Binder.restoreCallingIdentity(identity); |
| 12671 | } |
| 12672 | } |
| 12673 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12674 | @Override |
| 12675 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12676 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12677 | mApp.enforceCallingOrSelfPermission( |
| 12678 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12679 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12680 | |
| 12681 | final long identity = Binder.clearCallingIdentity(); |
| 12682 | try { |
| 12683 | Phone phone = getPhone(subId); |
| 12684 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12685 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12686 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12687 | phone.setVoiceServiceStateOverride(hasService); |
| 12688 | } finally { |
| 12689 | Binder.restoreCallingIdentity(identity); |
| 12690 | } |
| 12691 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12692 | |
| 12693 | /** |
| 12694 | * set removable eSIM as default eUICC. |
| 12695 | * |
| 12696 | * @hide |
| 12697 | */ |
| 12698 | @Override |
| 12699 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12700 | enforceModifyPermission(); |
| 12701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12702 | |
| 12703 | final long identity = Binder.clearCallingIdentity(); |
| 12704 | try { |
| 12705 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12706 | } finally { |
| 12707 | Binder.restoreCallingIdentity(identity); |
| 12708 | } |
| 12709 | } |
| 12710 | |
| 12711 | /** |
| 12712 | * Returns whether the removable eSIM is default eUICC or not. |
| 12713 | * |
| 12714 | * @hide |
| 12715 | */ |
| 12716 | @Override |
| 12717 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12718 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12719 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12720 | |
| 12721 | final long identity = Binder.clearCallingIdentity(); |
| 12722 | try { |
| 12723 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12724 | } finally { |
| 12725 | Binder.restoreCallingIdentity(identity); |
| 12726 | } |
| 12727 | } |
| 12728 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12729 | /** |
| 12730 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12731 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12732 | * application currently configured for this user. |
| 12733 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12734 | * {@code null} if the functionality is not supported. |
| 12735 | * @hide |
| 12736 | */ |
| 12737 | @Override |
| 12738 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12739 | boolean updateIfNeeded) { |
| 12740 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12741 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12742 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12743 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12744 | "getDefaultRespondViaMessageApplication"); |
| 12745 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12746 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12747 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12748 | UserHandle userHandle = null; |
| 12749 | final long identity = Binder.clearCallingIdentity(); |
| 12750 | try { |
| 12751 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12752 | } finally { |
| 12753 | Binder.restoreCallingIdentity(identity); |
| 12754 | } |
| 12755 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12756 | updateIfNeeded, userHandle); |
| 12757 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12758 | |
| 12759 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12760 | * Set whether the device is able to connect with null ciphering or integrity |
| 12761 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12762 | * and all new subscriptions after this. |
| 12763 | * |
| 12764 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12765 | * @hide |
| 12766 | */ |
| 12767 | @Override |
| 12768 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12769 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12770 | enforceModifyPermission(); |
| 12771 | checkForNullCipherAndIntegritySupport(); |
| 12772 | |
| 12773 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12774 | // for listening to these preference changes and applying them immediately. |
| 12775 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12776 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12777 | editor.apply(); |
| 12778 | |
| 12779 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12780 | phone.handleNullCipherEnabledChange(); |
| 12781 | } |
| 12782 | } |
| 12783 | |
| 12784 | |
| 12785 | /** |
| 12786 | * Get whether the device is able to connect with null ciphering or integrity |
| 12787 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12788 | * the state of the radio. |
| 12789 | * |
| 12790 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12791 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12792 | * version for this feature. |
| 12793 | * @hide |
| 12794 | */ |
| 12795 | @Override |
| 12796 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12797 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12798 | enforceReadPermission(); |
| 12799 | checkForNullCipherAndIntegritySupport(); |
| 12800 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12801 | } |
| 12802 | |
| 12803 | private void checkForNullCipherAndIntegritySupport() { |
| 12804 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12805 | throw new UnsupportedOperationException( |
| 12806 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12807 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12808 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12809 | throw new UnsupportedOperationException( |
| 12810 | "Null cipher and integrity operations unsupported by modem"); |
| 12811 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12812 | } |
| 12813 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12814 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12815 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12816 | throw new UnsupportedOperationException( |
| 12817 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12818 | + "above"); |
| 12819 | } |
| 12820 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12821 | throw new UnsupportedOperationException( |
| 12822 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12823 | } |
| 12824 | } |
| 12825 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12826 | private void checkForNullCipherNotificationSupport() { |
| 12827 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12828 | throw new UnsupportedOperationException( |
| 12829 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12830 | } |
| 12831 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12832 | throw new UnsupportedOperationException( |
| 12833 | "Null cipher notification operations unsupported by modem"); |
| 12834 | } |
| 12835 | } |
| 12836 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12837 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12838 | * Get the SIM state for the slot index. |
| 12839 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12840 | * |
| 12841 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12842 | */ |
| 12843 | @Override |
| 12844 | @SimState |
| 12845 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12846 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12847 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12848 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12849 | IccCardConstants.State simState; |
| 12850 | if (slotIndex < 0) { |
| 12851 | simState = IccCardConstants.State.UNKNOWN; |
| 12852 | } else { |
| 12853 | Phone phone = null; |
| 12854 | try { |
| 12855 | phone = PhoneFactory.getPhone(slotIndex); |
| 12856 | } catch (IllegalStateException e) { |
| 12857 | // ignore |
| 12858 | } |
| 12859 | if (phone == null) { |
| 12860 | simState = IccCardConstants.State.UNKNOWN; |
| 12861 | } else { |
| 12862 | IccCard icc = phone.getIccCard(); |
| 12863 | if (icc == null) { |
| 12864 | simState = IccCardConstants.State.UNKNOWN; |
| 12865 | } else { |
| 12866 | simState = icc.getState(); |
| 12867 | } |
| 12868 | } |
| 12869 | } |
| 12870 | return simState.ordinal(); |
| 12871 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12872 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12873 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12874 | boolean enableLogcat, |
| 12875 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12876 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12877 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12878 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12879 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12880 | ecdDataBuilder |
| 12881 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12882 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12883 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12884 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12885 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12886 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12887 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12888 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12889 | Executors.newCachedThreadPool(), db, |
| 12890 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12891 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12892 | } |
| 12893 | |
| 12894 | /** |
| 12895 | * Request telephony to persist state for debugging emergency call failures. |
| 12896 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12897 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12898 | * @param enableLogcat whether to collect logcat output |
| 12899 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12900 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12901 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12902 | */ |
| 12903 | @Override |
| 12904 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12905 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12906 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12907 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 12908 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 12909 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 12910 | && Flags.enableReadDropboxPermission()) { |
| 12911 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 12912 | "persistEmergencyCallDiagnosticData"); |
| 12913 | } else { |
| 12914 | // Otherwise, enforce legacy permission. |
| 12915 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12916 | "persistEmergencyCallDiagnosticData"); |
| 12917 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12918 | final long identity = Binder.clearCallingIdentity(); |
| 12919 | try { |
| 12920 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12921 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12922 | |
| 12923 | } finally { |
| 12924 | Binder.restoreCallingIdentity(identity); |
| 12925 | } |
| 12926 | } |
| 12927 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12928 | /** |
| 12929 | * Get current cell broadcast ranges. |
| 12930 | */ |
| 12931 | @Override |
| 12932 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12933 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12934 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12935 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12936 | |
| 12937 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12938 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12939 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12940 | final long identity = Binder.clearCallingIdentity(); |
| 12941 | try { |
| 12942 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12943 | } finally { |
| 12944 | Binder.restoreCallingIdentity(identity); |
| 12945 | } |
| 12946 | } |
| 12947 | |
| 12948 | /** |
| 12949 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12950 | * |
| 12951 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12952 | */ |
| 12953 | @Override |
| 12954 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12955 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12956 | @Nullable IIntegerConsumer callback) { |
| 12957 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12958 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12959 | |
| 12960 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12961 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12962 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12963 | final long identity = Binder.clearCallingIdentity(); |
| 12964 | try { |
| 12965 | Phone phone = getPhoneFromSubId(subId); |
| 12966 | if (DBG) { |
| 12967 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12968 | } |
| 12969 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12970 | if (callback != null) { |
| 12971 | try { |
| 12972 | callback.accept(result); |
| 12973 | } catch (RemoteException e) { |
| 12974 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12975 | } |
| 12976 | } |
| 12977 | }); |
| 12978 | } finally { |
| 12979 | Binder.restoreCallingIdentity(identity); |
| 12980 | } |
| 12981 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12982 | |
| 12983 | /** |
| 12984 | * Returns whether the device supports the domain selection service. |
| 12985 | * |
| 12986 | * @return {@code true} if the device supports the domain selection service. |
| 12987 | */ |
| 12988 | @Override |
| 12989 | public boolean isDomainSelectionSupported() { |
| 12990 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12991 | "isDomainSelectionSupported"); |
| 12992 | |
| 12993 | final long identity = Binder.clearCallingIdentity(); |
| 12994 | try { |
| 12995 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12996 | } finally { |
| 12997 | Binder.restoreCallingIdentity(identity); |
| 12998 | } |
| 12999 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13000 | |
| 13001 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13002 | * Returns whether the AOSP domain selection service is supported. |
| 13003 | * |
| 13004 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13005 | * {@code false} otherwise. |
| 13006 | */ |
| 13007 | @Override |
| 13008 | public boolean isAospDomainSelectionService() { |
| 13009 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13010 | "isAospDomainSelectionService"); |
| 13011 | |
| 13012 | final long identity = Binder.clearCallingIdentity(); |
| 13013 | try { |
| 13014 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13015 | String dssComponentName = mApp.getResources().getString( |
| 13016 | R.string.config_domain_selection_service_component_name); |
| 13017 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13018 | TelephonyDomainSelectionService.class.getName()); |
| 13019 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13020 | + ", aosp=" + componentName.flattenToString()); |
| 13021 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13022 | } |
| 13023 | } finally { |
| 13024 | Binder.restoreCallingIdentity(identity); |
| 13025 | } |
| 13026 | return false; |
| 13027 | } |
| 13028 | |
| 13029 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13030 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13031 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13032 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13033 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13034 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13035 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13036 | * {@code false} to disable. |
| 13037 | * @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] | 13038 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13039 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13040 | * |
| 13041 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13042 | */ |
| 13043 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13044 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13045 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13046 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13047 | if (enableSatellite) { |
| 13048 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13049 | @Override |
| 13050 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13051 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13052 | + ", resultData=" + resultData); |
| 13053 | boolean isAllowed = false; |
| 13054 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13055 | callback::accept); |
| 13056 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13057 | if (resultData != null |
| 13058 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13059 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13060 | } else { |
| 13061 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13062 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13063 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13064 | result.accept(resultCode); |
| 13065 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13066 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13067 | if (isAllowed) { |
| 13068 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13069 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13070 | } else { |
| 13071 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13072 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13073 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13074 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13075 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13076 | subId, resultReceiver); |
| 13077 | } else { |
| 13078 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13079 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13080 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13081 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13082 | } |
| 13083 | |
| 13084 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13085 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13086 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13087 | * @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] | 13088 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13089 | * 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] | 13090 | * |
| 13091 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13092 | */ |
| 13093 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13094 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13095 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13096 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13097 | } |
| 13098 | |
| 13099 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13100 | * Request to get whether the satellite service demo mode is enabled. |
| 13101 | * |
| 13102 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13103 | * is enabled for. |
| 13104 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13105 | * if the request is successful or an error code if the request failed. |
| 13106 | * |
| 13107 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13108 | */ |
| 13109 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13110 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13111 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13112 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13113 | } |
| 13114 | |
| 13115 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13116 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13117 | * |
| 13118 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13119 | * is enabled for. |
| 13120 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13121 | * enabled if the request is successful or an error code if the request failed. |
| 13122 | * |
| 13123 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13124 | */ |
| 13125 | @Override |
| 13126 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13127 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13128 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13129 | } |
| 13130 | |
| 13131 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13132 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13133 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13134 | * @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] | 13135 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13136 | * 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] | 13137 | */ |
| 13138 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13139 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13140 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13141 | } |
| 13142 | |
| 13143 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13144 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13145 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13146 | * @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] | 13147 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13148 | * 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] | 13149 | * |
| 13150 | * @throws SecurityException if the caller doesn't have required permission. |
| 13151 | */ |
| 13152 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13153 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13154 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13155 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13156 | } |
| 13157 | |
| 13158 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13159 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13160 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13161 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13162 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13163 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13164 | * @param resultCallback The callback to get the result of the request. |
| 13165 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13166 | * |
| 13167 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13168 | */ |
| 13169 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13170 | public void startSatelliteTransmissionUpdates(int subId, |
| 13171 | @NonNull IIntegerConsumer resultCallback, |
| 13172 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13173 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13174 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13175 | } |
| 13176 | |
| 13177 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13178 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13179 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13180 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13181 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13182 | * @param resultCallback The callback to get the result of the request. |
| 13183 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13184 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
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. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13187 | */ |
| 13188 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13189 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13190 | @NonNull IIntegerConsumer resultCallback, |
| 13191 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13192 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13193 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13194 | } |
| 13195 | |
| 13196 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13197 | * Register the subscription with a satellite provider. |
| 13198 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13199 | * |
| 13200 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13201 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13202 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13203 | * @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] | 13204 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13205 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13206 | * @return The signal transport used by the caller to cancel the provision request, |
| 13207 | * or {@code null} if the request failed. |
| 13208 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13209 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13210 | */ |
| 13211 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13212 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13213 | @NonNull String token, @NonNull byte[] provisionData, |
| 13214 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13215 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13216 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13217 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13218 | } |
| 13219 | |
| 13220 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13221 | * Unregister the device/subscription with the satellite provider. |
| 13222 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13223 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13224 | * should report as deprovisioned. |
| 13225 | * |
| 13226 | * @param subId The subId of the subscription to be deprovisioned. |
| 13227 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13228 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13229 | * |
| 13230 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13231 | */ |
| 13232 | @Override |
| 13233 | public void deprovisionSatelliteService(int subId, |
| 13234 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13235 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13236 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13237 | } |
| 13238 | |
| 13239 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13240 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13241 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13242 | * @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] | 13243 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13244 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13245 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13246 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13247 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13248 | */ |
| 13249 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13250 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13251 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13252 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13253 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13254 | } |
| 13255 | |
| 13256 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13257 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13258 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13259 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13260 | * @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] | 13261 | * @param callback The callback that was passed to |
| 13262 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13263 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13264 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13265 | */ |
| 13266 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13267 | public void unregisterForSatelliteProvisionStateChanged( |
| 13268 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13269 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13270 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13271 | } |
| 13272 | |
| 13273 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13274 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13275 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13276 | * @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] | 13277 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13278 | * satellite provider if the request is successful or an error code if the |
| 13279 | * request failed. |
| 13280 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13281 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13282 | */ |
| 13283 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13284 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13285 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13286 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13287 | } |
| 13288 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13289 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13290 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13291 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13292 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13293 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13294 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13295 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13296 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13297 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13298 | */ |
| 13299 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13300 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13301 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13302 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13303 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13304 | } |
| 13305 | |
| 13306 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13307 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13308 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13309 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13310 | * @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] | 13311 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13312 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13313 | * |
| 13314 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13315 | */ |
| 13316 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13317 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13318 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13319 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13320 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13321 | } |
| 13322 | |
| 13323 | /** |
| 13324 | * Register to receive incoming datagrams over satellite. |
| 13325 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13326 | * @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] | 13327 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13328 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13329 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13330 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13331 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13332 | */ |
| 13333 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13334 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13335 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13336 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13337 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | /** |
| 13341 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13342 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13343 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13344 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13345 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13346 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13347 | * |
| 13348 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13349 | */ |
| 13350 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13351 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13352 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13353 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13354 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13355 | } |
| 13356 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13357 | /** |
| 13358 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13359 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13360 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13361 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13362 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13363 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13364 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13365 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13366 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13367 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13368 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13369 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13370 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13371 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13372 | } |
| 13373 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13374 | /** |
| 13375 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13376 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13377 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13378 | * input to this method. Datagram received here will be passed down to modem without any |
| 13379 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13380 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13381 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13382 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13383 | * SOS_SMS or LOCATION_SHARING. |
| 13384 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13385 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13386 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13387 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13388 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13389 | * |
| 13390 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13391 | */ |
| 13392 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13393 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13394 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13395 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13396 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13397 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13398 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13399 | } |
| 13400 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13401 | /** |
| 13402 | * Request to get whether satellite communication is allowed for the current location. |
| 13403 | * |
| 13404 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13405 | * allowed for the current location for. |
| 13406 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13407 | * for the current location if the request is successful or an error code |
| 13408 | * if the request failed. |
| 13409 | * |
| 13410 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13411 | */ |
| 13412 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13413 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13414 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13415 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13416 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13417 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13418 | } |
| 13419 | |
| 13420 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13421 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13422 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13423 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13424 | * @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] | 13425 | * be visible if the request is successful or an error code if the request failed. |
| 13426 | * |
| 13427 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13428 | */ |
| 13429 | @Override |
| 13430 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13431 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13432 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13433 | } |
| 13434 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13435 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13436 | * Inform that Device is aligned to satellite for demo mode. |
| 13437 | * |
| 13438 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13439 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13440 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13441 | * |
| 13442 | * @throws SecurityException if the caller doesn't have required permission. |
| 13443 | */ |
| 13444 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13445 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13446 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13447 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13448 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13449 | } |
| 13450 | |
| 13451 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13452 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13453 | * by modem. |
| 13454 | * |
| 13455 | * @param subId The subId of the subscription to request for. |
| 13456 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13457 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13458 | * operation. |
| 13459 | * |
| 13460 | * @throws SecurityException if the caller doesn't have required permission. |
| 13461 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13462 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13463 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13464 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13465 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13466 | final long identity = Binder.clearCallingIdentity(); |
| 13467 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13468 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13469 | } finally { |
| 13470 | Binder.restoreCallingIdentity(identity); |
| 13471 | } |
| 13472 | } |
| 13473 | |
| 13474 | /** |
| 13475 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13476 | * by modem. |
| 13477 | * |
| 13478 | * @param subId The subId of the subscription to request for. |
| 13479 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13480 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13481 | * operation. |
| 13482 | * |
| 13483 | * @throws SecurityException if the caller doesn't have required permission. |
| 13484 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13485 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13486 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13487 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13488 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13489 | final long identity = Binder.clearCallingIdentity(); |
| 13490 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13491 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13492 | } finally { |
| 13493 | Binder.restoreCallingIdentity(identity); |
| 13494 | } |
| 13495 | } |
| 13496 | |
| 13497 | /** |
| 13498 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13499 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13500 | * |
| 13501 | * @param subId The subId of the subscription to request for. |
| 13502 | * |
| 13503 | * @return Integer array of reasons for disallowing satellite communication. |
| 13504 | * |
| 13505 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13506 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13507 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13508 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13509 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13510 | final long identity = Binder.clearCallingIdentity(); |
| 13511 | try { |
| 13512 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13513 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13514 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13515 | } finally { |
| 13516 | Binder.restoreCallingIdentity(identity); |
| 13517 | } |
| 13518 | } |
| 13519 | |
| 13520 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13521 | * Request to get the signal strength of the satellite connection. |
| 13522 | * |
| 13523 | * @param subId The subId of the subscription to request for. |
| 13524 | * @param result Result receiver to get the error code of the request and the current signal |
| 13525 | * strength of the satellite connection. |
| 13526 | * |
| 13527 | * @throws SecurityException if the caller doesn't have required permission. |
| 13528 | */ |
| 13529 | @Override |
| 13530 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13531 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13532 | final long identity = Binder.clearCallingIdentity(); |
| 13533 | try { |
| 13534 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13535 | } finally { |
| 13536 | Binder.restoreCallingIdentity(identity); |
| 13537 | } |
| 13538 | } |
| 13539 | |
| 13540 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13541 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13542 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13543 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13544 | * |
| 13545 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13546 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13547 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13548 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13549 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13550 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13551 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13552 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13553 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13554 | */ |
| 13555 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13556 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13557 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13558 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13559 | final long identity = Binder.clearCallingIdentity(); |
| 13560 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13561 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13562 | } finally { |
| 13563 | Binder.restoreCallingIdentity(identity); |
| 13564 | } |
| 13565 | } |
| 13566 | |
| 13567 | /** |
| 13568 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13569 | * If callback was not registered before, the request will be ignored. |
| 13570 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13571 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13572 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13573 | * @param callback The callback that was passed to |
| 13574 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13575 | * |
| 13576 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13577 | */ |
| 13578 | @Override |
| 13579 | public void unregisterForNtnSignalStrengthChanged( |
| 13580 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13581 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13582 | final long identity = Binder.clearCallingIdentity(); |
| 13583 | try { |
| 13584 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13585 | } finally { |
| 13586 | Binder.restoreCallingIdentity(identity); |
| 13587 | } |
| 13588 | } |
| 13589 | |
| 13590 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13591 | * Registers for satellite capabilities change event from the satellite service. |
| 13592 | * |
| 13593 | * @param subId The subId of the subscription to request for. |
| 13594 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13595 | * |
| 13596 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13597 | * |
| 13598 | * @throws SecurityException if the caller doesn't have required permission. |
| 13599 | */ |
| 13600 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13601 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13602 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13603 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13604 | final long identity = Binder.clearCallingIdentity(); |
| 13605 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13606 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13607 | } finally { |
| 13608 | Binder.restoreCallingIdentity(identity); |
| 13609 | } |
| 13610 | } |
| 13611 | |
| 13612 | /** |
| 13613 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13614 | * If callback was not registered before, the request will be ignored. |
| 13615 | * |
| 13616 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13617 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13618 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13619 | * |
| 13620 | * @throws SecurityException if the caller doesn't have required permission. |
| 13621 | */ |
| 13622 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13623 | public void unregisterForCapabilitiesChanged(int subId, |
| 13624 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13625 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13626 | final long identity = Binder.clearCallingIdentity(); |
| 13627 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13628 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13629 | } finally { |
| 13630 | Binder.restoreCallingIdentity(identity); |
| 13631 | } |
| 13632 | } |
| 13633 | |
| 13634 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13635 | * Registers for the satellite supported state changed. |
| 13636 | * |
| 13637 | * @param subId The subId of the subscription to register for supported state changed. |
| 13638 | * @param callback The callback to handle the satellite supported state changed event. |
| 13639 | * |
| 13640 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13641 | * |
| 13642 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13643 | */ |
| 13644 | @Override |
| 13645 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13646 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13647 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13648 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13649 | } |
| 13650 | |
| 13651 | /** |
| 13652 | * Unregisters for the satellite supported state changed. |
| 13653 | * If callback was not registered before, the request will be ignored. |
| 13654 | * |
| 13655 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13656 | * @param callback The callback that was passed to |
| 13657 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13658 | * |
| 13659 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13660 | */ |
| 13661 | @Override |
| 13662 | public void unregisterForSatelliteSupportedStateChanged( |
| 13663 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13664 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13665 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13666 | } |
| 13667 | |
| 13668 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13669 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13670 | * |
| 13671 | * @param servicePackageName The package name of the satellite vendor service. |
| 13672 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13673 | * {@code false} otherwise. |
| 13674 | */ |
| 13675 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13676 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13677 | TelephonyPermissions.enforceShellOnly( |
| 13678 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13680 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13681 | "setSatelliteServicePackageName"); |
| 13682 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13683 | } |
| 13684 | |
| 13685 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13686 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13687 | * |
| 13688 | * @param servicePackageName The package name of the satellite gateway service. |
| 13689 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13690 | * {@code false} otherwise. |
| 13691 | */ |
| 13692 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13693 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13694 | TelephonyPermissions.enforceShellOnly( |
| 13695 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13697 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13698 | "setSatelliteGatewayServicePackageName"); |
| 13699 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13700 | } |
| 13701 | |
| 13702 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13703 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13704 | * |
| 13705 | * @param packageName The package name of the satellite pointing UI app. |
| 13706 | * @param className The class name of the satellite pointing UI app. |
| 13707 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13708 | * {@code false} otherwise. |
| 13709 | */ |
| 13710 | public boolean setSatellitePointingUiClassName( |
| 13711 | @Nullable String packageName, @Nullable String className) { |
| 13712 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13713 | + ", className=" + className); |
| 13714 | TelephonyPermissions.enforceShellOnly( |
| 13715 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13717 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13718 | "setSatelliteGatewayServicePackageName"); |
| 13719 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13720 | } |
| 13721 | |
| 13722 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13723 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13724 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13725 | * listening mode. |
| 13726 | * |
| 13727 | * @param timeoutMillis The timeout duration in millisecond. |
| 13728 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13729 | */ |
| 13730 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13731 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13732 | TelephonyPermissions.enforceShellOnly( |
| 13733 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13735 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13736 | "setSatelliteListeningTimeoutDuration"); |
| 13737 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13738 | } |
| 13739 | |
| 13740 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13741 | * This API can be used by only CTS to override the timeout durations used by the |
| 13742 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13743 | * |
| 13744 | * @param timeoutMillis The timeout duration in millisecond. |
| 13745 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13746 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13747 | public boolean setDatagramControllerTimeoutDuration( |
| 13748 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13749 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13750 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13751 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13752 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13754 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13755 | "setDatagramControllerTimeoutDuration"); |
| 13756 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13757 | reset, timeoutType, timeoutMillis); |
| 13758 | } |
| 13759 | |
| 13760 | /** |
| 13761 | * This API can be used by only CTS to override the timeout durations used by the |
| 13762 | * SatelliteController module. |
| 13763 | * |
| 13764 | * @param timeoutMillis The timeout duration in millisecond. |
| 13765 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13766 | */ |
| 13767 | public boolean setSatelliteControllerTimeoutDuration( |
| 13768 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13769 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13770 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13771 | TelephonyPermissions.enforceShellOnly( |
| 13772 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13774 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13775 | "setSatelliteControllerTimeoutDuration"); |
| 13776 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13777 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13778 | } |
| 13779 | |
| 13780 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13781 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13782 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13783 | * |
| 13784 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13785 | * of the following values to enable the override: |
| 13786 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13787 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13788 | * To disable the override, use -1 for handoverType. |
| 13789 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13790 | * delaySeconds after the emergency call starts. |
| 13791 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13792 | */ |
| 13793 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13794 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13795 | TelephonyPermissions.enforceShellOnly( |
| 13796 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13798 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13799 | "setEmergencyCallToSatelliteHandoverType"); |
| 13800 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13801 | handoverType, delaySeconds); |
| 13802 | } |
| 13803 | |
| 13804 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13805 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13806 | * |
| 13807 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13808 | * otherwise. |
| 13809 | * @param isProvisioned The overriding provision status. |
| 13810 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13811 | */ |
| 13812 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13813 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13814 | + ", isProvisioned=" + isProvisioned); |
| 13815 | TelephonyPermissions.enforceShellOnly( |
| 13816 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13818 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13819 | "setOemEnabledSatelliteProvisionStatus"); |
| 13820 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13821 | } |
| 13822 | |
| 13823 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13824 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13825 | * |
| 13826 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13827 | */ |
| 13828 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13829 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13830 | long locationCountryCodeTimestampNanos) { |
| 13831 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13832 | + String.join(", ", currentNetworkCountryCodes) |
| 13833 | + ", locationCountryCode=" + locationCountryCode |
| 13834 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13835 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13836 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13837 | TelephonyPermissions.enforceShellOnly( |
| 13838 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13840 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13841 | "setCachedLocationCountryCode"); |
| 13842 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13843 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13844 | locationCountryCodeTimestampNanos); |
| 13845 | } |
| 13846 | |
| 13847 | /** |
| 13848 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13849 | * access controller. |
| 13850 | * |
| 13851 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13852 | * otherwise. |
| 13853 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13854 | */ |
| 13855 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13856 | String s2CellFile, long locationFreshDurationNanos, |
| 13857 | List<String> satelliteCountryCodes) { |
| 13858 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13859 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13860 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13861 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13862 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13863 | TelephonyPermissions.enforceShellOnly( |
| 13864 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13866 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13867 | "setSatelliteAccessControlOverlayConfigs"); |
| 13868 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13869 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13870 | } |
| 13871 | |
| 13872 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13873 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13874 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13875 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13876 | * |
| 13877 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13878 | * satellite modem or not. |
| 13879 | * |
| 13880 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13881 | */ |
| 13882 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13883 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13884 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13885 | + "disabled"); |
| 13886 | return false; |
| 13887 | } |
| 13888 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13889 | TelephonyPermissions.enforceShellOnly( |
| 13890 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13892 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13893 | "setShouldSendDatagramToModemInDemoMode"); |
| 13894 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13895 | shouldSendToModemInDemoMode); |
| 13896 | } |
| 13897 | |
| 13898 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13899 | * Sets the service defined in ComponentName to be bound. |
| 13900 | * |
| 13901 | * This should only be used for testing. |
| 13902 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13903 | * {@code false} otherwise. |
| 13904 | */ |
| 13905 | @Override |
| 13906 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13907 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13908 | |
| 13909 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13910 | "setDomainSelectionServiceOverride"); |
| 13911 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13912 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13913 | |
| 13914 | final long identity = Binder.clearCallingIdentity(); |
| 13915 | try { |
| 13916 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13917 | return DomainSelectionResolver.getInstance() |
| 13918 | .setDomainSelectionServiceOverride(componentName); |
| 13919 | } |
| 13920 | } finally { |
| 13921 | Binder.restoreCallingIdentity(identity); |
| 13922 | } |
| 13923 | return false; |
| 13924 | } |
| 13925 | |
| 13926 | /** |
| 13927 | * Clears the DomainSelectionService override. |
| 13928 | * |
| 13929 | * This should only be used for testing. |
| 13930 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 13931 | * {@code false} otherwise. |
| 13932 | */ |
| 13933 | @Override |
| 13934 | public boolean clearDomainSelectionServiceOverride() { |
| 13935 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 13936 | |
| 13937 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13938 | "clearDomainSelectionServiceOverride"); |
| 13939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13940 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 13941 | |
| 13942 | final long identity = Binder.clearCallingIdentity(); |
| 13943 | try { |
| 13944 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13945 | return DomainSelectionResolver.getInstance() |
| 13946 | .clearDomainSelectionServiceOverride(); |
| 13947 | } |
| 13948 | } finally { |
| 13949 | Binder.restoreCallingIdentity(identity); |
| 13950 | } |
| 13951 | return false; |
| 13952 | } |
| 13953 | |
| 13954 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13955 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13956 | * |
| 13957 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13958 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13959 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13960 | * |
| 13961 | * @param enable if notifications about disclosure events should be enabled |
| 13962 | * @throws SecurityException if the caller does not have the required privileges |
| 13963 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13964 | */ |
| 13965 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13966 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13967 | enforceModifyPermission(); |
| 13968 | checkForIdentifierDisclosureNotificationSupport(); |
| 13969 | |
| 13970 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13971 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13972 | editor.apply(); |
| 13973 | |
| 13974 | // Each phone instance is responsible for updating its respective modem immediately |
| 13975 | // after we've made a preference change. |
| 13976 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13977 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13978 | } |
| 13979 | } |
| 13980 | |
| 13981 | /** |
| 13982 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13983 | * |
| 13984 | * @throws SecurityException if the caller does not have the required privileges |
| 13985 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13986 | */ |
| 13987 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13988 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13989 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13990 | checkForIdentifierDisclosureNotificationSupport(); |
| 13991 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13992 | } |
| 13993 | |
| 13994 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13995 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 13996 | * are in use by the cellular modem. |
| 13997 | * |
| 13998 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13999 | * @throws SecurityException if the caller does not have the required privileges |
| 14000 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14001 | * and integrity algorithms in use |
| 14002 | * @hide |
| 14003 | */ |
| 14004 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14005 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14006 | enforceModifyPermission(); |
| 14007 | checkForNullCipherNotificationSupport(); |
| 14008 | |
| 14009 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14010 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14011 | editor.apply(); |
| 14012 | |
| 14013 | // Each phone instance is responsible for updating its respective modem immediately |
| 14014 | // after a preference change. |
| 14015 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14016 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14017 | } |
| 14018 | } |
| 14019 | |
| 14020 | /** |
| 14021 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14022 | * cellular modem. |
| 14023 | * |
| 14024 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14025 | * @throws SecurityException if the caller does not have the required privileges |
| 14026 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14027 | * and integrity algorithms in use |
| 14028 | * @hide |
| 14029 | */ |
| 14030 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14031 | public boolean isNullCipherNotificationsEnabled() { |
| 14032 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14033 | checkForNullCipherNotificationSupport(); |
| 14034 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14035 | } |
| 14036 | |
| 14037 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14038 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14039 | * |
| 14040 | * <p>This method behaves in one of the following ways: |
| 14041 | * <ul> |
| 14042 | * <li>return true : if the calling package has the appop permission {@link |
| 14043 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14044 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14045 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14046 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14047 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14048 | * </ul> |
| 14049 | */ |
| 14050 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14051 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14052 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14053 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14054 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14055 | return true; |
| 14056 | } |
| 14057 | } |
| 14058 | return false; |
| 14059 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14060 | |
| 14061 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14062 | * @return The subscription manager service instance. |
| 14063 | */ |
| 14064 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14065 | return SubscriptionManagerService.getInstance(); |
| 14066 | } |
| 14067 | |
| 14068 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14069 | * Class binds the consumer[callback] and carrierId. |
| 14070 | */ |
| 14071 | private static class CallerCallbackInfo { |
| 14072 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14073 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14074 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14075 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14076 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14077 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14078 | } |
| 14079 | |
| 14080 | public Consumer<Integer> getConsumer() { |
| 14081 | return mConsumer; |
| 14082 | } |
| 14083 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14084 | public Set<Integer> getCarrierIds() { |
| 14085 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14086 | } |
| 14087 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14088 | |
| 14089 | /* |
| 14090 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14091 | * But the context that is passed in is unused if the phone app is already alive. |
| 14092 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14093 | */ |
| 14094 | @VisibleForTesting |
| 14095 | public void setPackageManager(PackageManager packageManager) { |
| 14096 | mPackageManager = packageManager; |
| 14097 | } |
| 14098 | |
| 14099 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14100 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14101 | * But the context that is passed in is unused if the phone app is already alive. |
| 14102 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14103 | */ |
| 14104 | @VisibleForTesting |
| 14105 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14106 | mAppOps = appOps; |
| 14107 | } |
| 14108 | |
| 14109 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14110 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14111 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14112 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14113 | */ |
| 14114 | @VisibleForTesting |
| 14115 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14116 | mFeatureFlags = featureFlags; |
| 14117 | } |
| 14118 | |
| 14119 | /** |
| 14120 | * Make sure the device has required telephony feature |
| 14121 | * |
| 14122 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14123 | */ |
| 14124 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14125 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14126 | if (callingPackage == null || mPackageManager == null) { |
| 14127 | return; |
| 14128 | } |
| 14129 | |
| 14130 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14131 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14132 | Binder.getCallingUserHandle()) |
| 14133 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14134 | // Skip to check associated telephony feature, |
| 14135 | // if compatibility change is not enabled for the current process or |
| 14136 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14137 | return; |
| 14138 | } |
| 14139 | |
| 14140 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14141 | throw new UnsupportedOperationException( |
| 14142 | methodName + " is unsupported without " + telephonyFeature); |
| 14143 | } |
| 14144 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14145 | |
| 14146 | /** |
| 14147 | * Registers for the satellite communication allowed state changed. |
| 14148 | * |
| 14149 | * @param subId The subId of the subscription to register for the satellite communication |
| 14150 | * allowed state changed. |
| 14151 | * @param callback The callback to handle the satellite communication allowed |
| 14152 | * state changed event. |
| 14153 | * |
| 14154 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14155 | * |
| 14156 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14157 | */ |
| 14158 | @Override |
| 14159 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14160 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14161 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
| 14162 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14163 | subId, callback); |
| 14164 | } |
| 14165 | |
| 14166 | /** |
| 14167 | * Unregisters for the satellite communication allowed state changed. |
| 14168 | * If callback was not registered before, the request will be ignored. |
| 14169 | * |
| 14170 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14171 | * allowed state changed. |
| 14172 | * @param callback The callback that was passed to |
| 14173 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14174 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14175 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14176 | */ |
| 14177 | @Override |
| 14178 | public void unregisterForCommunicationAllowedStateChanged( |
| 14179 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14180 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
| 14181 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback); |
| 14182 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14183 | } |