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; |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 168 | import android.telephony.satellite.ProvisionSubscriberId; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 173 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 176 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 178 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 180 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 181 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 182 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 183 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 198 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 215 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 222 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 229 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 230 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 231 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 235 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 236 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.IccIoResult; |
| 239 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 247 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 248 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 249 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 250 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 251 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 252 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 253 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 254 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 255 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 256 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 257 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 258 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 259 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 260 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 261 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 262 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 263 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 264 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 265 | import com.android.services.telephony.TelecomAccountRegistry; |
| 266 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 267 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 268 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 269 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 270 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 271 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.io.IOException; |
| 273 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 274 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 276 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 277 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 278 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 279 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 280 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 281 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 282 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 284 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 285 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 286 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 287 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 288 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 289 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 290 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Implementation of the ITelephony interface. |
| 294 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 295 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 297 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 298 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 299 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | |
| 301 | // Message codes used with mMainThreadHandler |
| 302 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 303 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 304 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 305 | private static final int CMD_OPEN_CHANNEL = 9; |
| 306 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 307 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 308 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 309 | private static final int CMD_NV_READ_ITEM = 13; |
| 310 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 311 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 312 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 313 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 314 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 315 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 316 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 317 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 318 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 319 | private static final int CMD_SEND_ENVELOPE = 25; |
| 320 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 321 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 322 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 323 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 324 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 326 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 327 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 328 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 329 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 330 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 331 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 332 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 333 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 334 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 335 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 336 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 337 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 338 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 339 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 341 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 342 | private static final int CMD_SWITCH_SLOTS = 50; |
| 343 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 345 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 346 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 347 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 348 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 349 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 350 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 351 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 352 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 353 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 354 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 355 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 356 | private static final int CMD_MODEM_REBOOT = 64; |
| 357 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 358 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 359 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 360 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 361 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 362 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 363 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 364 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 365 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 366 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 367 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 368 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 369 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 370 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 371 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 372 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 373 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 374 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 375 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 376 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 377 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 378 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 379 | private static final int CMD_GET_CALL_WAITING = 87; |
| 380 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 381 | private static final int CMD_SET_CALL_WAITING = 89; |
| 382 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 383 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 384 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 385 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 386 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 387 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 388 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 389 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 390 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 391 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 392 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 393 | private static final int CMD_SET_SIM_POWER = 101; |
| 394 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 395 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 396 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 397 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 398 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 399 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 400 | 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] | 401 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 402 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 403 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 404 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 405 | private static final int CMD_ENABLE_VONR = 113; |
| 406 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 407 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 408 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 409 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 410 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 411 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 412 | // Parameters of select command. |
| 413 | private static final int SELECT_COMMAND = 0xA4; |
| 414 | private static final int SELECT_P1 = 0x04; |
| 415 | private static final int SELECT_P2 = 0; |
| 416 | private static final int SELECT_P3 = 0x10; |
| 417 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 418 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 419 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 420 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 421 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 422 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 423 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 424 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | /** The singleton instance. */ |
| 426 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 427 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 430 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 431 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 432 | private final CallManager mCM; |
| 433 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 434 | |
| 435 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 436 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 438 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 439 | private final SharedPreferences mTelephonySharedPreferences; |
| 440 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 441 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 442 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 443 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 444 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 446 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 447 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 448 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 449 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 450 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 451 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 452 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 453 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 454 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 455 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 456 | // String to store multi SIM allowed |
| 457 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 458 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 459 | // The AID of ISD-R. |
| 460 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 461 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 462 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 463 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 464 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 465 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 466 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 467 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 468 | 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] | 469 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 470 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 471 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 472 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 473 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 474 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 475 | */ |
| 476 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 477 | "reset_network_erase_modem_config_enabled"; |
| 478 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 479 | 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] | 480 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 481 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 482 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame^] | 483 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 484 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 485 | /** |
| 486 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 487 | * one ICCID active at the same time. |
| 488 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 489 | * |
| 490 | * @hide |
| 491 | */ |
| 492 | @ChangeId |
| 493 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 494 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 495 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 496 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 497 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 498 | * operation fails. |
| 499 | */ |
| 500 | @ChangeId |
| 501 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 502 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 503 | |
| 504 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | * A request object to use for transmitting data to an ICC. |
| 506 | */ |
| 507 | private static final class IccAPDUArgument { |
| 508 | public int channel, cla, command, p1, p2, p3; |
| 509 | public String data; |
| 510 | |
| 511 | public IccAPDUArgument(int channel, int cla, int command, |
| 512 | int p1, int p2, int p3, String data) { |
| 513 | this.channel = channel; |
| 514 | this.cla = cla; |
| 515 | this.command = command; |
| 516 | this.p1 = p1; |
| 517 | this.p2 = p2; |
| 518 | this.p3 = p3; |
| 519 | this.data = data; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 524 | * A request object to use for transmitting data to an ICC. |
| 525 | */ |
| 526 | private static final class ManualNetworkSelectionArgument { |
| 527 | public OperatorInfo operatorInfo; |
| 528 | public boolean persistSelection; |
| 529 | |
| 530 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 531 | this.operatorInfo = operatorInfo; |
| 532 | this.persistSelection = persistSelection; |
| 533 | } |
| 534 | } |
| 535 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 536 | private static final class PurchasePremiumCapabilityArgument { |
| 537 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 538 | public @NonNull IIntegerConsumer callback; |
| 539 | |
| 540 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 541 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 542 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 543 | this.callback = callback; |
| 544 | } |
| 545 | } |
| 546 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 547 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 548 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 549 | * request after sending. The main thread will notify the request when it is complete. |
| 550 | */ |
| 551 | private static final class MainThreadRequest { |
| 552 | /** The argument to use for the request */ |
| 553 | public Object argument; |
| 554 | /** The result of the request that is run on the main thread */ |
| 555 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 556 | // The subscriber id that this request applies to. Defaults to |
| 557 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 558 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 559 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 560 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 561 | public Phone phone; |
| 562 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 563 | public WorkSource workSource; |
| 564 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 | public MainThreadRequest(Object argument) { |
| 566 | this.argument = argument; |
| 567 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 568 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 569 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 570 | this.argument = argument; |
| 571 | if (phone != null) { |
| 572 | this.phone = phone; |
| 573 | } |
| 574 | this.workSource = workSource; |
| 575 | } |
| 576 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 577 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 578 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 579 | if (subId != null) { |
| 580 | this.subId = subId; |
| 581 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 582 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 586 | private static final class IncomingThirdPartyCallArgs { |
| 587 | public final ComponentName component; |
| 588 | public final String callId; |
| 589 | public final String callerDisplayName; |
| 590 | |
| 591 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 592 | String callerDisplayName) { |
| 593 | this.component = component; |
| 594 | this.callId = callId; |
| 595 | this.callerDisplayName = callerDisplayName; |
| 596 | } |
| 597 | } |
| 598 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 599 | /** |
| 600 | * A handler that processes messages on the main thread in the phone process. Since many |
| 601 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 602 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 603 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 604 | * on, which will be notified when the operation completes and will contain the result of the |
| 605 | * request. |
| 606 | * |
| 607 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 608 | * note that request.result must be set to something non-null for the calling thread to |
| 609 | * unblock. |
| 610 | */ |
| 611 | private final class MainThreadHandler extends Handler { |
| 612 | @Override |
| 613 | public void handleMessage(Message msg) { |
| 614 | MainThreadRequest request; |
| 615 | Message onCompleted; |
| 616 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 617 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 619 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 620 | |
| 621 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | case CMD_HANDLE_USSD_REQUEST: { |
| 623 | request = (MainThreadRequest) msg.obj; |
| 624 | final Phone phone = getPhoneFromRequest(request); |
| 625 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 626 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 628 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | if (!isUssdApiAllowed(request.subId)) { |
| 630 | // Carrier does not support use of this API, return failure. |
| 631 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 632 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 633 | Bundle returnData = new Bundle(); |
| 634 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 635 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 636 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | request.result = true; |
| 638 | notifyRequester(request); |
| 639 | return; |
| 640 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 641 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | try { |
| 643 | request.result = phone != null |
| 644 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 645 | } catch (CallStateException cse) { |
| 646 | request.result = false; |
| 647 | } |
| 648 | // Wake up the requesting thread |
| 649 | notifyRequester(request); |
| 650 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 653 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 654 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 655 | final Phone phone = getPhoneFromRequest(request); |
| 656 | request.result = phone != null ? |
| 657 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 658 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 659 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 660 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 662 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 663 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 667 | uiccPort = getUiccPortFromRequest(request); |
| 668 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 670 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 674 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 675 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 676 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 677 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 678 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | break; |
| 681 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | ar = (AsyncResult) msg.obj; |
| 684 | request = (MainThreadRequest) ar.userObj; |
| 685 | if (ar.exception == null && ar.result != null) { |
| 686 | request.result = ar.result; |
| 687 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 688 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | if (ar.result == null) { |
| 690 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 693 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } else { |
| 695 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 696 | } |
| 697 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 698 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | break; |
| 700 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 702 | request = (MainThreadRequest) msg.obj; |
| 703 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 704 | uiccPort = getUiccPortFromRequest(request); |
| 705 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 707 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | } else { |
| 710 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 711 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 712 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 713 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 714 | iccArgument.p2, |
| 715 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | } |
| 717 | break; |
| 718 | |
| 719 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 720 | ar = (AsyncResult) msg.obj; |
| 721 | request = (MainThreadRequest) ar.userObj; |
| 722 | if (ar.exception == null && ar.result != null) { |
| 723 | request.result = ar.result; |
| 724 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 725 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 726 | if (ar.result == null) { |
| 727 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 728 | } else if (ar.exception instanceof CommandException) { |
| 729 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 730 | ar.exception); |
| 731 | } else { |
| 732 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 733 | } |
| 734 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case CMD_EXCHANGE_SIM_IO: |
| 739 | request = (MainThreadRequest) msg.obj; |
| 740 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 741 | uiccPort = getUiccPortFromRequest(request); |
| 742 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 744 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 746 | } else { |
| 747 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 748 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 749 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 750 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 751 | iccArgument.data, onCompleted); |
| 752 | } |
| 753 | break; |
| 754 | |
| 755 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 756 | ar = (AsyncResult) msg.obj; |
| 757 | request = (MainThreadRequest) ar.userObj; |
| 758 | if (ar.exception == null && ar.result != null) { |
| 759 | request.result = ar.result; |
| 760 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 761 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 762 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 764 | break; |
| 765 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 766 | case CMD_SEND_ENVELOPE: |
| 767 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 768 | uiccPort = getUiccPortFromRequest(request); |
| 769 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 771 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 772 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | } else { |
| 774 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 775 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 776 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 777 | break; |
| 778 | |
| 779 | case EVENT_SEND_ENVELOPE_DONE: |
| 780 | ar = (AsyncResult) msg.obj; |
| 781 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 782 | if (ar.exception == null && ar.result != null) { |
| 783 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 784 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 785 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 786 | if (ar.result == null) { |
| 787 | loge("sendEnvelopeWithStatus: Empty response"); |
| 788 | } else if (ar.exception instanceof CommandException) { |
| 789 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 790 | ar.exception); |
| 791 | } else { |
| 792 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 793 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 794 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 795 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 796 | break; |
| 797 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | case CMD_OPEN_CHANNEL: |
| 799 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 800 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 801 | IccLogicalChannelRequest openChannelRequest = |
| 802 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 803 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 804 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 805 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 806 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 807 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 808 | } else { |
| 809 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 810 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 811 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 812 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | case EVENT_OPEN_CHANNEL_DONE: |
| 816 | ar = (AsyncResult) msg.obj; |
| 817 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 818 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 820 | int[] result = (int[]) ar.result; |
| 821 | int channelId = result[0]; |
| 822 | byte[] selectResponse = null; |
| 823 | if (result.length > 1) { |
| 824 | selectResponse = new byte[result.length - 1]; |
| 825 | for (int i = 1; i < result.length; ++i) { |
| 826 | selectResponse[i - 1] = (byte) result[i]; |
| 827 | } |
| 828 | } |
| 829 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 830 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 831 | |
| 832 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 833 | if (uiccPort == null) { |
| 834 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 835 | } else { |
| 836 | IccLogicalChannelRequest channelRequest = |
| 837 | (IccLogicalChannelRequest) request.argument; |
| 838 | channelRequest.channel = channelId; |
| 839 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 840 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 842 | if (ar.result == null) { |
| 843 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 844 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 845 | if (ar.exception != null) { |
| 846 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 847 | } |
| 848 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 849 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 850 | if (ar.exception instanceof CommandException) { |
| 851 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 852 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 853 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 854 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 855 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 856 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 860 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 861 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 862 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 863 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case CMD_CLOSE_CHANNEL: |
| 867 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 868 | uiccPort = getUiccPortFromRequest(request); |
| 869 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 870 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 871 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 872 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 873 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 874 | } else { |
| 875 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 876 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 877 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 881 | ar = (AsyncResult) msg.obj; |
| 882 | request = (MainThreadRequest) ar.userObj; |
| 883 | if (ar.exception == null) { |
| 884 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 885 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 886 | if (uiccPort == null) { |
| 887 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 888 | } else { |
| 889 | final int channelId = (Integer) request.argument; |
| 890 | uiccPort.onLogicalChannelClosed(channelId); |
| 891 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 892 | } else { |
| 893 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 894 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 895 | if (ar.exception instanceof CommandException) { |
| 896 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 897 | CommandException.Error error = |
| 898 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 899 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 900 | // should only throw exceptions from the binder threads. |
| 901 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 902 | "iccCloseLogicalChannel: invalid argument "); |
| 903 | } |
| 904 | } else { |
| 905 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 906 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 907 | request.result = (exception != null) ? exception : |
| 908 | new IllegalStateException( |
| 909 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 910 | } |
| 911 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case CMD_NV_READ_ITEM: |
| 915 | request = (MainThreadRequest) msg.obj; |
| 916 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 917 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 918 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 922 | ar = (AsyncResult) msg.obj; |
| 923 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 924 | if (ar.exception == null && ar.result != null) { |
| 925 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 926 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | request.result = ""; |
| 928 | if (ar.result == null) { |
| 929 | loge("nvReadItem: Empty response"); |
| 930 | } else if (ar.exception instanceof CommandException) { |
| 931 | loge("nvReadItem: CommandException: " + |
| 932 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 933 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 937 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 938 | break; |
| 939 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 940 | case CMD_NV_WRITE_ITEM: |
| 941 | request = (MainThreadRequest) msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 943 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 944 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 945 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 946 | break; |
| 947 | |
| 948 | case EVENT_NV_WRITE_ITEM_DONE: |
| 949 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 950 | break; |
| 951 | |
| 952 | case CMD_NV_WRITE_CDMA_PRL: |
| 953 | request = (MainThreadRequest) msg.obj; |
| 954 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 955 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 956 | break; |
| 957 | |
| 958 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 959 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 960 | break; |
| 961 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 962 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 963 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 964 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 965 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 966 | break; |
| 967 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 968 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 969 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 970 | break; |
| 971 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 972 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 973 | request = (MainThreadRequest) msg.obj; |
| 974 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 975 | request); |
| 976 | Phone phone = getPhoneFromRequest(request); |
| 977 | if (phone != null) { |
| 978 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 979 | } else { |
| 980 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 981 | request.result = false; |
| 982 | notifyRequester(request); |
| 983 | } |
| 984 | break; |
| 985 | } |
| 986 | |
| 987 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 988 | ar = (AsyncResult) msg.obj; |
| 989 | request = (MainThreadRequest) ar.userObj; |
| 990 | if (ar.exception == null && ar.result != null) { |
| 991 | request.result = ar.result; |
| 992 | } else { |
| 993 | // request.result must be set to something non-null |
| 994 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 995 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 996 | request.result = ar.result; |
| 997 | } else { |
| 998 | request.result = false; |
| 999 | } |
| 1000 | if (ar.result == null) { |
| 1001 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1002 | } else if (ar.exception instanceof CommandException) { |
| 1003 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1004 | + ar.exception); |
| 1005 | } else { |
| 1006 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1007 | } |
| 1008 | } |
| 1009 | notifyRequester(request); |
| 1010 | break; |
| 1011 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1012 | case CMD_IS_VONR_ENABLED: { |
| 1013 | request = (MainThreadRequest) msg.obj; |
| 1014 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1015 | request); |
| 1016 | Phone phone = getPhoneFromRequest(request); |
| 1017 | if (phone != null) { |
| 1018 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1019 | } else { |
| 1020 | loge("isVoNrEnabled: No phone object"); |
| 1021 | request.result = false; |
| 1022 | notifyRequester(request); |
| 1023 | } |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | if (ar.exception == null && ar.result != null) { |
| 1031 | request.result = ar.result; |
| 1032 | } else { |
| 1033 | // request.result must be set to something non-null |
| 1034 | // for the calling thread to unblock |
| 1035 | if (ar.result != null) { |
| 1036 | request.result = ar.result; |
| 1037 | } else { |
| 1038 | request.result = false; |
| 1039 | } |
| 1040 | if (ar.result == null) { |
| 1041 | loge("isVoNrEnabled: Empty response"); |
| 1042 | } else if (ar.exception instanceof CommandException) { |
| 1043 | loge("isVoNrEnabled: CommandException: " |
| 1044 | + ar.exception); |
| 1045 | } else { |
| 1046 | loge("isVoNrEnabled: Unknown exception"); |
| 1047 | } |
| 1048 | } |
| 1049 | notifyRequester(request); |
| 1050 | break; |
| 1051 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1052 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1053 | request = (MainThreadRequest) msg.obj; |
| 1054 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1055 | Phone phone = getPhoneFromRequest(request); |
| 1056 | if (phone != null) { |
| 1057 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1058 | request.workSource); |
| 1059 | } else { |
| 1060 | loge("enableNrDualConnectivity: No phone object"); |
| 1061 | request.result = |
| 1062 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1063 | notifyRequester(request); |
| 1064 | } |
| 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1069 | ar = (AsyncResult) msg.obj; |
| 1070 | request = (MainThreadRequest) ar.userObj; |
| 1071 | if (ar.exception == null) { |
| 1072 | request.result = |
| 1073 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1074 | } else { |
| 1075 | request.result = |
| 1076 | TelephonyManager |
| 1077 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1078 | if (ar.exception instanceof CommandException) { |
| 1079 | CommandException.Error error = |
| 1080 | ((CommandException) (ar.exception)).getCommandError(); |
| 1081 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1082 | request.result = |
| 1083 | TelephonyManager |
| 1084 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1085 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1086 | request.result = |
| 1087 | TelephonyManager |
| 1088 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1089 | } |
| 1090 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1091 | + ar.exception); |
| 1092 | } else { |
| 1093 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1094 | } |
| 1095 | } |
| 1096 | notifyRequester(request); |
| 1097 | break; |
| 1098 | } |
| 1099 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1100 | case CMD_ENABLE_VONR: { |
| 1101 | request = (MainThreadRequest) msg.obj; |
| 1102 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1103 | Phone phone = getPhoneFromRequest(request); |
| 1104 | if (phone != null) { |
| 1105 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1106 | request.workSource); |
| 1107 | } else { |
| 1108 | loge("setVoNrEnabled: No phone object"); |
| 1109 | request.result = |
| 1110 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1111 | notifyRequester(request); |
| 1112 | } |
| 1113 | break; |
| 1114 | } |
| 1115 | |
| 1116 | case EVENT_ENABLE_VONR_DONE: { |
| 1117 | ar = (AsyncResult) msg.obj; |
| 1118 | request = (MainThreadRequest) ar.userObj; |
| 1119 | if (ar.exception == null) { |
| 1120 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1121 | } else { |
| 1122 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1123 | if (ar.exception instanceof CommandException) { |
| 1124 | CommandException.Error error = |
| 1125 | ((CommandException) (ar.exception)).getCommandError(); |
| 1126 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1127 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1128 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1129 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1130 | } else { |
| 1131 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1132 | } |
| 1133 | loge("setVoNrEnabled" + ": CommandException: " |
| 1134 | + ar.exception); |
| 1135 | } else { |
| 1136 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1137 | } |
| 1138 | } |
| 1139 | notifyRequester(request); |
| 1140 | break; |
| 1141 | } |
| 1142 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1143 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1144 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1145 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1146 | request); |
| 1147 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1148 | break; |
| 1149 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1150 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1151 | ar = (AsyncResult) msg.obj; |
| 1152 | request = (MainThreadRequest) ar.userObj; |
| 1153 | if (ar.exception == null && ar.result != null) { |
| 1154 | request.result = ar.result; // Integer |
| 1155 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1156 | // request.result must be set to something non-null |
| 1157 | // for the calling thread to unblock |
| 1158 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1159 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1160 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1161 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1162 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1163 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1164 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1165 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1169 | break; |
| 1170 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1171 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1172 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1173 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1174 | request); |
| 1175 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1176 | (Pair<Integer, Long>) request.argument; |
| 1177 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1178 | reasonWithNetworkTypes.first, |
| 1179 | reasonWithNetworkTypes.second, |
| 1180 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1181 | break; |
| 1182 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1183 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1184 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1185 | break; |
| 1186 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1187 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1188 | request = (MainThreadRequest) msg.obj; |
| 1189 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1190 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1191 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1192 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1193 | break; |
| 1194 | |
| 1195 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1196 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1197 | break; |
| 1198 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1199 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1200 | request = (MainThreadRequest) msg.obj; |
| 1201 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1202 | request); |
| 1203 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1204 | break; |
| 1205 | |
| 1206 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1207 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1208 | break; |
| 1209 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1210 | case CMD_PERFORM_NETWORK_SCAN: |
| 1211 | request = (MainThreadRequest) msg.obj; |
| 1212 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1213 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1214 | break; |
| 1215 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | request = (MainThreadRequest) msg.obj; |
| 1218 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1220 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1221 | request.argument; |
| 1222 | int callForwardingReason = args.first; |
| 1223 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | } |
| 1226 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1227 | ar = (AsyncResult) msg.obj; |
| 1228 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1230 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1231 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1235 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1236 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1237 | // any service for voice call. |
| 1238 | if ((callForwardInfo.serviceClass |
| 1239 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1240 | callForwardingInfo = new CallForwardingInfo( |
| 1241 | callForwardInfo.status |
| 1242 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | callForwardInfo.reason, |
| 1244 | callForwardInfo.number, |
| 1245 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | break; |
| 1247 | } |
| 1248 | } |
| 1249 | // Didn't find a call forward info for voice call. |
| 1250 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1252 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } else { |
| 1256 | if (ar.result == null) { |
| 1257 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1258 | } |
| 1259 | if (ar.exception != null) { |
| 1260 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1261 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1262 | int errorCode = TelephonyManager |
| 1263 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | if (ar.exception instanceof CommandException) { |
| 1265 | CommandException.Error error = |
| 1266 | ((CommandException) (ar.exception)).getCommandError(); |
| 1267 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1268 | errorCode = TelephonyManager |
| 1269 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1271 | errorCode = TelephonyManager |
| 1272 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | } |
| 1274 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | request = (MainThreadRequest) msg.obj; |
| 1282 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1286 | request.argument).first; |
| 1287 | request.phone.setCallForwardingOption( |
| 1288 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1289 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | callForwardingInfoToSet.getReason(), |
| 1292 | callForwardingInfoToSet.getNumber(), |
| 1293 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1294 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | ar = (AsyncResult) msg.obj; |
| 1299 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | Consumer<Integer> callback = |
| 1301 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1302 | request.argument).second; |
| 1303 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1305 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1306 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | if (ar.exception instanceof CommandException) { |
| 1308 | CommandException.Error error = |
| 1309 | ((CommandException) (ar.exception)).getCommandError(); |
| 1310 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1311 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1312 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1314 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1315 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | callback.accept(errorCode); |
| 1319 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1320 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1326 | request = (MainThreadRequest) msg.obj; |
| 1327 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1328 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1329 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | ar = (AsyncResult) msg.obj; |
| 1334 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1335 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1336 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1338 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | // Service Class is a bit mask per 3gpp 27.007. |
| 1340 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1341 | if (callForwardResults.length > 1 |
| 1342 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1343 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1344 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1345 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1346 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1348 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | } |
| 1350 | } else { |
| 1351 | if (ar.result == null) { |
| 1352 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1353 | } |
| 1354 | if (ar.exception != null) { |
| 1355 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1356 | } |
| 1357 | if (ar.exception instanceof CommandException) { |
| 1358 | CommandException.Error error = |
| 1359 | ((CommandException) (ar.exception)).getCommandError(); |
| 1360 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1361 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1363 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1364 | callWaitingStatus = |
| 1365 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1369 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1370 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1371 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | request = (MainThreadRequest) msg.obj; |
| 1375 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1377 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1378 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1380 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1382 | ar = (AsyncResult) msg.obj; |
| 1383 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1384 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1385 | Consumer<Integer> callback = |
| 1386 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1387 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1388 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1389 | if (ar.exception instanceof CommandException) { |
| 1390 | CommandException.Error error = |
| 1391 | ((CommandException) (ar.exception)).getCommandError(); |
| 1392 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1393 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1394 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1395 | callback.accept( |
| 1396 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1397 | } else { |
| 1398 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1399 | } |
| 1400 | } else { |
| 1401 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1402 | } |
| 1403 | } else { |
| 1404 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1405 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1406 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1407 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1408 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1409 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
| 1412 | CellNetworkScanResult cellScanResult; |
| 1413 | if (ar.exception == null && ar.result != null) { |
| 1414 | cellScanResult = new CellNetworkScanResult( |
| 1415 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1416 | (List<OperatorInfo>) ar.result); |
| 1417 | } else { |
| 1418 | if (ar.result == null) { |
| 1419 | loge("getCellNetworkScanResults: Empty response"); |
| 1420 | } |
| 1421 | if (ar.exception != null) { |
| 1422 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1423 | } |
| 1424 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1425 | if (ar.exception instanceof CommandException) { |
| 1426 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1427 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1428 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1429 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1430 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1431 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1432 | } |
| 1433 | } |
| 1434 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1435 | } |
| 1436 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1437 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | |
| 1440 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1441 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1442 | ManualNetworkSelectionArgument selArg = |
| 1443 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1444 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1445 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1446 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1447 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | |
| 1450 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | if (ar.exception == null) { |
| 1454 | request.result = true; |
| 1455 | } else { |
| 1456 | request.result = false; |
| 1457 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1458 | } |
| 1459 | notifyRequester(request); |
| 1460 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1461 | break; |
| 1462 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1463 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1464 | request = (MainThreadRequest) msg.obj; |
| 1465 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1466 | if (defaultPhone != null) { |
| 1467 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1468 | } else { |
| 1469 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1470 | Bundle bundle = new Bundle(); |
| 1471 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1472 | new ModemActivityInfo(0, 0, 0, |
| 1473 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1474 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1475 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1478 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | ar = (AsyncResult) msg.obj; |
| 1480 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1481 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1482 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1483 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1484 | if (mLastModemActivityInfo == null) { |
| 1485 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1486 | mLastModemActivitySpecificInfo[0] = |
| 1487 | new ActivityStatsTechSpecificInfo( |
| 1488 | 0, |
| 1489 | 0, |
| 1490 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1491 | 0); |
| 1492 | mLastModemActivityInfo = |
| 1493 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1494 | } |
| 1495 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1496 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1497 | // Update the last modem activity info and the result of the request. |
| 1498 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1499 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1500 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1501 | } else { |
| 1502 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1503 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1504 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1505 | // We don't want to return mLastModemActivityInfo which is updated |
| 1506 | // inside mergeModemActivityInfo() |
| 1507 | ret = new ModemActivityInfo( |
| 1508 | mLastModemActivityInfo.getTimestampMillis(), |
| 1509 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1510 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1511 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1512 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1513 | } else { |
| 1514 | if (ar.result == null) { |
| 1515 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1516 | error = TelephonyManager.ModemActivityInfoException |
| 1517 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1518 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1519 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1520 | error = TelephonyManager.ModemActivityInfoException |
| 1521 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1522 | } else { |
| 1523 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1524 | error = TelephonyManager.ModemActivityInfoException |
| 1525 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1526 | } |
| 1527 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1528 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1529 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1530 | bundle.putParcelable( |
| 1531 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1532 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1533 | } else { |
| 1534 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1535 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1536 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1537 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1538 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1539 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1540 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1541 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1542 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1543 | CarrierRestrictionRules argument = |
| 1544 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1546 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1547 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1548 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | |
| 1550 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | if (ar.exception == null && ar.result != null) { |
| 1554 | request.result = ar.result; |
| 1555 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1556 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1557 | if (ar.exception instanceof CommandException) { |
| 1558 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1559 | CommandException.Error error = |
| 1560 | ((CommandException) (ar.exception)).getCommandError(); |
| 1561 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1562 | request.result = |
| 1563 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1564 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1565 | } else { |
| 1566 | loge("setAllowedCarriers: Unknown exception"); |
| 1567 | } |
| 1568 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1569 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1570 | break; |
| 1571 | |
| 1572 | case CMD_GET_ALLOWED_CARRIERS: |
| 1573 | request = (MainThreadRequest) msg.obj; |
| 1574 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1575 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1576 | break; |
| 1577 | |
| 1578 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1579 | ar = (AsyncResult) msg.obj; |
| 1580 | request = (MainThreadRequest) ar.userObj; |
| 1581 | if (ar.exception == null && ar.result != null) { |
| 1582 | request.result = ar.result; |
| 1583 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1584 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1585 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1586 | if (ar.result == null) { |
| 1587 | loge("getAllowedCarriers: Empty response"); |
| 1588 | } else if (ar.exception instanceof CommandException) { |
| 1589 | loge("getAllowedCarriers: CommandException: " + |
| 1590 | ar.exception); |
| 1591 | } else { |
| 1592 | loge("getAllowedCarriers: Unknown exception"); |
| 1593 | } |
| 1594 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1595 | if (request.argument != null) { |
| 1596 | // This is for the implementation of carrierRestrictionStatus. |
| 1597 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1598 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1599 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1600 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1601 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1602 | CarrierRestrictionRules carrierRestrictionRules = |
| 1603 | (CarrierRestrictionRules) ar.result; |
| 1604 | int carrierId = -1; |
| 1605 | try { |
| 1606 | CarrierIdentifier carrierIdentifier = |
| 1607 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1608 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1609 | carrierIdentifier); |
| 1610 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1611 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1612 | } |
| 1613 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1614 | int restrictedStatus = |
| 1615 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1616 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1617 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1618 | lockStatus = TelephonyManager |
| 1619 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } else { |
| 1622 | Rlog.e(LOG_TAG, |
| 1623 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1624 | } |
| 1625 | callback.accept(lockStatus); |
| 1626 | } else { |
| 1627 | // This is for the implementation of getAllowedCarriers. |
| 1628 | notifyRequester(request); |
| 1629 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1630 | break; |
| 1631 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1632 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1633 | ar = (AsyncResult) msg.obj; |
| 1634 | request = (MainThreadRequest) ar.userObj; |
| 1635 | if (ar.exception == null && ar.result != null) { |
| 1636 | request.result = ar.result; |
| 1637 | } else { |
| 1638 | request.result = new IllegalArgumentException( |
| 1639 | "Failed to retrieve Forbidden Plmns"); |
| 1640 | if (ar.result == null) { |
| 1641 | loge("getForbiddenPlmns: Empty response"); |
| 1642 | } else { |
| 1643 | loge("getForbiddenPlmns: Unknown exception"); |
| 1644 | } |
| 1645 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1646 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1647 | break; |
| 1648 | |
| 1649 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1650 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1651 | uiccPort = getUiccPortFromRequest(request); |
| 1652 | if (uiccPort == null) { |
| 1653 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1654 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1655 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1656 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1657 | break; |
| 1658 | } |
| 1659 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1660 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1661 | if (uiccApp == null) { |
| 1662 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1663 | + appType); |
| 1664 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1665 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1666 | break; |
| 1667 | } else { |
| 1668 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1669 | + " specified type -- " + appType); |
| 1670 | } |
| 1671 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1672 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1673 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1674 | break; |
| 1675 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1676 | case CMD_SWITCH_SLOTS: |
| 1677 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1678 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1679 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1680 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | |
| 1683 | case EVENT_SWITCH_SLOTS_DONE: |
| 1684 | ar = (AsyncResult) msg.obj; |
| 1685 | request = (MainThreadRequest) ar.userObj; |
| 1686 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1687 | notifyRequester(request); |
| 1688 | break; |
| 1689 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1690 | request = (MainThreadRequest) msg.obj; |
| 1691 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1692 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1693 | break; |
| 1694 | |
| 1695 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1696 | ar = (AsyncResult) msg.obj; |
| 1697 | request = (MainThreadRequest) ar.userObj; |
| 1698 | if (ar.exception != null) { |
| 1699 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1700 | } else { |
| 1701 | int mode = ((int[]) ar.result)[0]; |
| 1702 | if (mode == 0) { |
| 1703 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1704 | } else { |
| 1705 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1706 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1708 | notifyRequester(request); |
| 1709 | break; |
| 1710 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1711 | request = (MainThreadRequest) msg.obj; |
| 1712 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1713 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1714 | break; |
| 1715 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | if (ar.exception != null) { |
| 1719 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1720 | } else { |
| 1721 | request.result = ((int[]) ar.result)[0]; |
| 1722 | } |
| 1723 | notifyRequester(request); |
| 1724 | break; |
| 1725 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1726 | request = (MainThreadRequest) msg.obj; |
| 1727 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1728 | int mode = (int) request.argument; |
| 1729 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1730 | break; |
| 1731 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1732 | ar = (AsyncResult) msg.obj; |
| 1733 | request = (MainThreadRequest) ar.userObj; |
| 1734 | request.result = ar.exception == null; |
| 1735 | notifyRequester(request); |
| 1736 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1737 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1738 | request = (MainThreadRequest) msg.obj; |
| 1739 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1740 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1741 | break; |
| 1742 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1743 | ar = (AsyncResult) msg.obj; |
| 1744 | request = (MainThreadRequest) ar.userObj; |
| 1745 | if (ar.exception != null) { |
| 1746 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1747 | } else { |
| 1748 | request.result = ((int[]) ar.result)[0]; |
| 1749 | } |
| 1750 | notifyRequester(request); |
| 1751 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1752 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1753 | request = (MainThreadRequest) msg.obj; |
| 1754 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1755 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1756 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1757 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1758 | break; |
| 1759 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1760 | ar = (AsyncResult) msg.obj; |
| 1761 | request = (MainThreadRequest) ar.userObj; |
| 1762 | request.result = ar.exception == null; |
| 1763 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1764 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1765 | case CMD_GET_ALL_CELL_INFO: |
| 1766 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1767 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1768 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1769 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1770 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1771 | ar = (AsyncResult) msg.obj; |
| 1772 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1773 | // If a timeout occurs, the response will be null |
| 1774 | request.result = (ar.exception == null && ar.result != null) |
| 1775 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1776 | synchronized (request) { |
| 1777 | request.notifyAll(); |
| 1778 | } |
| 1779 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1780 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1781 | request = (MainThreadRequest) msg.obj; |
| 1782 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1783 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1784 | break; |
| 1785 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1786 | ar = (AsyncResult) msg.obj; |
| 1787 | request = (MainThreadRequest) ar.userObj; |
| 1788 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1789 | try { |
| 1790 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1791 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1792 | cb.onError( |
| 1793 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1794 | ar.exception.getClass().getName(), |
| 1795 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1796 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1797 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1798 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1799 | } else { |
| 1800 | // use the result as returned |
| 1801 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1802 | } |
| 1803 | } catch (RemoteException re) { |
| 1804 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1805 | } |
| 1806 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1807 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1808 | request = (MainThreadRequest) msg.obj; |
| 1809 | WorkSource ws = (WorkSource) request.argument; |
| 1810 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1811 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1812 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1813 | } |
| 1814 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1815 | ar = (AsyncResult) msg.obj; |
| 1816 | request = (MainThreadRequest) ar.userObj; |
| 1817 | if (ar.exception == null) { |
| 1818 | request.result = ar.result; |
| 1819 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1820 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1821 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1822 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | synchronized (request) { |
| 1826 | request.notifyAll(); |
| 1827 | } |
| 1828 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1829 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1830 | case CMD_MODEM_REBOOT: |
| 1831 | request = (MainThreadRequest) msg.obj; |
| 1832 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1833 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1834 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1835 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1836 | handleNullReturnEvent(msg, "rebootModem"); |
| 1837 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1838 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1839 | request = (MainThreadRequest) msg.obj; |
| 1840 | boolean enable = (boolean) request.argument; |
| 1841 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1842 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1843 | PhoneConfigurationManager.getInstance() |
| 1844 | .enablePhone(request.phone, enable, onCompleted); |
| 1845 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1846 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1847 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1848 | ar = (AsyncResult) msg.obj; |
| 1849 | request = (MainThreadRequest) ar.userObj; |
| 1850 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1851 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1852 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1853 | if ((boolean) request.result) { |
| 1854 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1855 | updateModemStateMetrics(); |
| 1856 | } else { |
| 1857 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1858 | + ar.exception); |
| 1859 | } |
| 1860 | notifyRequester(request); |
| 1861 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1862 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1863 | case CMD_GET_MODEM_STATUS: |
| 1864 | request = (MainThreadRequest) msg.obj; |
| 1865 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1866 | PhoneConfigurationManager.getInstance() |
| 1867 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1868 | break; |
| 1869 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1870 | ar = (AsyncResult) msg.obj; |
| 1871 | request = (MainThreadRequest) ar.userObj; |
| 1872 | int id = request.phone.getPhoneId(); |
| 1873 | if (ar.exception == null && ar.result != null) { |
| 1874 | request.result = ar.result; |
| 1875 | //update the cache as modem status has changed |
| 1876 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1877 | (boolean) request.result); |
| 1878 | } else { |
| 1879 | // Return true if modem status cannot be retrieved. For most cases, |
| 1880 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1881 | // and disable modem are not supported. Modem is always on. |
| 1882 | // TODO: this should be fixed in R to support a third |
| 1883 | // status UNKNOWN b/131631629 |
| 1884 | request.result = true; |
| 1885 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1886 | + ar.exception); |
| 1887 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1888 | notifyRequester(request); |
| 1889 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1890 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1891 | request = (MainThreadRequest) msg.obj; |
| 1892 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1893 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1894 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1895 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1896 | break; |
| 1897 | } |
| 1898 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1899 | ar = (AsyncResult) msg.obj; |
| 1900 | request = (MainThreadRequest) ar.userObj; |
| 1901 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1902 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1903 | args.second.accept(ar.exception == null); |
| 1904 | notifyRequester(request); |
| 1905 | break; |
| 1906 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1907 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1908 | request = (MainThreadRequest) msg.obj; |
| 1909 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1910 | Phone phone = getPhoneFromRequest(request); |
| 1911 | if (phone != null) { |
| 1912 | phone.getSystemSelectionChannels(onCompleted); |
| 1913 | } else { |
| 1914 | loge("getSystemSelectionChannels: No phone object"); |
| 1915 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1916 | notifyRequester(request); |
| 1917 | } |
| 1918 | break; |
| 1919 | } |
| 1920 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1921 | ar = (AsyncResult) msg.obj; |
| 1922 | request = (MainThreadRequest) ar.userObj; |
| 1923 | if (ar.exception == null && ar.result != null) { |
| 1924 | request.result = ar.result; |
| 1925 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1926 | request.result = new IllegalStateException( |
| 1927 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1928 | if (ar.result == null) { |
| 1929 | loge("getSystemSelectionChannels: Empty response"); |
| 1930 | } else { |
| 1931 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1932 | } |
| 1933 | } |
| 1934 | notifyRequester(request); |
| 1935 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1936 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1937 | ar = (AsyncResult) msg.obj; |
| 1938 | request = (MainThreadRequest) ar.userObj; |
| 1939 | if (ar.exception == null && ar.result != null) { |
| 1940 | request.result = ar.result; |
| 1941 | } else { |
| 1942 | request.result = -1; |
| 1943 | loge("Failed to set Forbidden Plmns"); |
| 1944 | if (ar.result == null) { |
| 1945 | loge("setForbidenPlmns: Empty response"); |
| 1946 | } else if (ar.exception != null) { |
| 1947 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1948 | request.result = -1; |
| 1949 | } else { |
| 1950 | loge("setForbiddenPlmns: Unknown exception"); |
| 1951 | } |
| 1952 | } |
| 1953 | notifyRequester(request); |
| 1954 | break; |
| 1955 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1956 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1957 | uiccPort = getUiccPortFromRequest(request); |
| 1958 | if (uiccPort == null) { |
| 1959 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1960 | request.result = -1; |
| 1961 | notifyRequester(request); |
| 1962 | break; |
| 1963 | } |
| 1964 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1965 | (Pair<Integer, List<String>>) request.argument; |
| 1966 | appType = setFplmnsArgs.first; |
| 1967 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1968 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1969 | if (uiccApp == null) { |
| 1970 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1971 | request.result = -1; |
| 1972 | loge("Failed to get UICC App"); |
| 1973 | notifyRequester(request); |
| 1974 | } else { |
| 1975 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1976 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1977 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1978 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1979 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1980 | case CMD_ERASE_MODEM_CONFIG: |
| 1981 | request = (MainThreadRequest) msg.obj; |
| 1982 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1983 | defaultPhone.eraseModemConfig(onCompleted); |
| 1984 | break; |
| 1985 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1986 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1987 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1988 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1989 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1992 | notifyRequester(request); |
| 1993 | break; |
| 1994 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1995 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1996 | request = (MainThreadRequest) msg.obj; |
| 1997 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1998 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1999 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2000 | changed.first, changed.second, onCompleted); |
| 2001 | break; |
| 2002 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2003 | ar = (AsyncResult) msg.obj; |
| 2004 | request = (MainThreadRequest) ar.userObj; |
| 2005 | if (ar.exception == null) { |
| 2006 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2007 | // If the operation is successful, update the PIN storage |
| 2008 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2009 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2010 | UiccController.getInstance().getPinStorage() |
| 2011 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2012 | } else { |
| 2013 | request.result = msg.arg1; |
| 2014 | } |
| 2015 | notifyRequester(request); |
| 2016 | break; |
| 2017 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2018 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2019 | request = (MainThreadRequest) msg.obj; |
| 2020 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2021 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2022 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2023 | enabled.first, enabled.second, onCompleted); |
| 2024 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2026 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2027 | ar = (AsyncResult) msg.obj; |
| 2028 | request = (MainThreadRequest) ar.userObj; |
| 2029 | if (ar.exception == null) { |
| 2030 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2031 | // If the operation is successful, update the PIN storage |
| 2032 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2033 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2034 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2035 | UiccController.getInstance().getPinStorage() |
| 2036 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2037 | } else { |
| 2038 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2039 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2040 | } else { |
| 2041 | request.result = msg.arg1; |
| 2042 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2043 | |
| 2044 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2045 | notifyRequester(request); |
| 2046 | break; |
| 2047 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2048 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2049 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2050 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2051 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2052 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2053 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2054 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2055 | |
| 2056 | case CMD_SET_DATA_THROTTLING: { |
| 2057 | request = (MainThreadRequest) msg.obj; |
| 2058 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2059 | DataThrottlingRequest dataThrottlingRequest = |
| 2060 | (DataThrottlingRequest) request.argument; |
| 2061 | Phone phone = getPhoneFromRequest(request); |
| 2062 | if (phone != null) { |
| 2063 | phone.setDataThrottling(onCompleted, |
| 2064 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2065 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2066 | } else { |
| 2067 | loge("setDataThrottling: No phone object"); |
| 2068 | request.result = |
| 2069 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2070 | notifyRequester(request); |
| 2071 | } |
| 2072 | |
| 2073 | break; |
| 2074 | } |
| 2075 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2076 | ar = (AsyncResult) msg.obj; |
| 2077 | request = (MainThreadRequest) ar.userObj; |
| 2078 | |
| 2079 | if (ar.exception == null) { |
| 2080 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2081 | } else if (ar.exception instanceof CommandException) { |
| 2082 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2083 | CommandException.Error error = |
| 2084 | ((CommandException) (ar.exception)).getCommandError(); |
| 2085 | |
| 2086 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2087 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2088 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2089 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2090 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2091 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2092 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2093 | } else { |
| 2094 | request.result = |
| 2095 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2096 | } |
| 2097 | } else { |
| 2098 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2099 | } |
| 2100 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2101 | notifyRequester(request); |
| 2102 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2103 | |
| 2104 | case CMD_SET_SIM_POWER: { |
| 2105 | request = (MainThreadRequest) msg.obj; |
| 2106 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2107 | request = (MainThreadRequest) msg.obj; |
| 2108 | int stateToSet = |
| 2109 | ((Pair<Integer, IIntegerConsumer>) |
| 2110 | request.argument).first; |
| 2111 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2112 | break; |
| 2113 | } |
| 2114 | case EVENT_SET_SIM_POWER_DONE: { |
| 2115 | ar = (AsyncResult) msg.obj; |
| 2116 | request = (MainThreadRequest) ar.userObj; |
| 2117 | IIntegerConsumer callback = |
| 2118 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2119 | if (ar.exception != null) { |
| 2120 | loge("setSimPower exception: " + ar.exception); |
| 2121 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2122 | .RESULT_ERROR_UNKNOWN; |
| 2123 | if (ar.exception instanceof CommandException) { |
| 2124 | CommandException.Error error = |
| 2125 | ((CommandException) (ar.exception)).getCommandError(); |
| 2126 | if (error == CommandException.Error.SIM_ERR) { |
| 2127 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2128 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2129 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2130 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2131 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2132 | } else { |
| 2133 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2134 | } |
| 2135 | } |
| 2136 | try { |
| 2137 | callback.accept(errorCode); |
| 2138 | } catch (RemoteException e) { |
| 2139 | // Ignore if the remote process is no longer available to call back. |
| 2140 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2141 | } |
| 2142 | } else { |
| 2143 | try { |
| 2144 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2145 | } catch (RemoteException e) { |
| 2146 | // Ignore if the remote process is no longer available to call back. |
| 2147 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2148 | } |
| 2149 | } |
| 2150 | break; |
| 2151 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2152 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2153 | request = (MainThreadRequest) msg.obj; |
| 2154 | |
| 2155 | final Phone phone = getPhoneFromRequest(request); |
| 2156 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2157 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2158 | notifyRequester(request); |
| 2159 | break; |
| 2160 | } |
| 2161 | |
| 2162 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2163 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2164 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2165 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2166 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2167 | request.subId, pair.first /*callingUid*/, |
| 2168 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2169 | break; |
| 2170 | } |
| 2171 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2172 | ar = (AsyncResult) msg.obj; |
| 2173 | request = (MainThreadRequest) ar.userObj; |
| 2174 | // request.result will be the exception of ar if present, true otherwise. |
| 2175 | // Be cautious not to leave result null which will wait() forever |
| 2176 | request.result = ar.exception != null ? ar.exception : true; |
| 2177 | notifyRequester(request); |
| 2178 | break; |
| 2179 | } |
| 2180 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2181 | request = (MainThreadRequest) msg.obj; |
| 2182 | |
| 2183 | Phone phone = getPhoneFromRequest(request); |
| 2184 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2185 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2186 | notifyRequester(request); |
| 2187 | break; |
| 2188 | } |
| 2189 | |
| 2190 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2191 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2192 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2193 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2194 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2195 | request.subId, pair.first /*callingUid*/, |
| 2196 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2197 | break; |
| 2198 | } |
| 2199 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2200 | ar = (AsyncResult) msg.obj; |
| 2201 | request = (MainThreadRequest) ar.userObj; |
| 2202 | request.result = ar.exception != null ? ar.exception : true; |
| 2203 | notifyRequester(request); |
| 2204 | break; |
| 2205 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2206 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | case CMD_GET_SLICING_CONFIG: { |
| 2208 | request = (MainThreadRequest) msg.obj; |
| 2209 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2210 | request.phone.getSlicingConfig(onCompleted); |
| 2211 | break; |
| 2212 | } |
| 2213 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2214 | ar = (AsyncResult) msg.obj; |
| 2215 | request = (MainThreadRequest) ar.userObj; |
| 2216 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2217 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2218 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2219 | Bundle bundle = new Bundle(); |
| 2220 | int resultCode = 0; |
| 2221 | if (ar.exception != null) { |
| 2222 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2223 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2224 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2225 | } else if (ar.result == null) { |
| 2226 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2227 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2228 | } else { |
| 2229 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2230 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2231 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2235 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2236 | } |
| 2237 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2238 | result.send(resultCode, bundle); |
| 2239 | notifyRequester(request); |
| 2240 | break; |
| 2241 | } |
| 2242 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2243 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2244 | request = (MainThreadRequest) msg.obj; |
| 2245 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2246 | PurchasePremiumCapabilityArgument arg = |
| 2247 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2248 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2249 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2251 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2253 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2254 | ar = (AsyncResult) msg.obj; |
| 2255 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | PurchasePremiumCapabilityArgument arg = |
| 2257 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2258 | try { |
| 2259 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2260 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2262 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2263 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2264 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2265 | } catch (RemoteException e) { |
| 2266 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2267 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2268 | + " failed: " + e; |
| 2269 | if (DBG) log(logStr); |
| 2270 | AnomalyReporter.reportAnomaly( |
| 2271 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2272 | } |
| 2273 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2274 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2275 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2276 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2277 | request = (MainThreadRequest) msg.obj; |
| 2278 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2279 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2280 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2281 | notifyRequester(request); |
| 2282 | break; |
| 2283 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | default: |
| 2285 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2286 | break; |
| 2287 | } |
| 2288 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2289 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2290 | private void notifyRequester(MainThreadRequest request) { |
| 2291 | synchronized (request) { |
| 2292 | request.notifyAll(); |
| 2293 | } |
| 2294 | } |
| 2295 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2296 | private void handleNullReturnEvent(Message msg, String command) { |
| 2297 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2298 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2299 | if (ar.exception == null) { |
| 2300 | request.result = true; |
| 2301 | } else { |
| 2302 | request.result = false; |
| 2303 | if (ar.exception instanceof CommandException) { |
| 2304 | loge(command + ": CommandException: " + ar.exception); |
| 2305 | } else { |
| 2306 | loge(command + ": Unknown exception"); |
| 2307 | } |
| 2308 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2309 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2310 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * Posts the specified command to be executed on the main thread, |
| 2315 | * waits for the request to complete, and returns the result. |
| 2316 | * @see #sendRequestAsync |
| 2317 | */ |
| 2318 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2319 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2320 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | /** |
| 2324 | * Posts the specified command to be executed on the main thread, |
| 2325 | * waits for the request to complete, and returns the result. |
| 2326 | * @see #sendRequestAsync |
| 2327 | */ |
| 2328 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2329 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2330 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Posts the specified command to be executed on the main thread, |
| 2335 | * waits for the request to complete, and returns the result. |
| 2336 | * @see #sendRequestAsync |
| 2337 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2338 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2339 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * Posts the specified command to be executed on the main thread, |
| 2344 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2345 | * if not timeout or null otherwise. |
| 2346 | * @see #sendRequestAsync |
| 2347 | */ |
| 2348 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2349 | long timeoutInMs) { |
| 2350 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | /** |
| 2354 | * Posts the specified command to be executed on the main thread, |
| 2355 | * waits for the request to complete, and returns the result. |
| 2356 | * @see #sendRequestAsync |
| 2357 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2358 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2359 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * Posts the specified command to be executed on the main thread, |
| 2364 | * waits for the request to complete, and returns the result. |
| 2365 | * @see #sendRequestAsync |
| 2366 | */ |
| 2367 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2368 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2369 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2373 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2374 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2375 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2376 | * @see #sendRequestAsync |
| 2377 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2378 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2379 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2381 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2382 | } |
| 2383 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2384 | MainThreadRequest request = null; |
| 2385 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2386 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2387 | } else if (phone != null) { |
| 2388 | request = new MainThreadRequest(argument, phone, workSource); |
| 2389 | } else { |
| 2390 | request = new MainThreadRequest(argument, subId, workSource); |
| 2391 | } |
| 2392 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2394 | msg.sendToTarget(); |
| 2395 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2398 | if (timeoutInMs >= 0) { |
| 2399 | // Wait for at least timeoutInMs before returning null request result |
| 2400 | long now = SystemClock.elapsedRealtime(); |
| 2401 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2402 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2403 | try { |
| 2404 | request.wait(deadline - now); |
| 2405 | } catch (InterruptedException e) { |
| 2406 | // Do nothing, go back and check if request is completed or timeout |
| 2407 | } finally { |
| 2408 | now = SystemClock.elapsedRealtime(); |
| 2409 | } |
| 2410 | } |
| 2411 | } else { |
| 2412 | // Wait for the request to complete |
| 2413 | while (request.result == null) { |
| 2414 | try { |
| 2415 | request.wait(); |
| 2416 | } catch (InterruptedException e) { |
| 2417 | // Do nothing, go back and wait until the request is complete |
| 2418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2422 | if (request.result == null) { |
| 2423 | Log.wtf(LOG_TAG, |
| 2424 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | return request.result; |
| 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2431 | * Posts the specified command to be executed on the main thread, and |
| 2432 | * returns immediately. |
| 2433 | * @see #sendRequest |
| 2434 | */ |
| 2435 | private void sendRequestAsync(int command) { |
| 2436 | mMainThreadHandler.sendEmptyMessage(command); |
| 2437 | } |
| 2438 | |
| 2439 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2440 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2441 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2442 | */ |
| 2443 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2444 | sendRequestAsync(command, argument, null, null); |
| 2445 | } |
| 2446 | |
| 2447 | /** |
| 2448 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2449 | * @see {@link #sendRequest(int,Object)} |
| 2450 | */ |
| 2451 | private void sendRequestAsync( |
| 2452 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2453 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2454 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2455 | msg.sendToTarget(); |
| 2456 | } |
| 2457 | |
| 2458 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2460 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2461 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2462 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | synchronized (PhoneInterfaceManager.class) { |
| 2464 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2465 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | } else { |
| 2467 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2468 | } |
| 2469 | return sInstance; |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2474 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2476 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2477 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2479 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2480 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2481 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2483 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2484 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2485 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2486 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2487 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2488 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2489 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2490 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2491 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2492 | mVendorApiLevel = SystemProperties.getInt( |
| 2493 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2494 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2495 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2497 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2498 | |
| 2499 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2500 | // entitlementStatus for satellite service. |
| 2501 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2504 | @VisibleForTesting |
| 2505 | public SharedPreferences getSharedPreferences() { |
| 2506 | return mTelephonySharedPreferences; |
| 2507 | } |
| 2508 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2509 | /** |
| 2510 | * Get the default phone for this device. |
| 2511 | */ |
| 2512 | @VisibleForTesting |
| 2513 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2514 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2515 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2516 | } |
| 2517 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | private void publish() { |
| 2519 | if (DBG) log("publish: " + this); |
| 2520 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2521 | TelephonyFrameworkInitializer |
| 2522 | .getTelephonyServiceManager() |
| 2523 | .getTelephonyServiceRegisterer() |
| 2524 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2527 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2528 | if (request.phone != null) { |
| 2529 | return request.phone; |
| 2530 | } else { |
| 2531 | return getPhoneFromSubId(request.subId); |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | private Phone getPhoneFromSubId(int subId) { |
| 2536 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2537 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2540 | /** |
| 2541 | * Get phone object associated with a subscription. |
| 2542 | * Return default phone if phone object associated with subscription is null |
| 2543 | * @param subId - subscriptionId |
| 2544 | * @return phone object associated with a subscription or default phone if null. |
| 2545 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2546 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2547 | Phone phone = getPhoneFromSubId(subId); |
| 2548 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2549 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2550 | phone = getDefaultPhone(); |
| 2551 | } |
| 2552 | return phone; |
| 2553 | } |
| 2554 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2555 | @Nullable |
| 2556 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2557 | Phone phone = getPhoneFromRequest(request); |
| 2558 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2559 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2560 | } |
| 2561 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2562 | /** |
| 2563 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2564 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2565 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2566 | * @return The Phone associated the sub Id |
| 2567 | */ |
| 2568 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2569 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2570 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2571 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2572 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2573 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2574 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2575 | } |
| 2576 | |
| 2577 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2578 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2579 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2582 | private boolean isImsAvailableOnDevice() { |
| 2583 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2584 | if (pm == null) { |
| 2585 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2586 | // so do not throw error and allow. |
| 2587 | return true; |
| 2588 | } |
| 2589 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2590 | } |
| 2591 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2593 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2594 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2595 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2596 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2599 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | if (DBG) log("dial: " + number); |
| 2601 | // No permission check needed here: This is just a wrapper around the |
| 2602 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2603 | // the UI before it does anything. |
| 2604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
| 2607 | String url = createTelUrl(number); |
| 2608 | if (url == null) { |
| 2609 | return; |
| 2610 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2611 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2613 | PhoneConstants.State state = mCM.getState(subId); |
| 2614 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2615 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2616 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2617 | mApp.startActivity(intent); |
| 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2625 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2628 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | if (DBG) log("call: " + number); |
| 2630 | |
| 2631 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2632 | // need to do a permission check since we're calling startActivity() |
| 2633 | // from the context of the phone app. |
| 2634 | enforceCallPermission(); |
| 2635 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2636 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2637 | != AppOpsManager.MODE_ALLOWED) { |
| 2638 | return; |
| 2639 | } |
| 2640 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2641 | enforceTelephonyFeatureWithException(callingPackage, |
| 2642 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2644 | final long identity = Binder.clearCallingIdentity(); |
| 2645 | try { |
| 2646 | String url = createTelUrl(number); |
| 2647 | if (url == null) { |
| 2648 | return; |
| 2649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | boolean isValid = false; |
| 2652 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2653 | if (slist != null) { |
| 2654 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2655 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2656 | isValid = true; |
| 2657 | break; |
| 2658 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2659 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | if (!isValid) { |
| 2662 | return; |
| 2663 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2664 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2666 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2667 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2668 | mApp.startActivity(intent); |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
| 2671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2674 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2675 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2676 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2677 | } |
| 2678 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2679 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2680 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2681 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2682 | } |
| 2683 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2684 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2687 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2688 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2689 | "supplyPinReportResultForSubscriber"); |
| 2690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2691 | final long identity = Binder.clearCallingIdentity(); |
| 2692 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2693 | Phone phone = getPhone(subId); |
| 2694 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | checkSimPin.start(); |
| 2696 | return checkSimPin.unlockSim(null, pin); |
| 2697 | } finally { |
| 2698 | Binder.restoreCallingIdentity(identity); |
| 2699 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2702 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2705 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2706 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2707 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | final long identity = Binder.clearCallingIdentity(); |
| 2709 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2710 | Phone phone = getPhone(subId); |
| 2711 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | checkSimPuk.start(); |
| 2713 | return checkSimPuk.unlockSim(puk, pin); |
| 2714 | } finally { |
| 2715 | Binder.restoreCallingIdentity(identity); |
| 2716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2720 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | * a synchronous one. |
| 2722 | */ |
| 2723 | private static class UnlockSim extends Thread { |
| 2724 | |
| 2725 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2726 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | |
| 2728 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2729 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2730 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | |
| 2732 | // For replies from SimCard interface |
| 2733 | private Handler mHandler; |
| 2734 | |
| 2735 | // For async handler to identify request type |
| 2736 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2737 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2738 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2739 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2740 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2742 | UnlockSim(int phoneId, IccCard simCard) { |
| 2743 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | mSimCard = simCard; |
| 2745 | } |
| 2746 | |
| 2747 | @Override |
| 2748 | public void run() { |
| 2749 | Looper.prepare(); |
| 2750 | synchronized (UnlockSim.this) { |
| 2751 | mHandler = new Handler() { |
| 2752 | @Override |
| 2753 | public void handleMessage(Message msg) { |
| 2754 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2755 | switch (msg.what) { |
| 2756 | case SUPPLY_PIN_COMPLETE: |
| 2757 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2758 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2759 | mRetryCount = msg.arg1; |
| 2760 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2761 | CommandException.Error error = null; |
| 2762 | if (ar.exception instanceof CommandException) { |
| 2763 | error = ((CommandException) (ar.exception)) |
| 2764 | .getCommandError(); |
| 2765 | } |
| 2766 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2767 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2768 | } else if (error == CommandException.Error.ABORTED) { |
| 2769 | /* When UiccCardApp dispose, handle message and return |
| 2770 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2771 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2772 | } else { |
| 2773 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2774 | } |
| 2775 | } else { |
| 2776 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2779 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | UnlockSim.this.notifyAll(); |
| 2781 | } |
| 2782 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2783 | case SUPPLY_PIN_DELAYED: |
| 2784 | if(!mDone) { |
| 2785 | String logStr = "Delay in receiving SIM PIN response "; |
| 2786 | if (DBG) log(logStr); |
| 2787 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2788 | } |
| 2789 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | } |
| 2791 | } |
| 2792 | }; |
| 2793 | UnlockSim.this.notifyAll(); |
| 2794 | } |
| 2795 | Looper.loop(); |
| 2796 | } |
| 2797 | |
| 2798 | /* |
| 2799 | * Use PIN or PUK to unlock SIM card |
| 2800 | * |
| 2801 | * If PUK is null, unlock SIM card with PIN |
| 2802 | * |
| 2803 | * 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] | 2804 | * |
| 2805 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2806 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2807 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2808 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | |
| 2810 | while (mHandler == null) { |
| 2811 | try { |
| 2812 | wait(); |
| 2813 | } catch (InterruptedException e) { |
| 2814 | Thread.currentThread().interrupt(); |
| 2815 | } |
| 2816 | } |
| 2817 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2818 | |
| 2819 | if (puk == null) { |
| 2820 | mSimCard.supplyPin(pin, callback); |
| 2821 | } else { |
| 2822 | mSimCard.supplyPuk(puk, pin, callback); |
| 2823 | } |
| 2824 | |
| 2825 | while (!mDone) { |
| 2826 | try { |
| 2827 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2828 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2829 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2830 | wait(); |
| 2831 | } catch (InterruptedException e) { |
| 2832 | // Restore the interrupted status |
| 2833 | Thread.currentThread().interrupt(); |
| 2834 | } |
| 2835 | } |
| 2836 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2837 | int[] resultArray = new int[2]; |
| 2838 | resultArray[0] = mResult; |
| 2839 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2840 | |
| 2841 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2842 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2843 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2844 | // This instance is no longer reused, so quit its thread's looper. |
| 2845 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2846 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2847 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2851 | /** |
| 2852 | * This method has been removed due to privacy and stability concerns. |
| 2853 | */ |
| 2854 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2856 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2857 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2860 | @Override |
| 2861 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2862 | mApp.getSystemService(AppOpsManager.class) |
| 2863 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2864 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2865 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2866 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2867 | // Callers targeting S have no business invoking this method. |
| 2868 | return; |
| 2869 | } |
| 2870 | |
| 2871 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2872 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2873 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2874 | .setCallingPackage(callingPackage) |
| 2875 | .setCallingFeatureId(null) |
| 2876 | .setCallingPid(Binder.getCallingPid()) |
| 2877 | .setCallingUid(Binder.getCallingUid()) |
| 2878 | .setMethod("updateServiceLocation") |
| 2879 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2880 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2881 | .build()); |
| 2882 | // Apps that lack location permission have no business calling this method; |
| 2883 | // however, because no permission was declared in the public API, denials must |
| 2884 | // all be "soft". |
| 2885 | switch (locationResult) { |
| 2886 | case DENIED_HARD: /* fall through */ |
| 2887 | case DENIED_SOFT: |
| 2888 | return; |
| 2889 | } |
| 2890 | |
| 2891 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | final long identity = Binder.clearCallingIdentity(); |
| 2893 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2894 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2900 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2901 | @Override |
| 2902 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2903 | return isRadioOnWithFeature(callingPackage, null); |
| 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | @Override |
| 2908 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2909 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2910 | callingFeatureId); |
| 2911 | } |
| 2912 | |
| 2913 | @Deprecated |
| 2914 | @Override |
| 2915 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2916 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2920 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2921 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2923 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2924 | return false; |
| 2925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2927 | enforceTelephonyFeatureWithException(callingPackage, |
| 2928 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2929 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | return isRadioOnForSubscriber(subId); |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(identity); |
| 2935 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | final Phone phone = getPhone(subId); |
| 2942 | if (phone != null) { |
| 2943 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2944 | } else { |
| 2945 | return false; |
| 2946 | } |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2949 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2953 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2954 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2955 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2956 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2959 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2960 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
| 2964 | final Phone phone = getPhone(subId); |
| 2965 | if (phone != null) { |
| 2966 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2967 | } |
| 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2970 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2974 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2977 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2978 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | |
| 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
| 2982 | final Phone phone = getPhone(subId); |
| 2983 | if (phone == null) { |
| 2984 | return false; |
| 2985 | } |
| 2986 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2987 | toggleRadioOnOffForSubscriber(subId); |
| 2988 | } |
| 2989 | return true; |
| 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2993 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2994 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2995 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2996 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2997 | |
| 2998 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2999 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3000 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3001 | /* |
| 3002 | * If any of the Radios are available, it will need to be |
| 3003 | * shutdown. So return true if any Radio is available. |
| 3004 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | final long identity = Binder.clearCallingIdentity(); |
| 3006 | try { |
| 3007 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3008 | Phone phone = PhoneFactory.getPhone(i); |
| 3009 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3010 | } |
| 3011 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3012 | return false; |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3015 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3019 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | enforceModifyPermission(); |
| 3021 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3022 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3023 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3028 | logv("Shutting down Phone " + i); |
| 3029 | shutdownRadioUsingPhoneId(i); |
| 3030 | } |
| 3031 | } finally { |
| 3032 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3037 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3038 | if (phone != null && phone.isRadioAvailable()) { |
| 3039 | phone.shutdownRadio(); |
| 3040 | } |
| 3041 | } |
| 3042 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3044 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3045 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3046 | if (!turnOn) { |
| 3047 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3048 | } |
| 3049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | final long identity = Binder.clearCallingIdentity(); |
| 3051 | try { |
| 3052 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3053 | if (defaultPhone != null) { |
| 3054 | defaultPhone.setRadioPower(turnOn); |
| 3055 | return true; |
| 3056 | } else { |
| 3057 | loge("There's no default phone."); |
| 3058 | return false; |
| 3059 | } |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3062 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3065 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3066 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3067 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3068 | if (!turnOn) { |
| 3069 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3070 | + ",callingPackage=" + getCurrentPackageName()); |
| 3071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | final long identity = Binder.clearCallingIdentity(); |
| 3073 | try { |
| 3074 | final Phone phone = getPhone(subId); |
| 3075 | if (phone != null) { |
| 3076 | phone.setRadioPower(turnOn); |
| 3077 | return true; |
| 3078 | } else { |
| 3079 | return false; |
| 3080 | } |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3083 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3086 | /** |
| 3087 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3088 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3089 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3090 | * powering it off, and these radio off votes will be cleared. |
| 3091 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3092 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3093 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3094 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3095 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3096 | * check its vote. |
| 3097 | * |
| 3098 | * @param subId The subscription ID. |
| 3099 | * @param reason The reason for powering off radio. |
| 3100 | * @return true on success and false on failure. |
| 3101 | */ |
| 3102 | public boolean requestRadioPowerOffForReason(int subId, |
| 3103 | @TelephonyManager.RadioPowerReason int reason) { |
| 3104 | enforceModifyPermission(); |
| 3105 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3106 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3107 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3108 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3109 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3110 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3111 | final long identity = Binder.clearCallingIdentity(); |
| 3112 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3113 | boolean result = false; |
| 3114 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3115 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3116 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3117 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3118 | if (!result) { |
| 3119 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3120 | } |
| 3121 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | /** |
| 3128 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3129 | * {@link requestRadioPowerOffForReason}. |
| 3130 | * |
| 3131 | * @param subId The subscription ID. |
| 3132 | * @param reason The reason for powering off radio. |
| 3133 | * @return true on success and false on failure. |
| 3134 | */ |
| 3135 | public boolean clearRadioPowerOffForReason(int subId, |
| 3136 | @TelephonyManager.RadioPowerReason int reason) { |
| 3137 | enforceModifyPermission(); |
| 3138 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3139 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3140 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3141 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3142 | final long identity = Binder.clearCallingIdentity(); |
| 3143 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3144 | boolean result = false; |
| 3145 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3146 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3147 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3148 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3149 | if (!result) { |
| 3150 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3151 | } |
| 3152 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3160 | * |
| 3161 | * @param subId The subscription ID. |
| 3162 | * @param callingPackage The package making the call. |
| 3163 | * @param callingFeatureId The feature in the package. |
| 3164 | * @return List of reasons for powering off radio. |
| 3165 | */ |
| 3166 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3167 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3168 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3169 | enforceTelephonyFeatureWithException(callingPackage, |
| 3170 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3171 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3172 | final long identity = Binder.clearCallingIdentity(); |
| 3173 | List result = new ArrayList(); |
| 3174 | try { |
| 3175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3176 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3177 | return result; |
| 3178 | } |
| 3179 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3180 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3181 | if (phone != null) { |
| 3182 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3183 | } else { |
| 3184 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3185 | } |
| 3186 | } finally { |
| 3187 | Binder.restoreCallingIdentity(identity); |
| 3188 | } |
| 3189 | return result; |
| 3190 | } |
| 3191 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3192 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3193 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3194 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3195 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3196 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3197 | enforceTelephonyFeatureWithException(callingPackage, |
| 3198 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3199 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3202 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3204 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3205 | phone.getDataSettingsManager().setDataEnabled( |
| 3206 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | return true; |
| 3208 | } else { |
| 3209 | return false; |
| 3210 | } |
| 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3213 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3216 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3218 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3219 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3221 | enforceTelephonyFeatureWithException(callingPackage, |
| 3222 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final long identity = Binder.clearCallingIdentity(); |
| 3225 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3226 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3228 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3229 | phone.getDataSettingsManager().setDataEnabled( |
| 3230 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3231 | return true; |
| 3232 | } else { |
| 3233 | return false; |
| 3234 | } |
| 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3240 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3241 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3242 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3243 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | final long identity = Binder.clearCallingIdentity(); |
| 3246 | try { |
| 3247 | final Phone phone = getPhone(subId); |
| 3248 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3249 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | } else { |
| 3251 | return false; |
| 3252 | } |
| 3253 | } finally { |
| 3254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3259 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3262 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3263 | enforceCallPermission(); |
| 3264 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3265 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3266 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3267 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | final long identity = Binder.clearCallingIdentity(); |
| 3269 | try { |
| 3270 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3271 | return; |
| 3272 | } |
| 3273 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3274 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
| 3277 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3278 | }; |
| 3279 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3280 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3281 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3283 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3284 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3286 | final long identity = Binder.clearCallingIdentity(); |
| 3287 | try { |
| 3288 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3289 | return false; |
| 3290 | } |
| 3291 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3292 | } finally { |
| 3293 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3297 | /** |
| 3298 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3299 | * tag on getCallState Binder call. |
| 3300 | */ |
| 3301 | @Deprecated |
| 3302 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3303 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3304 | if (CompatChanges.isChangeEnabled( |
| 3305 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3306 | Binder.getCallingUid())) { |
| 3307 | // Do not allow this API to be called on API version 31+, it should only be |
| 3308 | // called on old apps using this Binder call directly. |
| 3309 | throw new SecurityException("This method can only be used for applications " |
| 3310 | + "targeting API version 30 or less."); |
| 3311 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | final long identity = Binder.clearCallingIdentity(); |
| 3313 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3314 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3315 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(identity); |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | @Override |
| 3322 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3323 | if (CompatChanges.isChangeEnabled( |
| 3324 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3325 | Binder.getCallingUid())) { |
| 3326 | // Check READ_PHONE_STATE for API version 31+ |
| 3327 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3328 | featureId, "getCallStateForSubscription")) { |
| 3329 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3330 | + "targeting API level 31+."); |
| 3331 | } |
| 3332 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3333 | |
| 3334 | enforceTelephonyFeatureWithException(callingPackage, |
| 3335 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3336 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3340 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3341 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(identity); |
| 3344 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3347 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3348 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3349 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | @Override |
| 3353 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3354 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3355 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3359 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3360 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3361 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | } else { |
| 3363 | return PhoneConstantConversions.convertDataState( |
| 3364 | PhoneConstants.DataState.DISCONNECTED); |
| 3365 | } |
| 3366 | } finally { |
| 3367 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3371 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3372 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3373 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3377 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3378 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3379 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3380 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3383 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3384 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3385 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | } else { |
| 3387 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3388 | } |
| 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3395 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3396 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3397 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3398 | |
| 3399 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3400 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3401 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3402 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3403 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3404 | .setCallingPid(Binder.getCallingPid()) |
| 3405 | .setCallingUid(Binder.getCallingUid()) |
| 3406 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3407 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3408 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3409 | .build()); |
| 3410 | switch (locationResult) { |
| 3411 | case DENIED_HARD: |
| 3412 | throw new SecurityException("Not allowed to access cell location"); |
| 3413 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3414 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3415 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3418 | enforceTelephonyFeatureWithException(callingPackage, |
| 3419 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3420 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3421 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3425 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3426 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
| 3429 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3432 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3433 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3434 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3435 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3436 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3437 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3438 | // registered cell info, so return a NULL country instead. |
| 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3441 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3442 | // Get default phone in this case. |
| 3443 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3444 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3445 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3447 | if (phone == null) return ""; |
| 3448 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3449 | if (sst == null) return ""; |
| 3450 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3451 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3452 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3458 | /** |
| 3459 | * This method was removed due to potential issues caused by performing partial |
| 3460 | * updates of service state, and lack of a credible use case. |
| 3461 | * |
| 3462 | * This has the ability to break the telephony implementation by disabling notification of |
| 3463 | * changes in device connectivity. DO NOT USE THIS! |
| 3464 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3465 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3466 | public void enableLocationUpdates() { |
| 3467 | mApp.enforceCallingOrSelfPermission( |
| 3468 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3471 | /** |
| 3472 | * This method was removed due to potential issues caused by performing partial |
| 3473 | * updates of service state, and lack of a credible use case. |
| 3474 | * |
| 3475 | * This has the ability to break the telephony implementation by disabling notification of |
| 3476 | * changes in device connectivity. DO NOT USE THIS! |
| 3477 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | @Override |
| 3479 | public void disableLocationUpdates() { |
| 3480 | mApp.enforceCallingOrSelfPermission( |
| 3481 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | @Override |
| 3485 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3486 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3487 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3488 | try { |
| 3489 | mApp.getSystemService(AppOpsManager.class) |
| 3490 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3491 | } catch (SecurityException e) { |
| 3492 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3493 | throw e; |
| 3494 | } |
| 3495 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3496 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3497 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3498 | throw new SecurityException( |
| 3499 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3500 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3501 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3502 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3503 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3504 | return null; |
| 3505 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3506 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3507 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3508 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3509 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3510 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3511 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3512 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3513 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3515 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3516 | for (CellInfo ci : info) { |
| 3517 | if (ci instanceof CellInfoGsm) { |
| 3518 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3519 | } else if (ci instanceof CellInfoWcdma) { |
| 3520 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3523 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3526 | private List<CellInfo> getCachedCellInfo() { |
| 3527 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3528 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3529 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3530 | if (info != null) cellInfos.addAll(info); |
| 3531 | } |
| 3532 | return cellInfos; |
| 3533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3534 | |
| 3535 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3536 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3537 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3538 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3539 | |
| 3540 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3541 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3542 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3543 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3544 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3545 | .setCallingPid(Binder.getCallingPid()) |
| 3546 | .setCallingUid(Binder.getCallingUid()) |
| 3547 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3548 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3549 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3550 | .build()); |
| 3551 | switch (locationResult) { |
| 3552 | case DENIED_HARD: |
| 3553 | throw new SecurityException("Not allowed to access cell info"); |
| 3554 | case DENIED_SOFT: |
| 3555 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3558 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3559 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3560 | return getCachedCellInfo(); |
| 3561 | } |
| 3562 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3563 | enforceTelephonyFeatureWithException(callingPackage, |
| 3564 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3565 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3566 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3567 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3571 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3572 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3573 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3574 | if (info != null) cellInfos.addAll(info); |
| 3575 | } |
| 3576 | return cellInfos; |
| 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3582 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3583 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3584 | String callingFeatureId) { |
| 3585 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3586 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3590 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3591 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3592 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3593 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3596 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3597 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3598 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3599 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3600 | |
| 3601 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3602 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3603 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3604 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3605 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3606 | .setCallingPid(Binder.getCallingPid()) |
| 3607 | .setCallingUid(Binder.getCallingUid()) |
| 3608 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3609 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3610 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3611 | .build()); |
| 3612 | switch (locationResult) { |
| 3613 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3614 | if (TelephonyPermissions |
| 3615 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3616 | // Safetynet logging for b/154934934 |
| 3617 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3618 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3619 | throw new SecurityException("Not allowed to access cell info"); |
| 3620 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3621 | if (TelephonyPermissions |
| 3622 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3623 | // Safetynet logging for b/154934934 |
| 3624 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3625 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3626 | try { |
| 3627 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3628 | } catch (RemoteException re) { |
| 3629 | // Drop without consequences |
| 3630 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3631 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3634 | enforceTelephonyFeatureWithException(callingPackage, |
| 3635 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3636 | |
| 3637 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3638 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3639 | |
| 3640 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3641 | } |
| 3642 | |
| 3643 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3644 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3645 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3646 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | |
| 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3650 | Phone phone = getPhone(subId); |
| 3651 | if (phone == null) { |
| 3652 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3653 | } else { |
| 3654 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | } finally { |
| 3657 | Binder.restoreCallingIdentity(identity); |
| 3658 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3661 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3662 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3663 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3664 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3665 | return null; |
| 3666 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3667 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3668 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3669 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3670 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3671 | return null; |
| 3672 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3674 | enforceTelephonyFeatureWithException(callingPackage, |
| 3675 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | return phone.getImei(); |
| 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
| 3682 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3686 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3687 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3688 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3689 | callingFeatureId, "getPrimaryImei")) { |
| 3690 | throw new SecurityException("Caller does not have permission"); |
| 3691 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3692 | |
| 3693 | enforceTelephonyFeatureWithException(callingPackage, |
| 3694 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3695 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3699 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3700 | return phone.getImei(); |
| 3701 | } |
| 3702 | } |
| 3703 | throw new UnsupportedOperationException("Operation not supported"); |
| 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3710 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3711 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3712 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3713 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3714 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3715 | String tac = null; |
| 3716 | if (phone != null) { |
| 3717 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3718 | try { |
| 3719 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3720 | } catch (IndexOutOfBoundsException e) { |
| 3721 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3722 | return null; |
| 3723 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3724 | } |
| 3725 | return tac; |
| 3726 | } |
| 3727 | |
| 3728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3729 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3730 | try { |
| 3731 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3732 | } catch (SecurityException se) { |
| 3733 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3734 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3735 | + Binder.getCallingUid()); |
| 3736 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3737 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3738 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3739 | return null; |
| 3740 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3742 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3743 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3744 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3745 | return null; |
| 3746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3748 | enforceTelephonyFeatureWithException(callingPackage, |
| 3749 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | return phone.getMeid(); |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(identity); |
| 3756 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3760 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3761 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3762 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3763 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3764 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3765 | String manufacturerCode = null; |
| 3766 | if (phone != null) { |
| 3767 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3768 | try { |
| 3769 | manufacturerCode = |
| 3770 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3771 | } catch (IndexOutOfBoundsException e) { |
| 3772 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3773 | return null; |
| 3774 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3775 | } |
| 3776 | return manufacturerCode; |
| 3777 | } |
| 3778 | |
| 3779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3780 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3781 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3783 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3784 | return null; |
| 3785 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3786 | int subId = phone.getSubId(); |
| 3787 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3788 | mApp, subId, callingPackage, callingFeatureId, |
| 3789 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3790 | return null; |
| 3791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3793 | enforceTelephonyFeatureWithException(callingPackage, |
| 3794 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | return phone.getDeviceSvn(); |
| 3799 | } finally { |
| 3800 | Binder.restoreCallingIdentity(identity); |
| 3801 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3804 | @Override |
| 3805 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3806 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3807 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3808 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | final long identity = Binder.clearCallingIdentity(); |
| 3810 | try { |
| 3811 | final Phone phone = getPhone(subId); |
| 3812 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(identity); |
| 3815 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | @Override |
| 3819 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3820 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3821 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3822 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3823 | final long identity = Binder.clearCallingIdentity(); |
| 3824 | try { |
| 3825 | final Phone phone = getPhone(subId); |
| 3826 | return phone == null ? null : phone.getCarrierName(); |
| 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
| 3829 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3830 | } |
| 3831 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3832 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3833 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3834 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3835 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3836 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
| 3839 | final Phone phone = getPhone(subId); |
| 3840 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3841 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3842 | } finally { |
| 3843 | Binder.restoreCallingIdentity(identity); |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3848 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3849 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3850 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3851 | "getSubscriptionSpecificCarrierName"); |
| 3852 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3853 | final long identity = Binder.clearCallingIdentity(); |
| 3854 | try { |
| 3855 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3856 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
| 3859 | } |
| 3860 | } |
| 3861 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3862 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3863 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3864 | if (!isSubscriptionMccMnc) { |
| 3865 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3866 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3867 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3868 | if (phone == null) { |
| 3869 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3870 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3871 | |
| 3872 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3873 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3874 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3875 | final long identity = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
| 3880 | } |
| 3881 | } |
| 3882 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3883 | // |
| 3884 | // Internal helper methods. |
| 3885 | // |
| 3886 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3887 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3888 | * Make sure the caller is the calling package itself |
| 3889 | * |
| 3890 | * @throws SecurityException if the caller is not the calling package |
| 3891 | */ |
| 3892 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3893 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3894 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3895 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3896 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3897 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3898 | } catch (PackageManager.NameNotFoundException e) { |
| 3899 | // packageUid is -1 |
| 3900 | } |
| 3901 | if (packageUid != callingUid) { |
| 3902 | throw new SecurityException(message + ": Package " + callingPackage |
| 3903 | + " does not belong to " + callingUid); |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3908 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3909 | * |
| 3910 | * @throws SecurityException if the caller does not have the required permission |
| 3911 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3912 | @VisibleForTesting |
| 3913 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3914 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3915 | } |
| 3916 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3917 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3918 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3919 | * |
| 3920 | * @throws SecurityException if the caller does not have the required permission |
| 3921 | */ |
| 3922 | @VisibleForTesting |
| 3923 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3924 | enforceReadPermission(null); |
| 3925 | } |
| 3926 | |
| 3927 | /** |
| 3928 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3929 | * |
| 3930 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3931 | */ |
| 3932 | @VisibleForTesting |
| 3933 | public void enforceReadPermission(String msg) { |
| 3934 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3937 | private void enforceActiveEmergencySessionPermission() { |
| 3938 | mApp.enforceCallingOrSelfPermission( |
| 3939 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3940 | } |
| 3941 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3942 | /** |
| 3943 | * Make sure the caller has the CALL_PHONE permission. |
| 3944 | * |
| 3945 | * @throws SecurityException if the caller does not have the required permission |
| 3946 | */ |
| 3947 | private void enforceCallPermission() { |
| 3948 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3949 | } |
| 3950 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3951 | private void enforceSettingsPermission() { |
| 3952 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3955 | private void enforceRebootPermission() { |
| 3956 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3957 | } |
| 3958 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3959 | /** |
| 3960 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3961 | * @param message - log message to print. |
| 3962 | * @throws SecurityException if the caller does not have the required permission |
| 3963 | */ |
| 3964 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3965 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3966 | } |
| 3967 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3968 | /** |
| 3969 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3970 | * @param message - log message to print. |
| 3971 | * @throws SecurityException if the caller does not have the required permission |
| 3972 | */ |
| 3973 | private void enforcePackageUsageStatsPermission(String message) { |
| 3974 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3975 | } |
| 3976 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3977 | private String createTelUrl(String number) { |
| 3978 | if (TextUtils.isEmpty(number)) { |
| 3979 | return null; |
| 3980 | } |
| 3981 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3982 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3985 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3986 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3989 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3990 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3993 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3994 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3997 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3998 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3999 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4002 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4003 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4004 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4005 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4006 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4010 | if (phone == null) { |
| 4011 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4012 | } else { |
| 4013 | return phone.getPhoneType(); |
| 4014 | } |
| 4015 | } finally { |
| 4016 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4017 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /** |
| 4021 | * Returns the CDMA ERI icon index to display |
| 4022 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4023 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4024 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4025 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4026 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4029 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4030 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4031 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4033 | mApp, subId, callingPackage, callingFeatureId, |
| 4034 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4035 | return -1; |
| 4036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4037 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4038 | enforceTelephonyFeatureWithException(callingPackage, |
| 4039 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4040 | "getCdmaEriIconIndexForSubscriber"); |
| 4041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | final long identity = Binder.clearCallingIdentity(); |
| 4043 | try { |
| 4044 | final Phone phone = getPhone(subId); |
| 4045 | if (phone != null) { |
| 4046 | return phone.getCdmaEriIconIndex(); |
| 4047 | } else { |
| 4048 | return -1; |
| 4049 | } |
| 4050 | } finally { |
| 4051 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | /** |
| 4056 | * Returns the CDMA ERI icon mode, |
| 4057 | * 0 - ON |
| 4058 | * 1 - FLASHING |
| 4059 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4060 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4061 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4062 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4063 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4066 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4067 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4068 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4070 | mApp, subId, callingPackage, callingFeatureId, |
| 4071 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4072 | return -1; |
| 4073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4074 | |
| 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
| 4077 | final Phone phone = getPhone(subId); |
| 4078 | if (phone != null) { |
| 4079 | return phone.getCdmaEriIconMode(); |
| 4080 | } else { |
| 4081 | return -1; |
| 4082 | } |
| 4083 | } finally { |
| 4084 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4085 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | /** |
| 4089 | * Returns the CDMA ERI text, |
| 4090 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4091 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4092 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4093 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4094 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4097 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4098 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4099 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4100 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4101 | mApp, subId, callingPackage, callingFeatureId, |
| 4102 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4103 | return null; |
| 4104 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | |
| 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | final Phone phone = getPhone(subId); |
| 4109 | if (phone != null) { |
| 4110 | return phone.getCdmaEriText(); |
| 4111 | } else { |
| 4112 | return null; |
| 4113 | } |
| 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4116 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4120 | * Returns the CDMA MDN. |
| 4121 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4122 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4123 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4125 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4127 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4128 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | final long identity = Binder.clearCallingIdentity(); |
| 4131 | try { |
| 4132 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4133 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | return phone.getLine1Number(); |
| 4135 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4136 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4137 | return null; |
| 4138 | } |
| 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | /** |
| 4145 | * Returns the CDMA MIN. |
| 4146 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4147 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4148 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4150 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4151 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4152 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4153 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | final long identity = Binder.clearCallingIdentity(); |
| 4156 | try { |
| 4157 | final Phone phone = getPhone(subId); |
| 4158 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4159 | return phone.getCdmaMin(); |
| 4160 | } else { |
| 4161 | return null; |
| 4162 | } |
| 4163 | } finally { |
| 4164 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4168 | @Override |
| 4169 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4170 | INumberVerificationCallback callback, String callingPackage) { |
| 4171 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4172 | != PERMISSION_GRANTED) { |
| 4173 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4174 | } |
| 4175 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4176 | |
| 4177 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4178 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4179 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4180 | + "calling package: " + callingPackage |
| 4181 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4184 | enforceTelephonyFeatureWithException(callingPackage, |
| 4185 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4186 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4187 | if (range == null) { |
| 4188 | throw new NullPointerException("Range must be non-null"); |
| 4189 | } |
| 4190 | |
| 4191 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4192 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4193 | |
| 4194 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4195 | } |
| 4196 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4197 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4198 | * Returns true if CDMA provisioning needs to run. |
| 4199 | */ |
| 4200 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4201 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4202 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4203 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4204 | final long identity = Binder.clearCallingIdentity(); |
| 4205 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4206 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
| 4209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4213 | * Sets the voice mail number of a given subId. |
| 4214 | */ |
| 4215 | @Override |
| 4216 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4217 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4218 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4220 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4221 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | final long identity = Binder.clearCallingIdentity(); |
| 4224 | try { |
| 4225 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4226 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4227 | return success; |
| 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4233 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4234 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4235 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4236 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4237 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4238 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4239 | throw new SecurityException("caller must be system dialer"); |
| 4240 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4242 | enforceTelephonyFeatureWithException(callingPackage, |
| 4243 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4248 | if (phoneAccountHandle == null) { |
| 4249 | return null; |
| 4250 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4251 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | } finally { |
| 4253 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4254 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4258 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4259 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4260 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4261 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4262 | mApp, subId, callingPackage, callingFeatureId, |
| 4263 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4264 | return null; |
| 4265 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4266 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4267 | enforceTelephonyFeatureWithException(callingPackage, |
| 4268 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4269 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4270 | final long identity = Binder.clearCallingIdentity(); |
| 4271 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4272 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4273 | } finally { |
| 4274 | Binder.restoreCallingIdentity(identity); |
| 4275 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4279 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4280 | VisualVoicemailSmsFilterSettings settings) { |
| 4281 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4282 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4283 | enforceTelephonyFeatureWithException(callingPackage, |
| 4284 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4285 | final long identity = Binder.clearCallingIdentity(); |
| 4286 | try { |
| 4287 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4288 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | } finally { |
| 4290 | Binder.restoreCallingIdentity(identity); |
| 4291 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4295 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4296 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4297 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4298 | enforceTelephonyFeatureWithException(callingPackage, |
| 4299 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4300 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | final long identity = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4304 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4305 | } finally { |
| 4306 | Binder.restoreCallingIdentity(identity); |
| 4307 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4311 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4312 | String callingPackage, int subId) { |
| 4313 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | |
| 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
| 4317 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4318 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4325 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4326 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | |
| 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
| 4330 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4331 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4338 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4339 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4340 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4341 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4342 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4343 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4344 | |
| 4345 | enforceTelephonyFeatureWithException(callingPackage, |
| 4346 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4347 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4348 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4349 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4350 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4351 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4352 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4353 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4354 | * Sets the voice activation state of a given subId. |
| 4355 | */ |
| 4356 | @Override |
| 4357 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4359 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4362 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | final long identity = Binder.clearCallingIdentity(); |
| 4365 | try { |
| 4366 | final Phone phone = getPhone(subId); |
| 4367 | if (phone != null) { |
| 4368 | phone.setVoiceActivationState(activationState); |
| 4369 | } else { |
| 4370 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4371 | } |
| 4372 | } finally { |
| 4373 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | /** |
| 4378 | * Sets the data activation state of a given subId. |
| 4379 | */ |
| 4380 | @Override |
| 4381 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4383 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4384 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4385 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4386 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4388 | final long identity = Binder.clearCallingIdentity(); |
| 4389 | try { |
| 4390 | final Phone phone = getPhone(subId); |
| 4391 | if (phone != null) { |
| 4392 | phone.setDataActivationState(activationState); |
| 4393 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4394 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4395 | } |
| 4396 | } finally { |
| 4397 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | /** |
| 4402 | * Returns the voice activation state of a given subId. |
| 4403 | */ |
| 4404 | @Override |
| 4405 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4406 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4408 | enforceTelephonyFeatureWithException(callingPackage, |
| 4409 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4410 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4411 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
| 4414 | if (phone != null) { |
| 4415 | return phone.getVoiceActivationState(); |
| 4416 | } else { |
| 4417 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4418 | } |
| 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | /** |
| 4425 | * Returns the data activation state of a given subId. |
| 4426 | */ |
| 4427 | @Override |
| 4428 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4429 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4431 | enforceTelephonyFeatureWithException(callingPackage, |
| 4432 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4433 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4434 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4435 | final long identity = Binder.clearCallingIdentity(); |
| 4436 | try { |
| 4437 | if (phone != null) { |
| 4438 | return phone.getDataActivationState(); |
| 4439 | } else { |
| 4440 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4441 | } |
| 4442 | } finally { |
| 4443 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4448 | * Returns the unread count of voicemails for a subId |
| 4449 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4450 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4451 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4452 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4453 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4454 | mApp, subId, callingPackage, callingFeatureId, |
| 4455 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4456 | return 0; |
| 4457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | final long identity = Binder.clearCallingIdentity(); |
| 4459 | try { |
| 4460 | final Phone phone = getPhone(subId); |
| 4461 | if (phone != null) { |
| 4462 | return phone.getVoiceMessageCount(); |
| 4463 | } else { |
| 4464 | return 0; |
| 4465 | } |
| 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4472 | * returns true, if the device is in a state where both voice and data |
| 4473 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4474 | */ |
| 4475 | @Override |
| 4476 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4477 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4478 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4482 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
| 4485 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4489 | * Send the dialer code if called from the current default dialer or the caller has |
| 4490 | * carrier privilege. |
| 4491 | * @param inputCode The dialer code to send |
| 4492 | */ |
| 4493 | @Override |
| 4494 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4495 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4496 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4497 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4498 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4499 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4500 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4501 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4502 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4504 | enforceTelephonyFeatureWithException(callingPackage, |
| 4505 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4509 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4510 | } finally { |
| 4511 | Binder.restoreCallingIdentity(identity); |
| 4512 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4513 | } |
| 4514 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4515 | @Override |
| 4516 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4517 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4518 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4519 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4520 | |
| 4521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4522 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4523 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4524 | final long identity = Binder.clearCallingIdentity(); |
| 4525 | try { |
| 4526 | if (!isActiveSubscription(subId)) { |
| 4527 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4528 | } |
| 4529 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4532 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4533 | } |
| 4534 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4536 | public boolean isInEmergencySmsMode() { |
| 4537 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4538 | |
| 4539 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4540 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4541 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4542 | final long identity = Binder.clearCallingIdentity(); |
| 4543 | try { |
| 4544 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4545 | if (phone.isInEmergencySmsMode()) { |
| 4546 | return true; |
| 4547 | } |
| 4548 | } |
| 4549 | } finally { |
| 4550 | Binder.restoreCallingIdentity(identity); |
| 4551 | } |
| 4552 | return false; |
| 4553 | } |
| 4554 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4555 | /** |
| 4556 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4557 | * @param subId The subscription to use to check the configuration. |
| 4558 | * @param c The callback that will be used to send the result. |
| 4559 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4560 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4561 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4562 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4563 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4564 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4565 | |
| 4566 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4568 | "IMS not available on device."); |
| 4569 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4570 | final long token = Binder.clearCallingIdentity(); |
| 4571 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4572 | int slotId = getSlotIndexOrException(subId); |
| 4573 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4574 | |
| 4575 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4576 | if (controller != null) { |
| 4577 | ImsManager imsManager = controller.getImsManager(subId); |
| 4578 | if (imsManager != null) { |
| 4579 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4580 | } else { |
| 4581 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4582 | } |
| 4583 | } else { |
| 4584 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4585 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4586 | } catch (ImsException e) { |
| 4587 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4588 | } finally { |
| 4589 | Binder.restoreCallingIdentity(token); |
| 4590 | } |
| 4591 | } |
| 4592 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4593 | /** |
| 4594 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4595 | * @param subId The subscription to use to check the configuration. |
| 4596 | * @param c The callback that will be used to send the result. |
| 4597 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4599 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4600 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4601 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4602 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4603 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4604 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4605 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4606 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4607 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4608 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4609 | if (controller != null) { |
| 4610 | ImsManager imsManager = controller.getImsManager(subId); |
| 4611 | if (imsManager != null) { |
| 4612 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4613 | } else { |
| 4614 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4615 | + "is inactive, ignoring unregister."); |
| 4616 | // If the ImsManager is not valid, just return, since the callback |
| 4617 | // will already have been removed internally. |
| 4618 | } |
| 4619 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(token); |
| 4622 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4625 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4626 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4627 | * @param subId The subscription to use to check the configuration. |
| 4628 | * @param c The callback that will be used to send the result. |
| 4629 | */ |
| 4630 | @Override |
| 4631 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4632 | throws RemoteException { |
| 4633 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4634 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4635 | |
| 4636 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4637 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4638 | "IMS not available on device."); |
| 4639 | } |
| 4640 | final long token = Binder.clearCallingIdentity(); |
| 4641 | try { |
| 4642 | int slotId = getSlotIndexOrException(subId); |
| 4643 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4644 | |
| 4645 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4646 | if (controller != null) { |
| 4647 | ImsManager imsManager = controller.getImsManager(subId); |
| 4648 | if (imsManager != null) { |
| 4649 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4650 | } else { |
| 4651 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4652 | } |
| 4653 | } else { |
| 4654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4655 | } |
| 4656 | } catch (ImsException e) { |
| 4657 | throw new ServiceSpecificException(e.getCode()); |
| 4658 | } finally { |
| 4659 | Binder.restoreCallingIdentity(token); |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | /** |
| 4664 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4665 | * @param subId The subscription to use to check the configuration. |
| 4666 | * @param c The callback that will be used to send the result. |
| 4667 | */ |
| 4668 | @Override |
| 4669 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4670 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4671 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4673 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4674 | } |
| 4675 | final long token = Binder.clearCallingIdentity(); |
| 4676 | |
| 4677 | try { |
| 4678 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4679 | if (controller != null) { |
| 4680 | ImsManager imsManager = controller.getImsManager(subId); |
| 4681 | if (imsManager != null) { |
| 4682 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4683 | } else { |
| 4684 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4685 | + "is inactive, ignoring unregister."); |
| 4686 | // If the ImsManager is not valid, just return, since the callback |
| 4687 | // will already have been removed internally. |
| 4688 | } |
| 4689 | } |
| 4690 | } finally { |
| 4691 | Binder.restoreCallingIdentity(token); |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4696 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4697 | */ |
| 4698 | @Override |
| 4699 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4700 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4701 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4702 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4703 | "IMS not available on device."); |
| 4704 | } |
| 4705 | final long token = Binder.clearCallingIdentity(); |
| 4706 | try { |
| 4707 | Phone phone = getPhone(subId); |
| 4708 | if (phone == null) { |
| 4709 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4710 | + subId + "'"); |
| 4711 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4712 | } |
| 4713 | phone.getImsRegistrationState(regState -> { |
| 4714 | try { |
| 4715 | consumer.accept((regState == null) |
| 4716 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4717 | } catch (RemoteException e) { |
| 4718 | // Ignore if the remote process is no longer available to call back. |
| 4719 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4720 | } |
| 4721 | }); |
| 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(token); |
| 4724 | } |
| 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * Get the transport type for the IMS service registration state. |
| 4729 | */ |
| 4730 | @Override |
| 4731 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4732 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4733 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4734 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4735 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4736 | "IMS not available on device."); |
| 4737 | } |
| 4738 | final long token = Binder.clearCallingIdentity(); |
| 4739 | try { |
| 4740 | Phone phone = getPhone(subId); |
| 4741 | if (phone == null) { |
| 4742 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4743 | + subId + "'"); |
| 4744 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4745 | } |
| 4746 | phone.getImsRegistrationTech(regTech -> { |
| 4747 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4748 | int regTechConverted = (regTech == null) |
| 4749 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4750 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4751 | regTechConverted); |
| 4752 | try { |
| 4753 | consumer.accept(regTechConverted); |
| 4754 | } catch (RemoteException e) { |
| 4755 | // Ignore if the remote process is no longer available to call back. |
| 4756 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4757 | } |
| 4758 | }); |
| 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(token); |
| 4761 | } |
| 4762 | } |
| 4763 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4764 | /** |
| 4765 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4766 | * @param subId The subscription to use to check the configuration. |
| 4767 | * @param c The callback that will be used to send the result. |
| 4768 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4770 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4771 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4772 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4773 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4774 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4775 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4776 | "IMS not available on device."); |
| 4777 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4778 | final long token = Binder.clearCallingIdentity(); |
| 4779 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4780 | int slotId = getSlotIndexOrException(subId); |
| 4781 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4782 | |
| 4783 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4784 | if (controller != null) { |
| 4785 | ImsManager imsManager = controller.getImsManager(subId); |
| 4786 | if (imsManager != null) { |
| 4787 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4788 | } else { |
| 4789 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4790 | } |
| 4791 | } else { |
| 4792 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4793 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4794 | } catch (ImsException e) { |
| 4795 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(token); |
| 4798 | } |
| 4799 | } |
| 4800 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4801 | /** |
| 4802 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4803 | * @param subId The subscription to use to check the configuration. |
| 4804 | * @param c The callback that will be used to send the result. |
| 4805 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4806 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4807 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4808 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4809 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4810 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4811 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4812 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4813 | |
| 4814 | final long token = Binder.clearCallingIdentity(); |
| 4815 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4816 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4817 | if (controller != null) { |
| 4818 | ImsManager imsManager = controller.getImsManager(subId); |
| 4819 | if (imsManager != null) { |
| 4820 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4821 | } else { |
| 4822 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4823 | + " is inactive, ignoring unregister."); |
| 4824 | // If the ImsManager is not valid, just return, since the callback |
| 4825 | // will already have been removed internally. |
| 4826 | } |
| 4827 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4828 | } finally { |
| 4829 | Binder.restoreCallingIdentity(token); |
| 4830 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4834 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4835 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4836 | |
| 4837 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4838 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4839 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4840 | final long token = Binder.clearCallingIdentity(); |
| 4841 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4842 | int slotId = getSlotIndexOrException(subId); |
| 4843 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4844 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4845 | } catch (com.android.ims.ImsException e) { |
| 4846 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4847 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4848 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4849 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4850 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4851 | } finally { |
| 4852 | Binder.restoreCallingIdentity(token); |
| 4853 | } |
| 4854 | } |
| 4855 | |
| 4856 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4857 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4858 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4859 | |
| 4860 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4861 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4862 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4863 | final long token = Binder.clearCallingIdentity(); |
| 4864 | try { |
| 4865 | Phone phone = getPhone(subId); |
| 4866 | if (phone == null) return false; |
| 4867 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4868 | } catch (com.android.ims.ImsException e) { |
| 4869 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4870 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(token); |
| 4873 | } |
| 4874 | } |
| 4875 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4876 | /** |
| 4877 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4878 | * subscription. |
| 4879 | * @param subId The subscription to use to check the configuration. |
| 4880 | * @param callback The callback that will be used to send the result. |
| 4881 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4882 | * @param transportType The transport type of the MmTelFeature capability. |
| 4883 | */ |
| 4884 | @Override |
| 4885 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4886 | int transportType) { |
| 4887 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4888 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4889 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4890 | "IMS not available on device."); |
| 4891 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4892 | final long token = Binder.clearCallingIdentity(); |
| 4893 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4894 | int slotId = getSlotIndex(subId); |
| 4895 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4896 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4897 | + subId + "'"); |
| 4898 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4899 | } |
| 4900 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4901 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4902 | transportType, aBoolean -> { |
| 4903 | try { |
| 4904 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4905 | } catch (RemoteException e) { |
| 4906 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4907 | + "running. Ignore"); |
| 4908 | } |
| 4909 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4910 | } catch (ImsException e) { |
| 4911 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4912 | } finally { |
| 4913 | Binder.restoreCallingIdentity(token); |
| 4914 | } |
| 4915 | } |
| 4916 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4917 | /** |
| 4918 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4919 | * @param subId The subscription to use to check the configuration. |
| 4920 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4921 | @Override |
| 4922 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4923 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4924 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4925 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4926 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4927 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4928 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4929 | final long token = Binder.clearCallingIdentity(); |
| 4930 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4931 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4932 | // 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] | 4933 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4934 | } catch (ImsException e) { |
| 4935 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4936 | } finally { |
| 4937 | Binder.restoreCallingIdentity(token); |
| 4938 | } |
| 4939 | } |
| 4940 | |
| 4941 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4942 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4944 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4945 | |
| 4946 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4947 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 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. The |
| 4953 | // 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] | 4954 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4955 | } catch (ImsException e) { |
| 4956 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(identity); |
| 4959 | } |
| 4960 | } |
| 4961 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4962 | /** |
| 4963 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4964 | * @param subId The subscription to use to check the configuration. |
| 4965 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4966 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4967 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4968 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4969 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4970 | |
| 4971 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4972 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4973 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4974 | final long identity = Binder.clearCallingIdentity(); |
| 4975 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4976 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4977 | // 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] | 4978 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4979 | } catch (ImsException e) { |
| 4980 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4981 | } finally { |
| 4982 | Binder.restoreCallingIdentity(identity); |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4987 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4989 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4990 | |
| 4991 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4992 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 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. The |
| 4998 | // 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] | 4999 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5000 | } catch (ImsException e) { |
| 5001 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
| 5004 | } |
| 5005 | } |
| 5006 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5007 | /** |
| 5008 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5009 | * @param subId The subscription to use to check the configuration. |
| 5010 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5011 | @Override |
| 5012 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5013 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5014 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5015 | |
| 5016 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5017 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5018 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5019 | final long identity = Binder.clearCallingIdentity(); |
| 5020 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5021 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5022 | // 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] | 5023 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5024 | } catch (ImsException e) { |
| 5025 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5032 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5034 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5035 | |
| 5036 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5037 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5038 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5041 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5042 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5043 | // 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] | 5044 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5045 | } catch (ImsException e) { |
| 5046 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
| 5050 | } |
| 5051 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5052 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5053 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5054 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5055 | * @param subId The subscription to use to check the configuration. |
| 5056 | */ |
| 5057 | @Override |
| 5058 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5059 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5060 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5061 | |
| 5062 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5063 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5064 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5067 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5068 | // 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] | 5069 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5070 | } catch (ImsException e) { |
| 5071 | throw new ServiceSpecificException(e.getCode()); |
| 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | /** |
| 5078 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5079 | * Requires MODIFY_PHONE_STATE permission. |
| 5080 | * @param subId The subscription to use to check the configuration. |
| 5081 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5082 | * false otherwise |
| 5083 | */ |
| 5084 | @Override |
| 5085 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5087 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5088 | |
| 5089 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5090 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5091 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5094 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5095 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5096 | // 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] | 5097 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5098 | } catch (ImsException e) { |
| 5099 | throw new ServiceSpecificException(e.getCode()); |
| 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
| 5102 | } |
| 5103 | } |
| 5104 | |
| 5105 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5106 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5107 | * @param subId The subscription to use to check the configuration. |
| 5108 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5109 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5110 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5111 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5112 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5113 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5114 | |
| 5115 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5116 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5117 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5118 | final long identity = Binder.clearCallingIdentity(); |
| 5119 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5120 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5121 | // 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] | 5122 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5123 | } catch (ImsException e) { |
| 5124 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5131 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5133 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5134 | |
| 5135 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5136 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5137 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5138 | final long identity = Binder.clearCallingIdentity(); |
| 5139 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5140 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5141 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5142 | // 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] | 5143 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5144 | } catch (ImsException e) { |
| 5145 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5146 | } finally { |
| 5147 | Binder.restoreCallingIdentity(identity); |
| 5148 | } |
| 5149 | } |
| 5150 | |
| 5151 | @Override |
| 5152 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5154 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5155 | |
| 5156 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5157 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5158 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5159 | final long identity = Binder.clearCallingIdentity(); |
| 5160 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5161 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5162 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5163 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5164 | } catch (ImsException e) { |
| 5165 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(identity); |
| 5168 | } |
| 5169 | } |
| 5170 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5171 | /** |
| 5172 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5173 | * @param subId The subscription to use to check the configuration. |
| 5174 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5175 | @Override |
| 5176 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5177 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5178 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5179 | |
| 5180 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5181 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5182 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5183 | final long identity = Binder.clearCallingIdentity(); |
| 5184 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5185 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5186 | // 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] | 5187 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5188 | } catch (ImsException e) { |
| 5189 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5190 | } finally { |
| 5191 | Binder.restoreCallingIdentity(identity); |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | @Override |
| 5196 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5198 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5199 | |
| 5200 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5201 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5202 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5205 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5206 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5207 | // 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] | 5208 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5209 | } catch (ImsException e) { |
| 5210 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5211 | } finally { |
| 5212 | Binder.restoreCallingIdentity(identity); |
| 5213 | } |
| 5214 | } |
| 5215 | |
| 5216 | @Override |
| 5217 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5218 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5219 | |
| 5220 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5221 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5222 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5225 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5226 | // 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] | 5227 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5228 | } catch (ImsException e) { |
| 5229 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | @Override |
| 5236 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5238 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5239 | |
| 5240 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5241 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5242 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5243 | final long identity = Binder.clearCallingIdentity(); |
| 5244 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5245 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5246 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5247 | // 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] | 5248 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5249 | } catch (ImsException e) { |
| 5250 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5251 | } finally { |
| 5252 | Binder.restoreCallingIdentity(identity); |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | @Override |
| 5257 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5258 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5259 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5260 | |
| 5261 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5262 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 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. The |
| 5268 | // 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] | 5269 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5270 | } catch (ImsException e) { |
| 5271 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5272 | } finally { |
| 5273 | Binder.restoreCallingIdentity(identity); |
| 5274 | } |
| 5275 | } |
| 5276 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5277 | /** |
| 5278 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5279 | * @param subId The subscription to use to check the configuration. |
| 5280 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5281 | @Override |
| 5282 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5283 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5284 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5285 | |
| 5286 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5287 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5288 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5289 | final long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5291 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5292 | // 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] | 5293 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5294 | } catch (ImsException e) { |
| 5295 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
| 5298 | } |
| 5299 | } |
| 5300 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5301 | @Override |
| 5302 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5303 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5304 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5305 | final long identity = Binder.clearCallingIdentity(); |
| 5306 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5307 | if (!isImsAvailableOnDevice()) { |
| 5308 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5309 | "IMS not available on device."); |
| 5310 | } |
| 5311 | int slotId = getSlotIndexOrException(subId); |
| 5312 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5313 | |
| 5314 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5315 | if (controller != null) { |
| 5316 | ImsManager imsManager = controller.getImsManager(subId); |
| 5317 | if (imsManager != null) { |
| 5318 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5319 | } else { |
| 5320 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5321 | } |
| 5322 | } else { |
| 5323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5324 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5325 | } catch (ImsException e) { |
| 5326 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
| 5330 | } |
| 5331 | |
| 5332 | @Override |
| 5333 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5334 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5335 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5336 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5337 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5338 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5339 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5340 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5341 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5342 | if (controller != null) { |
| 5343 | ImsManager imsManager = controller.getImsManager(subId); |
| 5344 | if (imsManager != null) { |
| 5345 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5346 | } else { |
| 5347 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5348 | + " is inactive, ignoring unregister."); |
| 5349 | // If the ImsManager is not valid, just return, since the callback will already |
| 5350 | // have been removed internally. |
| 5351 | } |
| 5352 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
| 5355 | } |
| 5356 | } |
| 5357 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5358 | @Override |
| 5359 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5360 | IFeatureProvisioningCallback callback) { |
| 5361 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5362 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5363 | |
| 5364 | final long identity = Binder.clearCallingIdentity(); |
| 5365 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5366 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5367 | } |
| 5368 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5369 | try { |
| 5370 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5371 | if (controller == null) { |
| 5372 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5373 | "Device does not support IMS"); |
| 5374 | } |
| 5375 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5376 | } finally { |
| 5377 | Binder.restoreCallingIdentity(identity); |
| 5378 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | @Override |
| 5382 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5383 | IFeatureProvisioningCallback callback) { |
| 5384 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5385 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5386 | |
| 5387 | final long identity = Binder.clearCallingIdentity(); |
| 5388 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5389 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5390 | } |
| 5391 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5392 | try { |
| 5393 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5394 | if (controller == null) { |
| 5395 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5396 | return; |
| 5397 | } |
| 5398 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5399 | } finally { |
| 5400 | Binder.restoreCallingIdentity(identity); |
| 5401 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5402 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5403 | |
| 5404 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5406 | message); |
| 5407 | } |
| 5408 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5409 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5410 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5411 | boolean isProvisioned) { |
| 5412 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5413 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5414 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5415 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5416 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5419 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5420 | if (controller == null) { |
| 5421 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5422 | return; |
| 5423 | } |
| 5424 | controller.setRcsProvisioningStatusForCapability( |
| 5425 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | |
| 5432 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5433 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5434 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5435 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5436 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5437 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5438 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5439 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5440 | final long identity = Binder.clearCallingIdentity(); |
| 5441 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5442 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5443 | if (controller == null) { |
| 5444 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5445 | |
| 5446 | // device does not support IMS, this method will return true always. |
| 5447 | return true; |
| 5448 | } |
| 5449 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5450 | } finally { |
| 5451 | Binder.restoreCallingIdentity(identity); |
| 5452 | } |
| 5453 | } |
| 5454 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5455 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5456 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5457 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5458 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5459 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5460 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5461 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5462 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5463 | final long identity = Binder.clearCallingIdentity(); |
| 5464 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5465 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5466 | if (controller == null) { |
| 5467 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5468 | return; |
| 5469 | } |
| 5470 | controller.setImsProvisioningStatusForCapability( |
| 5471 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | @Override |
| 5478 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5479 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5480 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5481 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5482 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5483 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5484 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5485 | final long identity = Binder.clearCallingIdentity(); |
| 5486 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5487 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5488 | if (controller == null) { |
| 5489 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5490 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5491 | // device does not support IMS, this method will return true always. |
| 5492 | return true; |
| 5493 | } |
| 5494 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5501 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5502 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5503 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5504 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5505 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5506 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5507 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5510 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5511 | if (controller == null) { |
| 5512 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5513 | |
| 5514 | // device does not support IMS, this method will return false |
| 5515 | return false; |
| 5516 | } |
| 5517 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5520 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5524 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5525 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5526 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5527 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5528 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5529 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5530 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5531 | final long identity = Binder.clearCallingIdentity(); |
| 5532 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5533 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5534 | if (controller == null) { |
| 5535 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5536 | |
| 5537 | // device does not support IMS, this method will return false |
| 5538 | return false; |
| 5539 | } |
| 5540 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5541 | } finally { |
| 5542 | Binder.restoreCallingIdentity(identity); |
| 5543 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5544 | } |
| 5545 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5546 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5547 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5548 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5549 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5550 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5551 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5552 | mApp, subId, "getImsProvisioningInt"); |
| 5553 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5554 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5555 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5556 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
| 5559 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5560 | int slotId = getSlotIndex(subId); |
| 5561 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5562 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5563 | + subId + "' for key:" + key); |
| 5564 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5565 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5566 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5567 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5568 | if (controller == null) { |
| 5569 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5570 | |
| 5571 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5572 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5573 | } |
| 5574 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5575 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5576 | return retVal; |
| 5577 | } |
| 5578 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5579 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5580 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5581 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5582 | + subId + "' for key:" + key); |
| 5583 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5584 | } finally { |
| 5585 | Binder.restoreCallingIdentity(identity); |
| 5586 | } |
| 5587 | } |
| 5588 | |
| 5589 | @Override |
| 5590 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5591 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5592 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5593 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5594 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5595 | mApp, subId, "getImsProvisioningString"); |
| 5596 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5597 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5598 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5599 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5600 | final long identity = Binder.clearCallingIdentity(); |
| 5601 | try { |
| 5602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5603 | int slotId = getSlotIndex(subId); |
| 5604 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5605 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5606 | + subId + "' for key:" + key); |
| 5607 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5608 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5609 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5610 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5611 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5612 | + subId + "' for key:" + key); |
| 5613 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | @Override |
| 5620 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5621 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5622 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5623 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5625 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5626 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5627 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5628 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5629 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5633 | int slotId = getSlotIndex(subId); |
| 5634 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5635 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5636 | + subId + "' for key:" + key); |
| 5637 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5638 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5639 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5640 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5641 | if (controller == null) { |
| 5642 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5643 | |
| 5644 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5645 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5646 | } |
| 5647 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5648 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5649 | return retVal; |
| 5650 | } |
| 5651 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5652 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5653 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5654 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5655 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5656 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5657 | } finally { |
| 5658 | Binder.restoreCallingIdentity(identity); |
| 5659 | } |
| 5660 | } |
| 5661 | |
| 5662 | @Override |
| 5663 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5664 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5665 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5666 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5668 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5669 | |
| 5670 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5671 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5672 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5673 | final long identity = Binder.clearCallingIdentity(); |
| 5674 | try { |
| 5675 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5676 | int slotId = getSlotIndex(subId); |
| 5677 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5678 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5679 | + subId + "' for key:" + key); |
| 5680 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5681 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5682 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5683 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5684 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5685 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5686 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
| 5689 | } |
| 5690 | } |
| 5691 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5692 | /** |
| 5693 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5694 | * for the given slot ID or no ImsResolver instance has been created. |
| 5695 | * @param slotId The slot ID that the IMS service is created for. |
| 5696 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5697 | */ |
| 5698 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5699 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5700 | ImsFeature.FEATURE_MMTEL)) { |
| 5701 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5702 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5703 | } |
| 5704 | } |
| 5705 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5706 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5707 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5708 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5709 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5710 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5711 | } |
| 5712 | return slotId; |
| 5713 | } |
| 5714 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5715 | private int getSlotIndex(int subId) { |
| 5716 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5717 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5718 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5719 | } |
| 5720 | return slotId; |
| 5721 | } |
| 5722 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5723 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5724 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5725 | */ |
| 5726 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5727 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5728 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5729 | try { |
| 5730 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5731 | } catch (SecurityException se) { |
| 5732 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5733 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5734 | + Binder.getCallingUid()); |
| 5735 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5736 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5737 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5738 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5739 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5740 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5741 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5742 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5743 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5744 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5745 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5746 | enforceTelephonyFeatureWithException(callingPackage, |
| 5747 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
| 5751 | final Phone phone = getPhone(subId); |
| 5752 | if (phone != null) { |
| 5753 | return phone.getServiceState().getDataNetworkType(); |
| 5754 | } else { |
| 5755 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5756 | } |
| 5757 | } finally { |
| 5758 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5759 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | /** |
| 5763 | * Returns the data network type |
| 5764 | */ |
| 5765 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5766 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5767 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5768 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | /** |
| 5772 | * Returns the data network type for a subId |
| 5773 | */ |
| 5774 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5775 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5776 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5777 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5778 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5779 | mApp, functionName)) { |
| 5780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5781 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5782 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5783 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5786 | enforceTelephonyFeatureWithException(callingPackage, |
| 5787 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5788 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5789 | final long identity = Binder.clearCallingIdentity(); |
| 5790 | try { |
| 5791 | final Phone phone = getPhone(subId); |
| 5792 | if (phone != null) { |
| 5793 | return phone.getServiceState().getDataNetworkType(); |
| 5794 | } else { |
| 5795 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5796 | } |
| 5797 | } finally { |
| 5798 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5799 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5803 | * Returns the Voice network type for a subId |
| 5804 | */ |
| 5805 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5806 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5807 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5808 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5809 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5810 | mApp, functionName)) { |
| 5811 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5812 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5813 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5814 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5817 | enforceTelephonyFeatureWithException(callingPackage, |
| 5818 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5819 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5820 | final long identity = Binder.clearCallingIdentity(); |
| 5821 | try { |
| 5822 | final Phone phone = getPhone(subId); |
| 5823 | if (phone != null) { |
| 5824 | return phone.getServiceState().getVoiceNetworkType(); |
| 5825 | } else { |
| 5826 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5827 | } |
| 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | /** |
| 5834 | * @return true if a ICC card is present |
| 5835 | */ |
| 5836 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5837 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5838 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5839 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5843 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5844 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5845 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5846 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5847 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5848 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5849 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5850 | final long identity = Binder.clearCallingIdentity(); |
| 5851 | try { |
| 5852 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5853 | if (phone != null) { |
| 5854 | return phone.getIccCard().hasIccCard(); |
| 5855 | } else { |
| 5856 | return false; |
| 5857 | } |
| 5858 | } finally { |
| 5859 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5860 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | /** |
| 5864 | * Return if the current radio is LTE on CDMA. This |
| 5865 | * is a tri-state return value as for a period of time |
| 5866 | * the mode may be unknown. |
| 5867 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5868 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5869 | * @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] | 5870 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5871 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5872 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5873 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5874 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5875 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5876 | } |
| 5877 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5878 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5879 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5880 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5881 | try { |
| 5882 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5883 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5884 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5885 | } |
| 5886 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5887 | enforceTelephonyFeatureWithException(callingPackage, |
| 5888 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5889 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | final long identity = Binder.clearCallingIdentity(); |
| 5891 | try { |
| 5892 | final Phone phone = getPhone(subId); |
| 5893 | if (phone == null) { |
| 5894 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5895 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5896 | return TelephonyProperties.lte_on_cdma_device() |
| 5897 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | } |
| 5899 | } finally { |
| 5900 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5901 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5902 | } |
| 5903 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5904 | /** |
| 5905 | * {@hide} |
| 5906 | * Returns Default subId, 0 in the case of single standby. |
| 5907 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5908 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5909 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5912 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5913 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5916 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5917 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5918 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5919 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5920 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5921 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5922 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5925 | /** |
| 5926 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5927 | */ |
| 5928 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5931 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5933 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
| 5936 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | /** |
| 5940 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5941 | */ |
| 5942 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | final long identity = Binder.clearCallingIdentity(); |
| 5944 | try { |
| 5945 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5946 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5948 | } finally { |
| 5949 | Binder.restoreCallingIdentity(identity); |
| 5950 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5951 | } |
| 5952 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5953 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5954 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5955 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5956 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5957 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5958 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5959 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5960 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5961 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5962 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5963 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5964 | } |
| 5965 | return PhoneFactory.getPhone(phoneId); |
| 5966 | } |
| 5967 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5968 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5969 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5970 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5971 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5972 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5973 | /*message=*/ "iccOpenLogicalChannel"); |
| 5974 | |
| 5975 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5976 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5977 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5978 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5979 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5980 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5981 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5982 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5983 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5984 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5985 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5986 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5987 | Phone phone; |
| 5988 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5990 | mApp, request.subId, message); |
| 5991 | phone = getPhoneFromSubId(request.subId); |
| 5992 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5993 | enforceModifyPermission(); |
| 5994 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5995 | } else { |
| 5996 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5997 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5998 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6002 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | final long identity = Binder.clearCallingIdentity(); |
| 6004 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6005 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6007 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6008 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6009 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6010 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | loge("The calling package is not allowed to access ISD-R."); |
| 6012 | throw new SecurityException( |
| 6013 | "The calling package is not allowed to access ISD-R."); |
| 6014 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6015 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6018 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6019 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | return response; |
| 6021 | } finally { |
| 6022 | Binder.restoreCallingIdentity(identity); |
| 6023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6027 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6028 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6029 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6030 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6031 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6032 | /*message=*/"iccCloseLogicalChannel"); |
| 6033 | |
| 6034 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6035 | |
| 6036 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6037 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6038 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6039 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6040 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6041 | // before this feature is enabled, this API should only return false if |
| 6042 | // the operation fails instead of throwing runtime exception for |
| 6043 | // backward-compatibility. |
| 6044 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6045 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6048 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6049 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6051 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6052 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6053 | Boolean success = false; |
| 6054 | if (result instanceof RuntimeException) { |
| 6055 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6056 | if (shouldThrowExceptionOnFailure) { |
| 6057 | throw (RuntimeException) result; |
| 6058 | } else { |
| 6059 | return false; |
| 6060 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6061 | } else if (result instanceof Boolean) { |
| 6062 | success = (Boolean) result; |
| 6063 | } else { |
| 6064 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6065 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6066 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | return success; |
| 6068 | } finally { |
| 6069 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6070 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6074 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6075 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6077 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6078 | |
| 6079 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6080 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6081 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6082 | if (DBG) { |
| 6083 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6084 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6085 | + p3 + " data=" + data); |
| 6086 | } |
| 6087 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6088 | command, p1, p2, p3, data); |
| 6089 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6090 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6091 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6092 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6093 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6094 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6095 | |
| 6096 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6097 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6098 | "iccTransmitApduLogicalChannelBySlot"); |
| 6099 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6100 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6101 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6102 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6103 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6104 | } |
| 6105 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6106 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6107 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6111 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6114 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | return ""; |
| 6116 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6117 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6119 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6120 | null /* workSource */); |
| 6121 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6122 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | // Append the returned status code to the end of the response payload. |
| 6124 | String s = Integer.toHexString( |
| 6125 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6126 | if (response.payload != null) { |
| 6127 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6128 | } |
| 6129 | return s; |
| 6130 | } finally { |
| 6131 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6132 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6133 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6134 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6135 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6136 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6137 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6139 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6141 | |
| 6142 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6143 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6144 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6145 | if (DBG) { |
| 6146 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6147 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6148 | } |
| 6149 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6150 | cla, command, p1, p2, p3, data); |
| 6151 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6152 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6153 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6154 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6155 | 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] | 6156 | enforceModifyPermission(); |
| 6157 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6158 | |
| 6159 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6160 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6161 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6162 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6163 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6164 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6165 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6169 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6170 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6174 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6175 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6176 | final long identity = Binder.clearCallingIdentity(); |
| 6177 | try { |
| 6178 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6179 | && TextUtils.equals(ISDR_AID, data)) { |
| 6180 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6181 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6182 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | if (bestComponent == null |
| 6184 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6185 | loge("The calling package is not allowed to select ISD-R."); |
| 6186 | throw new SecurityException( |
| 6187 | "The calling package is not allowed to select ISD-R."); |
| 6188 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6189 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6190 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6192 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6193 | null /* workSource */); |
| 6194 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | // Append the returned status code to the end of the response payload. |
| 6197 | String s = Integer.toHexString( |
| 6198 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6199 | if (response.payload != null) { |
| 6200 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6201 | } |
| 6202 | return s; |
| 6203 | } finally { |
| 6204 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6205 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6209 | 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] | 6210 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6211 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6212 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6213 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6214 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6215 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6217 | final long identity = Binder.clearCallingIdentity(); |
| 6218 | try { |
| 6219 | if (DBG) { |
| 6220 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6221 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6222 | } |
| 6223 | |
| 6224 | IccIoResult response = |
| 6225 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6226 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6227 | subId); |
| 6228 | |
| 6229 | if (DBG) { |
| 6230 | log("Exchange SIM_IO [R]" + response); |
| 6231 | } |
| 6232 | |
| 6233 | byte[] result = null; |
| 6234 | int length = 2; |
| 6235 | if (response.payload != null) { |
| 6236 | length = 2 + response.payload.length; |
| 6237 | result = new byte[length]; |
| 6238 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6239 | } else { |
| 6240 | result = new byte[length]; |
| 6241 | } |
| 6242 | |
| 6243 | result[length - 1] = (byte) response.sw2; |
| 6244 | result[length - 2] = (byte) response.sw1; |
| 6245 | return result; |
| 6246 | } finally { |
| 6247 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6248 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6249 | } |
| 6250 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6251 | /** |
| 6252 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6253 | * on a particular subscription |
| 6254 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6255 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6256 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6258 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6259 | return null; |
| 6260 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6262 | enforceTelephonyFeatureWithException(callingPackage, |
| 6263 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | final long identity = Binder.clearCallingIdentity(); |
| 6266 | try { |
| 6267 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6268 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6269 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6270 | return null; |
| 6271 | } |
| 6272 | Object response = sendRequest( |
| 6273 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6274 | if (response instanceof String[]) { |
| 6275 | return (String[]) response; |
| 6276 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6277 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6279 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6282 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6283 | } |
| 6284 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6285 | /** |
| 6286 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6287 | * subscription. |
| 6288 | * |
| 6289 | * @param subId the id of the subscription. |
| 6290 | * @param appType the uicc app type, must be USIM or SIM. |
| 6291 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6292 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6293 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6294 | * @return number of fplmns that is successfully written to the SIM. |
| 6295 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6296 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6297 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6298 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6299 | mApp, subId, "setForbiddenPlmns"); |
| 6300 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6301 | enforceTelephonyFeatureWithException(callingPackage, |
| 6302 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6303 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6304 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6305 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6306 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6307 | } |
| 6308 | if (fplmns == null) { |
| 6309 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6310 | } |
| 6311 | for (String fplmn : fplmns) { |
| 6312 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6313 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6314 | } |
| 6315 | } |
| 6316 | final long identity = Binder.clearCallingIdentity(); |
| 6317 | try { |
| 6318 | Object response = sendRequest( |
| 6319 | CMD_SET_FORBIDDEN_PLMNS, |
| 6320 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6321 | subId); |
| 6322 | return (int) response; |
| 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
| 6325 | } |
| 6326 | } |
| 6327 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6328 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6329 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6330 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6331 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6332 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6333 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6334 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6339 | if (response.payload == null) { |
| 6340 | return ""; |
| 6341 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6343 | // Append the returned status code to the end of the response payload. |
| 6344 | String s = Integer.toHexString( |
| 6345 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6346 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6347 | return s; |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6351 | } |
| 6352 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6353 | /** |
| 6354 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6355 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6356 | * |
| 6357 | * @param itemID the ID of the item to read |
| 6358 | * @return the NV item as a String, or null on error. |
| 6359 | */ |
| 6360 | @Override |
| 6361 | public String nvReadItem(int itemID) { |
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(), "nvReadItem"); |
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("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6369 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6370 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6371 | return value; |
| 6372 | } finally { |
| 6373 | Binder.restoreCallingIdentity(identity); |
| 6374 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | /** |
| 6378 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6379 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6380 | * |
| 6381 | * @param itemID the ID of the item to read |
| 6382 | * @param itemValue the value to write, as a String |
| 6383 | * @return true on success; false on any failure |
| 6384 | */ |
| 6385 | @Override |
| 6386 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6387 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6389 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | |
| 6391 | final long identity = Binder.clearCallingIdentity(); |
| 6392 | try { |
| 6393 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6394 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6395 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6396 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6397 | return success; |
| 6398 | } finally { |
| 6399 | Binder.restoreCallingIdentity(identity); |
| 6400 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | /** |
| 6404 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6405 | * Used for device configuration by some CDMA operators. |
| 6406 | * |
| 6407 | * @param preferredRoamingList byte array containing the new PRL |
| 6408 | * @return true on success; false on any failure |
| 6409 | */ |
| 6410 | @Override |
| 6411 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6413 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | |
| 6415 | final long identity = Binder.clearCallingIdentity(); |
| 6416 | try { |
| 6417 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6418 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6419 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6420 | return success; |
| 6421 | } finally { |
| 6422 | Binder.restoreCallingIdentity(identity); |
| 6423 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6427 | * 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] | 6428 | * Used for device configuration by some CDMA operators. |
| 6429 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6430 | * @param slotIndex - device slot. |
| 6431 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6432 | * @return true on success; false on any failure |
| 6433 | */ |
| 6434 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6435 | public boolean resetModemConfig(int slotIndex) { |
| 6436 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6437 | if (phone != null) { |
| 6438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6439 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6440 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6441 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6442 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6443 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6444 | final long identity = Binder.clearCallingIdentity(); |
| 6445 | try { |
| 6446 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6447 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6448 | return success; |
| 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
| 6451 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6452 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6453 | return false; |
| 6454 | } |
| 6455 | |
| 6456 | /** |
| 6457 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6458 | * |
| 6459 | * @param slotIndex - device slot. |
| 6460 | * |
| 6461 | * @return true on success; false on any failure |
| 6462 | */ |
| 6463 | @Override |
| 6464 | public boolean rebootModem(int slotIndex) { |
| 6465 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6466 | if (phone != null) { |
| 6467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6468 | mApp, phone.getSubId(), "rebootModem"); |
| 6469 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6470 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6471 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6472 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6476 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6477 | return success; |
| 6478 | } finally { |
| 6479 | Binder.restoreCallingIdentity(identity); |
| 6480 | } |
| 6481 | } |
| 6482 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6483 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6484 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6485 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6486 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6487 | * {@link #disableIms(int)}. |
| 6488 | * @param slotIndex device slot. |
| 6489 | */ |
| 6490 | public void resetIms(int slotIndex) { |
| 6491 | enforceModifyPermission(); |
| 6492 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6493 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6494 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6495 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6496 | final long identity = Binder.clearCallingIdentity(); |
| 6497 | try { |
| 6498 | if (mImsResolver == null) { |
| 6499 | // may happen if the does not support IMS. |
| 6500 | return; |
| 6501 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6502 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6509 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6510 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6511 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6512 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6513 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6514 | |
| 6515 | final long identity = Binder.clearCallingIdentity(); |
| 6516 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6517 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6518 | // may happen if the device does not support IMS. |
| 6519 | return; |
| 6520 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6521 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6522 | } finally { |
| 6523 | Binder.restoreCallingIdentity(identity); |
| 6524 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6525 | } |
| 6526 | |
| 6527 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6528 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6529 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6530 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6531 | public void disableIms(int slotId) { |
| 6532 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6533 | |
| 6534 | final long identity = Binder.clearCallingIdentity(); |
| 6535 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6536 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6537 | // may happen if the device does not support IMS. |
| 6538 | return; |
| 6539 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6540 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6547 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6548 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6549 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6550 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6551 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6552 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | |
| 6554 | final long identity = Binder.clearCallingIdentity(); |
| 6555 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6557 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6558 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6559 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6560 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6564 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6565 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6566 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6567 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6568 | @Override |
| 6569 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6570 | enforceModifyPermission(); |
| 6571 | |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | try { |
| 6574 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6575 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6576 | } finally { |
| 6577 | Binder.restoreCallingIdentity(identity); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6582 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6583 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6584 | */ |
| 6585 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6586 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6587 | |
| 6588 | final long identity = Binder.clearCallingIdentity(); |
| 6589 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6590 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6591 | // may happen if the device does not support IMS. |
| 6592 | return null; |
| 6593 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6594 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6595 | } finally { |
| 6596 | Binder.restoreCallingIdentity(identity); |
| 6597 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6598 | } |
| 6599 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6600 | /** |
| 6601 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6602 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6603 | */ |
| 6604 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6606 | |
| 6607 | final long identity = Binder.clearCallingIdentity(); |
| 6608 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6609 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6610 | // may happen if the device does not support IMS. |
| 6611 | return null; |
| 6612 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6613 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6614 | } finally { |
| 6615 | Binder.restoreCallingIdentity(identity); |
| 6616 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6617 | } |
| 6618 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6619 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6620 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6621 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6622 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6623 | * @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] | 6624 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6625 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6626 | * @param packageName The name of the package that the current configuration will be replaced |
| 6627 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6628 | * @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] | 6629 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6630 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6631 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6632 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6634 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6638 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6639 | // may happen if the device does not support IMS. |
| 6640 | return false; |
| 6641 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6642 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6643 | for (int featureType : featureTypes) { |
| 6644 | featureConfig.put(featureType, packageName); |
| 6645 | } |
| 6646 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6647 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | } finally { |
| 6649 | Binder.restoreCallingIdentity(identity); |
| 6650 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6654 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6655 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6656 | * |
| 6657 | * This should only be used for testing. |
| 6658 | * |
| 6659 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6660 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6661 | */ |
| 6662 | @Override |
| 6663 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6664 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6665 | "clearCarrierImsServiceOverride"); |
| 6666 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6667 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6668 | |
| 6669 | final long identity = Binder.clearCallingIdentity(); |
| 6670 | try { |
| 6671 | if (mImsResolver == null) { |
| 6672 | // may happen if the device does not support IMS. |
| 6673 | return false; |
| 6674 | } |
| 6675 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6676 | } finally { |
| 6677 | Binder.restoreCallingIdentity(identity); |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6682 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6683 | * |
| 6684 | * @param slotId The slot that the ImsService is associated with. |
| 6685 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6686 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6687 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6688 | * @return the package name of the ImsService configuration. |
| 6689 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6690 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6691 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6692 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6693 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6694 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6695 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | final long identity = Binder.clearCallingIdentity(); |
| 6697 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6698 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6699 | // may happen if the device does not support IMS. |
| 6700 | return ""; |
| 6701 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6702 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6703 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6704 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | } finally { |
| 6706 | Binder.restoreCallingIdentity(identity); |
| 6707 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6708 | } |
| 6709 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6710 | /** |
| 6711 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6712 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6713 | * @param callback A callback with an integer containing the |
| 6714 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6715 | */ |
| 6716 | @Override |
| 6717 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6718 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6719 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6720 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6721 | "IMS not available on device."); |
| 6722 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6723 | final long token = Binder.clearCallingIdentity(); |
| 6724 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6725 | int slotId = getSlotIndex(subId); |
| 6726 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6727 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6728 | + subId + "'"); |
| 6729 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6730 | } |
| 6731 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6732 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6733 | try { |
| 6734 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6735 | } catch (RemoteException e) { |
| 6736 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6737 | + "Ignore"); |
| 6738 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6739 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6740 | } catch (ImsException e) { |
| 6741 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6742 | } finally { |
| 6743 | Binder.restoreCallingIdentity(token); |
| 6744 | } |
| 6745 | } |
| 6746 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6747 | /** |
| 6748 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6749 | */ |
| 6750 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6751 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | |
| 6753 | final long identity = Binder.clearCallingIdentity(); |
| 6754 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6755 | // NOTE: Before S, this method only set the default phone. |
| 6756 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6757 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6758 | phone.setImsRegistrationState(registered); |
| 6759 | } |
| 6760 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(identity); |
| 6763 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6764 | } |
| 6765 | |
| 6766 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6767 | * Set the network selection mode to automatic. |
| 6768 | * |
| 6769 | */ |
| 6770 | @Override |
| 6771 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6773 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6775 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6776 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6778 | final long identity = Binder.clearCallingIdentity(); |
| 6779 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6780 | if (!isActiveSubscription(subId)) { |
| 6781 | return; |
| 6782 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6783 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6784 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6785 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
| 6788 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6789 | } |
| 6790 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6791 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6792 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6793 | * |
| 6794 | * @param subId the id of the subscription. |
| 6795 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6796 | * the operator to attach to. |
| 6797 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6798 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6799 | * normal network selection next time. |
| 6800 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6801 | */ |
| 6802 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6803 | public boolean setNetworkSelectionModeManual( |
| 6804 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6806 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6807 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6808 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6809 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6810 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6811 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6812 | if (!isActiveSubscription(subId)) { |
| 6813 | return false; |
| 6814 | } |
| 6815 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6817 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6819 | if (DBG) { |
| 6820 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6821 | + " operator: " + operatorInfo); |
| 6822 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6824 | } finally { |
| 6825 | Binder.restoreCallingIdentity(identity); |
| 6826 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6827 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6828 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6829 | * Get the manual network selection |
| 6830 | * |
| 6831 | * @param subId the id of the subscription. |
| 6832 | * |
| 6833 | * @return the previously saved user selected PLMN |
| 6834 | */ |
| 6835 | @Override |
| 6836 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6837 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6838 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6839 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6840 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6841 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6842 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6843 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6844 | final long identity = Binder.clearCallingIdentity(); |
| 6845 | try { |
| 6846 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6847 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | final Phone phone = getPhone(subId); |
| 6851 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6852 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6853 | } |
| 6854 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6855 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6856 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6857 | } finally { |
| 6858 | Binder.restoreCallingIdentity(identity); |
| 6859 | } |
| 6860 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6861 | |
| 6862 | /** |
| 6863 | * Scans for available networks. |
| 6864 | */ |
| 6865 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6866 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6867 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6869 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6870 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6871 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6872 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6873 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6874 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6875 | .setCallingPid(Binder.getCallingPid()) |
| 6876 | .setCallingUid(Binder.getCallingUid()) |
| 6877 | .setMethod("getCellNetworkScanResults") |
| 6878 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6879 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6880 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6881 | .build()); |
| 6882 | switch (locationResult) { |
| 6883 | case DENIED_HARD: |
| 6884 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6885 | case DENIED_SOFT: |
| 6886 | return null; |
| 6887 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6889 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6890 | try { |
| 6891 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6892 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6893 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
| 6899 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6900 | * Get the call forwarding info, given the call forwarding reason. |
| 6901 | */ |
| 6902 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6903 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6904 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6905 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6906 | |
| 6907 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6908 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6909 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6910 | long identity = Binder.clearCallingIdentity(); |
| 6911 | try { |
| 6912 | if (DBG) { |
| 6913 | log("getCallForwarding: subId " + subId |
| 6914 | + " callForwardingReason" + callForwardingReason); |
| 6915 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6916 | |
| 6917 | Phone phone = getPhone(subId); |
| 6918 | if (phone == null) { |
| 6919 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6920 | callback.onError( |
| 6921 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6922 | } catch (RemoteException e) { |
| 6923 | // ignore |
| 6924 | } |
| 6925 | return; |
| 6926 | } |
| 6927 | |
| 6928 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6929 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6930 | @Override |
| 6931 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6932 | try { |
| 6933 | callback.onCallForwardingInfoAvailable(info); |
| 6934 | } catch (RemoteException e) { |
| 6935 | // ignore |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | @Override |
| 6940 | public void onError(int error) { |
| 6941 | try { |
| 6942 | callback.onError(error); |
| 6943 | } catch (RemoteException e) { |
| 6944 | // ignore |
| 6945 | } |
| 6946 | } |
| 6947 | }); |
| 6948 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
| 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | /** |
| 6955 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6956 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6957 | */ |
| 6958 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6959 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6960 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6961 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6962 | |
| 6963 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6964 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6965 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6966 | long identity = Binder.clearCallingIdentity(); |
| 6967 | try { |
| 6968 | if (DBG) { |
| 6969 | log("setCallForwarding: subId " + subId |
| 6970 | + " callForwardingInfo" + callForwardingInfo); |
| 6971 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6972 | |
| 6973 | Phone phone = getPhone(subId); |
| 6974 | if (phone == null) { |
| 6975 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6976 | callback.accept( |
| 6977 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6978 | } catch (RemoteException e) { |
| 6979 | // ignore |
| 6980 | } |
| 6981 | return; |
| 6982 | } |
| 6983 | |
| 6984 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6985 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6986 | |
| 6987 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6988 | } finally { |
| 6989 | Binder.restoreCallingIdentity(identity); |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6994 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6995 | */ |
| 6996 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6997 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6998 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6999 | |
| 7000 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7001 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7002 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7003 | long identity = Binder.clearCallingIdentity(); |
| 7004 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7005 | Phone phone = getPhone(subId); |
| 7006 | if (phone == null) { |
| 7007 | try { |
| 7008 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7009 | } catch (RemoteException e) { |
| 7010 | // ignore |
| 7011 | } |
| 7012 | return; |
| 7013 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7014 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7015 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7016 | boolean requireUssd = c.getBoolean( |
| 7017 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7018 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7019 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7020 | if (requireUssd) { |
| 7021 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7022 | getSubscriptionCarrierId(subId)); |
| 7023 | String newUssdCommand = ""; |
| 7024 | try { |
| 7025 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7026 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7027 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7028 | } catch (NullPointerException e) { |
| 7029 | loge("Failed to generate USSD number" + e); |
| 7030 | } |
| 7031 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7032 | mMainThreadHandler, callback, carrierXmlParser, |
| 7033 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7034 | final String ussdCommand = newUssdCommand; |
| 7035 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7036 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7037 | }); |
| 7038 | } else { |
| 7039 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7040 | callback::accept); |
| 7041 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7042 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7043 | } finally { |
| 7044 | Binder.restoreCallingIdentity(identity); |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7049 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7050 | */ |
| 7051 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7052 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7053 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7054 | |
| 7055 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7056 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7057 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7058 | long identity = Binder.clearCallingIdentity(); |
| 7059 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7060 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7061 | |
| 7062 | Phone phone = getPhone(subId); |
| 7063 | if (phone == null) { |
| 7064 | try { |
| 7065 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7066 | } catch (RemoteException e) { |
| 7067 | // ignore |
| 7068 | } |
| 7069 | return; |
| 7070 | } |
| 7071 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7072 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7073 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7074 | boolean requireUssd = c.getBoolean( |
| 7075 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7076 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7077 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7078 | if (requireUssd) { |
| 7079 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7080 | getSubscriptionCarrierId(subId)); |
| 7081 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7082 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7083 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7084 | String newUssdCommand = ""; |
| 7085 | try { |
| 7086 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7087 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7088 | .makeCommand(ssAction, null); |
| 7089 | } catch (NullPointerException e) { |
| 7090 | loge("Failed to generate USSD number" + e); |
| 7091 | } |
| 7092 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7093 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7094 | final String ussdCommand = newUssdCommand; |
| 7095 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7096 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7097 | }); |
| 7098 | } else { |
| 7099 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7100 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7101 | |
| 7102 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7103 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7104 | } finally { |
| 7105 | Binder.restoreCallingIdentity(identity); |
| 7106 | } |
| 7107 | } |
| 7108 | |
| 7109 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7110 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7111 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7112 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7113 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7114 | * location related information which will be sent if the caller already possess |
| 7115 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7116 | * @param request contains the radio access networks with bands/channels to scan |
| 7117 | * @param messenger callback messenger for scan results or errors |
| 7118 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7119 | * @return the id of the requested scan which can be used to stop the scan. |
| 7120 | */ |
| 7121 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7122 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7123 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7124 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7126 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7127 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7128 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7129 | if (!renounceFineLocationAccess) { |
| 7130 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7131 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7132 | .setCallingPackage(callingPackage) |
| 7133 | .setCallingFeatureId(callingFeatureId) |
| 7134 | .setCallingPid(Binder.getCallingPid()) |
| 7135 | .setCallingUid(Binder.getCallingUid()) |
| 7136 | .setMethod("requestNetworkScan") |
| 7137 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7138 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7139 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7140 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7141 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7142 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7143 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7144 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7145 | if (e != null) { |
| 7146 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7147 | throw e; |
| 7148 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7149 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7150 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7151 | } |
| 7152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7153 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7154 | |
| 7155 | enforceTelephonyFeatureWithException(callingPackage, |
| 7156 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7157 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7158 | int callingUid = Binder.getCallingUid(); |
| 7159 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
| 7162 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7163 | renounceFineLocationAccess, request, messenger, binder, |
| 7164 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7165 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7166 | } finally { |
| 7167 | Binder.restoreCallingIdentity(identity); |
| 7168 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7169 | } |
| 7170 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7171 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7172 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7173 | boolean hasCarrierPriv; |
| 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7177 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7178 | } finally { |
| 7179 | Binder.restoreCallingIdentity(identity); |
| 7180 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7181 | boolean hasNetworkScanPermission = |
| 7182 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7183 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7184 | |
| 7185 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7186 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7187 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7191 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7192 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7193 | return new SecurityException("Specific channels must not be" |
| 7194 | + " scanned without location access."); |
| 7195 | } |
| 7196 | } |
| 7197 | } |
| 7198 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7199 | return null; |
| 7200 | } |
| 7201 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7202 | /** |
| 7203 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7204 | * |
| 7205 | * @param subId id of the subscription |
| 7206 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7207 | */ |
| 7208 | @Override |
| 7209 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7211 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7213 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | final long identity = Binder.clearCallingIdentity(); |
| 7215 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7216 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7217 | } finally { |
| 7218 | Binder.restoreCallingIdentity(identity); |
| 7219 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7223 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7224 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7225 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7226 | */ |
| 7227 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7228 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7229 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7230 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7231 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7233 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7234 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7238 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7239 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7240 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7241 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7242 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | } finally { |
| 7244 | Binder.restoreCallingIdentity(identity); |
| 7245 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7249 | * Get the allowed network types for certain reason. |
| 7250 | * |
| 7251 | * @param subId the id of the subscription. |
| 7252 | * @param reason the reason the allowed network type change is taking place |
| 7253 | * @return the allowed network types. |
| 7254 | */ |
| 7255 | @Override |
| 7256 | public long getAllowedNetworkTypesForReason(int subId, |
| 7257 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7258 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7259 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7260 | |
| 7261 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7262 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7263 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7264 | final long identity = Binder.clearCallingIdentity(); |
| 7265 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7266 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7267 | } finally { |
| 7268 | Binder.restoreCallingIdentity(identity); |
| 7269 | } |
| 7270 | } |
| 7271 | |
| 7272 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7273 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7274 | * @param subId subscription id of the sim card |
| 7275 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7276 | * This can be passed following states |
| 7277 | * <ol> |
| 7278 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7279 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7280 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7281 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7282 | * </ol> |
| 7283 | * @return operation result. |
| 7284 | */ |
| 7285 | @Override |
| 7286 | public int setNrDualConnectivityState(int subId, |
| 7287 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7288 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7289 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7290 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7291 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7292 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7293 | } |
| 7294 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7295 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
| 7298 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7299 | nrDualConnectivityState, subId, |
| 7300 | workSource); |
| 7301 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7302 | return result; |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
| 7305 | } |
| 7306 | } |
| 7307 | |
| 7308 | /** |
| 7309 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7310 | * @return true if dual connectivity is enabled else false |
| 7311 | */ |
| 7312 | @Override |
| 7313 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7314 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7315 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7316 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7317 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7318 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7319 | return false; |
| 7320 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7321 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7325 | null, subId, workSource); |
| 7326 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7327 | return isEnabled; |
| 7328 | } finally { |
| 7329 | Binder.restoreCallingIdentity(identity); |
| 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7334 | * Set the allowed network types of the device and |
| 7335 | * provide the reason triggering the allowed network change. |
| 7336 | * |
| 7337 | * @param subId the id of the subscription. |
| 7338 | * @param reason the reason the allowed network type change is taking place |
| 7339 | * @param allowedNetworkTypes the allowed network types. |
| 7340 | * @return true on success; false on any failure. |
| 7341 | */ |
| 7342 | @Override |
| 7343 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7344 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7345 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7347 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7348 | // If the caller only has carrier privileges, then they should not be able to override |
| 7349 | // any network types which were set for security reasons. |
| 7350 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7351 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7352 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7353 | throw new SecurityException( |
| 7354 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7355 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7356 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7357 | |
| 7358 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7359 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7360 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7361 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7362 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7363 | return false; |
| 7364 | } |
| 7365 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7366 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7367 | return false; |
| 7368 | } |
| 7369 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7370 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7371 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7372 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7373 | Phone phone = getPhone(subId); |
| 7374 | if (phone == null) { |
| 7375 | return false; |
| 7376 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7377 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7378 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7379 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7380 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7381 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7382 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7383 | final long identity = Binder.clearCallingIdentity(); |
| 7384 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7385 | Boolean success = (Boolean) sendRequest( |
| 7386 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7387 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7388 | |
| 7389 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7390 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7391 | } finally { |
| 7392 | Binder.restoreCallingIdentity(identity); |
| 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7397 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7398 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7399 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7400 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7401 | * @hide |
| 7402 | */ |
| 7403 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7404 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7405 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7406 | |
| 7407 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7408 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7411 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7412 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7413 | if (phone != null) { |
| 7414 | return phone.hasMatchedTetherApnSetting(); |
| 7415 | } else { |
| 7416 | return false; |
| 7417 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7418 | } finally { |
| 7419 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7420 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7424 | * Get the user enabled state of Mobile Data. |
| 7425 | * |
| 7426 | * TODO: remove and use isUserDataEnabled. |
| 7427 | * This can't be removed now because some vendor codes |
| 7428 | * calls through ITelephony directly while they should |
| 7429 | * use TelephonyManager. |
| 7430 | * |
| 7431 | * @return true on enabled |
| 7432 | */ |
| 7433 | @Override |
| 7434 | public boolean getDataEnabled(int subId) { |
| 7435 | return isUserDataEnabled(subId); |
| 7436 | } |
| 7437 | |
| 7438 | /** |
| 7439 | * Get whether mobile data is enabled per user setting. |
| 7440 | * |
| 7441 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7442 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7443 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7444 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7445 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7446 | * |
| 7447 | * @return {@code true} if data is enabled else {@code false} |
| 7448 | */ |
| 7449 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7450 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7451 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7452 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7453 | try { |
| 7454 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7455 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7456 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7457 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7458 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7459 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7461 | mApp, subId, functionName); |
| 7462 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | |
| 7465 | final long identity = Binder.clearCallingIdentity(); |
| 7466 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7467 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7469 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7470 | if (phone != null) { |
| 7471 | boolean retVal = phone.isUserDataEnabled(); |
| 7472 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7473 | return retVal; |
| 7474 | } else { |
| 7475 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7476 | return false; |
| 7477 | } |
| 7478 | } finally { |
| 7479 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7480 | } |
| 7481 | } |
| 7482 | |
| 7483 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7484 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7485 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7486 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7487 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7488 | * @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] | 7489 | */ |
| 7490 | @Override |
| 7491 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7492 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7493 | try { |
| 7494 | try { |
| 7495 | mApp.enforceCallingOrSelfPermission( |
| 7496 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7497 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7498 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7499 | try { |
| 7500 | mApp.enforceCallingOrSelfPermission( |
| 7501 | android.Manifest.permission.READ_PHONE_STATE, |
| 7502 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7503 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7504 | mApp.enforceCallingOrSelfPermission( |
| 7505 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7506 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7507 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7508 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7509 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7510 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7512 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7513 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7514 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7517 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7518 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7519 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7520 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7521 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | return retVal; |
| 7523 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7524 | if (DBG) { |
| 7525 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7526 | + subId + " retVal=false"); |
| 7527 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | return false; |
| 7529 | } |
| 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7532 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7533 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7534 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7535 | /** |
| 7536 | * Check if data is enabled for a specific reason |
| 7537 | * @param subId Subscription index |
| 7538 | * @param reason the reason the data enable change is taking place |
| 7539 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7540 | */ |
| 7541 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7542 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7543 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7544 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7545 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7546 | try { |
| 7547 | mApp.enforceCallingOrSelfPermission( |
| 7548 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7549 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7550 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7551 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7552 | functionName); |
| 7553 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7554 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7555 | try { |
| 7556 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7557 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7558 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7560 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7561 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7562 | } |
| 7563 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7564 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7565 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7566 | |
| 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7569 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7570 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7571 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7572 | + " reason=" + reason); |
| 7573 | } |
| 7574 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7575 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7576 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7577 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7578 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7579 | return retVal; |
| 7580 | } else { |
| 7581 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7582 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7583 | + subId + " retVal=false"); |
| 7584 | } |
| 7585 | return false; |
| 7586 | } |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
| 7589 | } |
| 7590 | } |
| 7591 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7592 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7593 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7594 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7595 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7596 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7597 | // No permission needed; this only lets the caller inspect their own status. |
| 7598 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7599 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7600 | |
| 7601 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7602 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7603 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7604 | |
| 7605 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7606 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7607 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7608 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7609 | } |
| 7610 | |
| 7611 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7612 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7613 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7614 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7615 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7616 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7617 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7618 | if (cpt == null) { |
| 7619 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7620 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7621 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7622 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7623 | } |
| 7624 | |
| 7625 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7626 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7627 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7628 | |
| 7629 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7630 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7631 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [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; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7634 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7635 | Phone phone = getPhone(subId); |
| 7636 | if (phone == null) { |
| 7637 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7638 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7639 | } |
| 7640 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7641 | if (cpt == null) { |
| 7642 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7643 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7644 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7645 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | @Override |
| 7649 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7650 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7651 | |
| 7652 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7653 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7654 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7655 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7656 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7657 | } |
| 7658 | |
| 7659 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7660 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7661 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7662 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7663 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7664 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7665 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7666 | if (phone == null) { |
| 7667 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7668 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7669 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7670 | if (cpt == null) { |
| 7671 | continue; |
| 7672 | } |
| 7673 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7674 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7675 | break; |
| 7676 | } |
| 7677 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7678 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7679 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7680 | |
| 7681 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7682 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7683 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7684 | |
| 7685 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7686 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7687 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7688 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7689 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7690 | if (phone == null) { |
| 7691 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7692 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7693 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7694 | if (cpt == null) { |
| 7695 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7696 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7697 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7698 | } |
| 7699 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7700 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7701 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7702 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7703 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7704 | if (phone == null) { |
| 7705 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7706 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7707 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7708 | if (cpt == null) { |
| 7709 | return Collections.emptyList(); |
| 7710 | } |
| 7711 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7712 | } |
| 7713 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7714 | @Override |
| 7715 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7716 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7717 | |
| 7718 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7719 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7720 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7721 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7722 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7723 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7724 | try { |
| 7725 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7726 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7727 | } |
| 7728 | } finally { |
| 7729 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7730 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7731 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7732 | } |
| 7733 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7734 | @Override |
| 7735 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7736 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7737 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7738 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7739 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7740 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7741 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7742 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7743 | if (phone == null) { |
| 7744 | return null; |
| 7745 | } |
| 7746 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7747 | if (cpt == null) { |
| 7748 | return null; |
| 7749 | } |
| 7750 | return cpt.getCarrierServicePackageName(); |
| 7751 | } |
| 7752 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7753 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7754 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7755 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7756 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7757 | return null; |
| 7758 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7759 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7760 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7761 | return null; |
| 7762 | } |
| 7763 | return iccId; |
| 7764 | } |
| 7765 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7766 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7767 | public void setCallComposerStatus(int subId, int status) { |
| 7768 | enforceModifyPermission(); |
| 7769 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7770 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7771 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7772 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
| 7775 | Phone phone = getPhone(subId); |
| 7776 | if (phone != null) { |
| 7777 | Phone defaultPhone = phone.getImsPhone(); |
| 7778 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7779 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7780 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7781 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7782 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7783 | } |
| 7784 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7785 | } catch (ImsException e) { |
| 7786 | throw new ServiceSpecificException(e.getCode()); |
| 7787 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | @Override |
| 7793 | public int getCallComposerStatus(int subId) { |
| 7794 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7795 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7796 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7797 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7798 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7799 | final long identity = Binder.clearCallingIdentity(); |
| 7800 | try { |
| 7801 | Phone phone = getPhone(subId); |
| 7802 | if (phone != null) { |
| 7803 | Phone defaultPhone = phone.getImsPhone(); |
| 7804 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7805 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7806 | return imsPhone.getCallComposerStatus(); |
| 7807 | } |
| 7808 | } |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
| 7811 | } |
| 7812 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7813 | } |
| 7814 | |
| 7815 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7816 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7817 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7818 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7819 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7820 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7821 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7822 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7823 | "setLine1NumberForDisplayForSubscriber"); |
| 7824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7825 | final long identity = Binder.clearCallingIdentity(); |
| 7826 | try { |
| 7827 | final String iccId = getIccId(subId); |
| 7828 | final Phone phone = getPhone(subId); |
| 7829 | if (phone == null) { |
| 7830 | return false; |
| 7831 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame^] | 7832 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7833 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7834 | return false; |
| 7835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | final String subscriberId = phone.getSubscriberId(); |
| 7837 | |
| 7838 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7839 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7840 | + subscriberId + " to " + number); |
| 7841 | } |
| 7842 | |
| 7843 | if (TextUtils.isEmpty(iccId)) { |
| 7844 | return false; |
| 7845 | } |
| 7846 | |
| 7847 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7848 | |
| 7849 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7850 | if (alphaTag == null) { |
| 7851 | editor.remove(alphaTagPrefKey); |
| 7852 | } else { |
| 7853 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7854 | } |
| 7855 | |
| 7856 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7857 | // track all merged IMSIs based on line number |
| 7858 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7859 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7860 | if (number == null) { |
| 7861 | editor.remove(numberPrefKey); |
| 7862 | editor.remove(subscriberPrefKey); |
| 7863 | } else { |
| 7864 | editor.putString(numberPrefKey, number); |
| 7865 | editor.putString(subscriberPrefKey, subscriberId); |
| 7866 | } |
| 7867 | |
| 7868 | editor.commit(); |
| 7869 | return true; |
| 7870 | } finally { |
| 7871 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7872 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7876 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7877 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7878 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7879 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7880 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7881 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7882 | return null; |
| 7883 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7884 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7885 | enforceTelephonyFeatureWithException(callingPackage, |
| 7886 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7888 | final long identity = Binder.clearCallingIdentity(); |
| 7889 | try { |
| 7890 | String iccId = getIccId(subId); |
| 7891 | if (iccId != null) { |
| 7892 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7893 | if (DBG_MERGE) { |
| 7894 | log("getLine1NumberForDisplay returning " |
| 7895 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7896 | } |
| 7897 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7900 | return null; |
| 7901 | } finally { |
| 7902 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7903 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7907 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7908 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7909 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7910 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7911 | return null; |
| 7912 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7913 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7914 | final long identity = Binder.clearCallingIdentity(); |
| 7915 | try { |
| 7916 | String iccId = getIccId(subId); |
| 7917 | if (iccId != null) { |
| 7918 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7919 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7920 | } |
| 7921 | return null; |
| 7922 | } finally { |
| 7923 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7924 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7925 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7926 | |
| 7927 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7928 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7929 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7930 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7931 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7932 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7933 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7934 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7935 | return null; |
| 7936 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7937 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7938 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7939 | // the process, where TelephonyManager was instantiated. |
| 7940 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7941 | final long identity = Binder.clearCallingIdentity(); |
| 7942 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7943 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7944 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7945 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7946 | |
| 7947 | // Figure out what subscribers are currently active |
| 7948 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7949 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7950 | // Only consider subs which match the current subId |
| 7951 | // This logic can be simplified. See b/131189269 for progress. |
| 7952 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7953 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7954 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | |
| 7956 | // First pass, find a number override for an active subscriber |
| 7957 | String mergeNumber = null; |
| 7958 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7959 | for (String key : prefs.keySet()) { |
| 7960 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7961 | final String subscriberId = (String) prefs.get(key); |
| 7962 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7963 | final String iccId = key.substring( |
| 7964 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7965 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7966 | mergeNumber = (String) prefs.get(numberKey); |
| 7967 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7968 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7969 | + " for active subscriber " + subscriberId); |
| 7970 | } |
| 7971 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7972 | break; |
| 7973 | } |
| 7974 | } |
| 7975 | } |
| 7976 | } |
| 7977 | |
| 7978 | // Shortcut when no active merged subscribers |
| 7979 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7980 | return null; |
| 7981 | } |
| 7982 | |
| 7983 | // Second pass, find all subscribers under that line override |
| 7984 | final ArraySet<String> result = new ArraySet<>(); |
| 7985 | for (String key : prefs.keySet()) { |
| 7986 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7987 | final String number = (String) prefs.get(key); |
| 7988 | if (mergeNumber.equals(number)) { |
| 7989 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7990 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7991 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7992 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7993 | result.add(subscriberId); |
| 7994 | } |
| 7995 | } |
| 7996 | } |
| 7997 | } |
| 7998 | |
| 7999 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8000 | Arrays.sort(resultArray); |
| 8001 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8002 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8003 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8004 | } |
| 8005 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8006 | } finally { |
| 8007 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8008 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8009 | } |
| 8010 | |
| 8011 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8012 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8013 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8014 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8015 | enforceTelephonyFeatureWithException(callingPackage, |
| 8016 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8017 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8018 | final long identity = Binder.clearCallingIdentity(); |
| 8019 | try { |
| 8020 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8021 | TelephonyManager.class); |
| 8022 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8023 | if (subscriberId == null) { |
| 8024 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8025 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8026 | + subId); |
| 8027 | } |
| 8028 | return null; |
| 8029 | } |
| 8030 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8031 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8032 | .getSubscriptionInfo(subId); |
| 8033 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8034 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8035 | if (groupUuid == null) { |
| 8036 | return new String[]{subscriberId}; |
| 8037 | } |
| 8038 | |
| 8039 | // Get all subscriberIds from the group. |
| 8040 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8041 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8042 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8043 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8044 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8045 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8046 | if (subscriberId != null) { |
| 8047 | mergedSubscriberIds.add(subscriberId); |
| 8048 | } |
| 8049 | } |
| 8050 | |
| 8051 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8052 | } finally { |
| 8053 | Binder.restoreCallingIdentity(identity); |
| 8054 | |
| 8055 | } |
| 8056 | } |
| 8057 | |
| 8058 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8059 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8060 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8061 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8062 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8063 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8064 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8065 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
| 8068 | final Phone phone = getPhone(subId); |
| 8069 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8070 | } finally { |
| 8071 | Binder.restoreCallingIdentity(identity); |
| 8072 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8073 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8074 | |
| 8075 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8076 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8077 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8078 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8079 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8080 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8081 | |
| 8082 | final long identity = Binder.clearCallingIdentity(); |
| 8083 | try { |
| 8084 | final Phone phone = getPhone(subId); |
| 8085 | if (phone == null) { |
| 8086 | return false; |
| 8087 | } |
| 8088 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8089 | cdmaNonRoamingList); |
| 8090 | } finally { |
| 8091 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8092 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8096 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8097 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8098 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8099 | if (phone == null) { |
| 8100 | return raf; |
| 8101 | } |
| 8102 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8103 | try { |
| 8104 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8105 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8106 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8107 | } catch (SecurityException e) { |
| 8108 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8109 | throw e; |
| 8110 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8111 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8112 | enforceTelephonyFeatureWithException(callingPackage, |
| 8113 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8115 | final long identity = Binder.clearCallingIdentity(); |
| 8116 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8117 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | } finally { |
| 8119 | Binder.restoreCallingIdentity(identity); |
| 8120 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8121 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8122 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8123 | |
| 8124 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8125 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8126 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8127 | try { |
| 8128 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8129 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8130 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8131 | } |
| 8132 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8133 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8134 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8135 | |
| 8136 | enforceTelephonyFeatureWithException(callingPackage, |
| 8137 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8138 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8139 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8140 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8141 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8142 | throw new SecurityException("App must be the dialer role holder to" |
| 8143 | + " upload a call composer pic"); |
| 8144 | } |
| 8145 | |
| 8146 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8147 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8148 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8149 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8150 | boolean readUntilEnd = false; |
| 8151 | int totalBytesRead = 0; |
| 8152 | byte[] buffer = new byte[16 * 1024]; |
| 8153 | while (true) { |
| 8154 | int numRead; |
| 8155 | try { |
| 8156 | numRead = input.read(buffer); |
| 8157 | } catch (IOException e) { |
| 8158 | try { |
| 8159 | fd.checkError(); |
| 8160 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8161 | null); |
| 8162 | } catch (IOException e1) { |
| 8163 | // This means that the other side closed explicitly with an error. If this |
| 8164 | // happens, log and ignore. |
| 8165 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8166 | } |
| 8167 | break; |
| 8168 | } |
| 8169 | if (numRead == -1) { |
| 8170 | readUntilEnd = true; |
| 8171 | break; |
| 8172 | } |
| 8173 | totalBytesRead += numRead; |
| 8174 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8175 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8176 | try { |
| 8177 | input.close(); |
| 8178 | } catch (IOException e) { |
| 8179 | // ignore |
| 8180 | } |
| 8181 | break; |
| 8182 | } |
| 8183 | output.write(buffer, 0, numRead); |
| 8184 | } |
| 8185 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8186 | // close is above, where the picture size is too big. |
| 8187 | |
| 8188 | try { |
| 8189 | fd.checkError(); |
| 8190 | } catch (IOException e) { |
| 8191 | loge("Remote end for call composer closed with an error: " + e); |
| 8192 | return; |
| 8193 | } |
| 8194 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8195 | if (!readUntilEnd) { |
| 8196 | loge("Did not finish reading entire image; aborting"); |
| 8197 | return; |
| 8198 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8199 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8200 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8201 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8202 | new CallComposerPictureTransfer.Factory() {}, |
| 8203 | imageData, |
| 8204 | (result) -> { |
| 8205 | if (result.first != null) { |
| 8206 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8207 | Bundle outputResult = new Bundle(); |
| 8208 | outputResult.putParcelable( |
| 8209 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8210 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8211 | outputResult); |
| 8212 | } else { |
| 8213 | callback.send(result.second, null); |
| 8214 | } |
| 8215 | } |
| 8216 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8217 | }); |
| 8218 | } |
| 8219 | |
| 8220 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8221 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8222 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8223 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8225 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8226 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8228 | final long identity = Binder.clearCallingIdentity(); |
| 8229 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8230 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8231 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | } finally { |
| 8233 | Binder.restoreCallingIdentity(identity); |
| 8234 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8235 | } |
| 8236 | |
| 8237 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8238 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8239 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8241 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8242 | return false; |
| 8243 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8244 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8245 | enforceTelephonyFeatureWithException(callingPackage, |
| 8246 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8247 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8248 | final long identity = Binder.clearCallingIdentity(); |
| 8249 | try { |
| 8250 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8251 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8252 | // In the long run, we may instead need to check if there exists a connection service |
| 8253 | // which can support video calling. |
| 8254 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8255 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8256 | return imsManager.isVtEnabledByPlatform() |
| 8257 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8258 | && imsManager.isVtEnabledByUser(); |
| 8259 | } finally { |
| 8260 | Binder.restoreCallingIdentity(identity); |
| 8261 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8262 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8263 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8264 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8265 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8266 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8268 | mApp, subId, callingPackage, callingFeatureId, |
| 8269 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8270 | return false; |
| 8271 | } |
| 8272 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8273 | enforceTelephonyFeatureWithException(callingPackage, |
| 8274 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | final long identity = Binder.clearCallingIdentity(); |
| 8277 | try { |
| 8278 | CarrierConfigManager configManager = |
| 8279 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8280 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8281 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
| 8284 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8285 | } |
| 8286 | |
| 8287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8288 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8290 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | return false; |
| 8292 | } |
| 8293 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8294 | enforceTelephonyFeatureWithException(callingPackage, |
| 8295 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8297 | final long identity = Binder.clearCallingIdentity(); |
| 8298 | try { |
| 8299 | CarrierConfigManager configManager = |
| 8300 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8301 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8303 | } finally { |
| 8304 | Binder.restoreCallingIdentity(identity); |
| 8305 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8306 | } |
| 8307 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8308 | @Override |
| 8309 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8310 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8311 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8312 | } |
| 8313 | |
| 8314 | @Override |
| 8315 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8316 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8317 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8319 | final long identity = Binder.clearCallingIdentity(); |
| 8320 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8321 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8322 | } finally { |
| 8323 | Binder.restoreCallingIdentity(identity); |
| 8324 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8325 | } |
| 8326 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8327 | /** |
| 8328 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8329 | * support for the feature and device firmware support. |
| 8330 | * |
| 8331 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8332 | */ |
| 8333 | @Override |
| 8334 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8335 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8336 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8339 | final Phone phone = getPhone(subscriptionId); |
| 8340 | if (phone == null) { |
| 8341 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8342 | return false; |
| 8343 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8345 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8346 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8347 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8348 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8349 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8350 | return isCarrierSupported && isDeviceSupported; |
| 8351 | } finally { |
| 8352 | Binder.restoreCallingIdentity(identity); |
| 8353 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8354 | } |
| 8355 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8356 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8357 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8358 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8359 | * 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] | 8360 | */ |
| 8361 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8362 | final long identity = Binder.clearCallingIdentity(); |
| 8363 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8364 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8365 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8366 | return false; |
| 8367 | } |
| 8368 | } |
| 8369 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8370 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8371 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8372 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8373 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8374 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8375 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8376 | } finally { |
| 8377 | Binder.restoreCallingIdentity(identity); |
| 8378 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8379 | } |
| 8380 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8381 | @Deprecated |
| 8382 | @Override |
| 8383 | public String getDeviceId(String callingPackage) { |
| 8384 | return getDeviceIdWithFeature(callingPackage, null); |
| 8385 | } |
| 8386 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8387 | /** |
| 8388 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8389 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8390 | * |
| 8391 | * <p>Requires Permission: |
| 8392 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8393 | */ |
| 8394 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8395 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8396 | try { |
| 8397 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8398 | } catch (SecurityException se) { |
| 8399 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8400 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8401 | + Binder.getCallingUid()); |
| 8402 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8403 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8404 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8405 | return null; |
| 8406 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8407 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8408 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8409 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8410 | return null; |
| 8411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8412 | |
| 8413 | final long identity = Binder.clearCallingIdentity(); |
| 8414 | try { |
| 8415 | return phone.getDeviceId(); |
| 8416 | } finally { |
| 8417 | Binder.restoreCallingIdentity(identity); |
| 8418 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8419 | } |
| 8420 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8421 | /** |
| 8422 | * {@hide} |
| 8423 | * Returns the IMS Registration Status on a particular subid |
| 8424 | * |
| 8425 | * @param subId |
| 8426 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8427 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8428 | Phone phone = getPhone(subId); |
| 8429 | if (phone != null) { |
| 8430 | return phone.isImsRegistered(); |
| 8431 | } else { |
| 8432 | return false; |
| 8433 | } |
| 8434 | } |
| 8435 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8436 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8437 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8438 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8439 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8440 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8441 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8442 | } |
| 8443 | final long identity = Binder.clearCallingIdentity(); |
| 8444 | try { |
| 8445 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8446 | } finally { |
| 8447 | Binder.restoreCallingIdentity(identity); |
| 8448 | } |
| 8449 | } |
| 8450 | |
| 8451 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8452 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8453 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8454 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8455 | mApp, |
| 8456 | subscriptionId, |
| 8457 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8458 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8459 | |
| 8460 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8461 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8462 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | Phone phone = getPhone(subscriptionId); |
| 8466 | if (phone == null) { |
| 8467 | return null; |
| 8468 | } |
| 8469 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8470 | } finally { |
| 8471 | Binder.restoreCallingIdentity(identity); |
| 8472 | } |
| 8473 | } |
| 8474 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8475 | /** |
| 8476 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8477 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8478 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8479 | final long identity = Binder.clearCallingIdentity(); |
| 8480 | try { |
| 8481 | Phone phone = getPhone(subId); |
| 8482 | if (phone != null) { |
| 8483 | return phone.isWifiCallingEnabled(); |
| 8484 | } else { |
| 8485 | return false; |
| 8486 | } |
| 8487 | } finally { |
| 8488 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8489 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8490 | } |
| 8491 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8492 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8493 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8494 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8495 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8496 | final long identity = Binder.clearCallingIdentity(); |
| 8497 | try { |
| 8498 | Phone phone = getPhone(subId); |
| 8499 | if (phone != null) { |
| 8500 | return phone.isVideoEnabled(); |
| 8501 | } else { |
| 8502 | return false; |
| 8503 | } |
| 8504 | } finally { |
| 8505 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8506 | } |
| 8507 | } |
| 8508 | |
| 8509 | /** |
| 8510 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8511 | * defined in {@link ImsRegistrationImplBase}. |
| 8512 | */ |
| 8513 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
| 8516 | Phone phone = getPhone(subId); |
| 8517 | if (phone != null) { |
| 8518 | return phone.getImsRegistrationTech(); |
| 8519 | } else { |
| 8520 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8521 | } |
| 8522 | } finally { |
| 8523 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8524 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8525 | } |
| 8526 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8527 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8528 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8529 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8530 | |
| 8531 | enforceTelephonyFeatureWithException(callingPackage, |
| 8532 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8533 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8534 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8535 | return; |
| 8536 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8537 | Phone defaultPhone = getDefaultPhone(); |
| 8538 | if (defaultPhone != null) { |
| 8539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8540 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8541 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8542 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8543 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8544 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8545 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8546 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8547 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8548 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8549 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8550 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8551 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8552 | setDataRoamingEnabled(subId, phone == null ? false |
| 8553 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8554 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8555 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8556 | // There has been issues when Sms raw table somehow stores orphan |
| 8557 | // fragments. They lead to garbled message when new fragments come |
| 8558 | // in and combined with those stale ones. In case this happens again, |
| 8559 | // user can reset all network settings which will clean up this table. |
| 8560 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8561 | // Clean up IMS settings as well here. |
| 8562 | int slotId = getSlotIndex(subId); |
| 8563 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8564 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8565 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8566 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8567 | if (defaultPhone == null) { |
| 8568 | return; |
| 8569 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8570 | // Erase modem config if erase modem on network setting is enabled. |
| 8571 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8572 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8573 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8574 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8575 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8576 | |
| 8577 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8578 | } finally { |
| 8579 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8580 | } |
| 8581 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8582 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8583 | @VisibleForTesting |
| 8584 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8585 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8586 | return; |
| 8587 | } |
| 8588 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8589 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8590 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8591 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8592 | "user=" + defaultNetworkType); |
| 8593 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8594 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8595 | defaultNetworkType, null); |
| 8596 | } |
| 8597 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8598 | private void cleanUpSmsRawTable(Context context) { |
| 8599 | ContentResolver resolver = context.getContentResolver(); |
| 8600 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8601 | resolver.delete(uri, null, null); |
| 8602 | } |
| 8603 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8604 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8605 | public String getSimLocaleForSubscriber(int subId) { |
| 8606 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8607 | |
| 8608 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8609 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8610 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8611 | final Phone phone = getPhone(subId); |
| 8612 | if (phone == null) { |
| 8613 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8614 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8616 | final long identity = Binder.clearCallingIdentity(); |
| 8617 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8618 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8619 | phone.getContext().getOpPackageName(), |
| 8620 | phone.getContext().getAttributionTag()); |
| 8621 | if (info == null) { |
| 8622 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8623 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8624 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8625 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8626 | // preferences (EF-PL and EF-LI)... |
| 8627 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8628 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8629 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8630 | if (localeFromDefaultSim != null) { |
| 8631 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8632 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8633 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8634 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8635 | } else { |
| 8636 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8637 | } |
| 8638 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8640 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8641 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8642 | // the SIM and carrier preferences does not include a country we add the country |
| 8643 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8644 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8645 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8646 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8647 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8648 | } |
| 8649 | |
| 8650 | if (DBG) log("No locale found - returning null"); |
| 8651 | return null; |
| 8652 | } finally { |
| 8653 | Binder.restoreCallingIdentity(identity); |
| 8654 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8655 | } |
| 8656 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8657 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8658 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8659 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8660 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8661 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8662 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8663 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8664 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8665 | return localeTag; |
| 8666 | } |
| 8667 | } |
| 8668 | return inputLocale.toLanguageTag(); |
| 8669 | } |
| 8670 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8671 | /** |
| 8672 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8673 | */ |
| 8674 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8675 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8676 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8677 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8678 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8679 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8680 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8681 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8682 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8683 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8684 | * representing the state of the modem. |
| 8685 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8686 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8687 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8688 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8689 | */ |
| 8690 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8691 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8692 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8693 | |
| 8694 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8695 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8696 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8697 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8698 | |
| 8699 | final long identity = Binder.clearCallingIdentity(); |
| 8700 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8701 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8702 | } finally { |
| 8703 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8704 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8705 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8706 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8707 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8708 | // less than total activity duration. |
| 8709 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8710 | if (info == null) { |
| 8711 | return false; |
| 8712 | } |
| 8713 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8714 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8715 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8716 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8717 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8718 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8719 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8720 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8721 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8722 | } |
| 8723 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8724 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8725 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8726 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8727 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8728 | |
| 8729 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8730 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8731 | } |
| 8732 | |
| 8733 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8734 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8735 | rat, |
| 8736 | freq, |
| 8737 | info.getReceiveTimeMillis(rat, freq) |
| 8738 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8739 | } |
| 8740 | |
| 8741 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8742 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8743 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8744 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8745 | |
| 8746 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8747 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8748 | } |
| 8749 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8750 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8751 | rat, |
| 8752 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8753 | } |
| 8754 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8755 | /** |
| 8756 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8757 | * @param info recent ModemActivityInfo |
| 8758 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8759 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8760 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8761 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8762 | boolean matched; |
| 8763 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8764 | matched = false; |
| 8765 | int rat = info.getSpecificInfoRat(i); |
| 8766 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8767 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8768 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8769 | //if it already exists |
| 8770 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8771 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8772 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8773 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8774 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8775 | updateLastModemActivityInfo(info, rat, freq); |
| 8776 | matched = true; |
| 8777 | } |
| 8778 | } else { |
| 8779 | updateLastModemActivityInfo(info, rat); |
| 8780 | matched = true; |
| 8781 | } |
| 8782 | } |
| 8783 | } |
| 8784 | |
| 8785 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8786 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8787 | new ActivityStatsTechSpecificInfo( |
| 8788 | rat, |
| 8789 | freq, |
| 8790 | info.getTransmitTimeMillis(rat, freq), |
| 8791 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8792 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8793 | } |
| 8794 | } |
| 8795 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8796 | mLastModemActivitySpecificInfo = |
| 8797 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8798 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8799 | |
| 8800 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8801 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8802 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8803 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8804 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8805 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8806 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8807 | |
| 8808 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8809 | new ModemActivityInfo( |
| 8810 | mLastModemActivityInfo.getTimestampMillis(), |
| 8811 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8812 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8813 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8814 | } |
| 8815 | |
| 8816 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8817 | ActivityStatsTechSpecificInfo[] info) { |
| 8818 | int infoSize = info.length; |
| 8819 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8820 | for (int i = 0; i < infoSize; i++) { |
| 8821 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8822 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8823 | info[i].getTransmitTimeMillis(), |
| 8824 | (int) info[i].getReceiveTimeMillis()); |
| 8825 | } |
| 8826 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8827 | } |
| 8828 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8829 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8830 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8831 | */ |
| 8832 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8833 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8834 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8835 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8836 | if (phone == null) { |
| 8837 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8838 | return null; |
| 8839 | } |
| 8840 | |
| 8841 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8842 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8843 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8844 | return null; |
| 8845 | } |
| 8846 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8847 | enforceTelephonyFeatureWithException(callingPackage, |
| 8848 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8849 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8850 | boolean hasFinePermission = false; |
| 8851 | boolean hasCoarsePermission = false; |
| 8852 | if (!renounceFineLocationAccess) { |
| 8853 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8854 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8855 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8856 | .setCallingPackage(callingPackage) |
| 8857 | .setCallingFeatureId(callingFeatureId) |
| 8858 | .setCallingPid(Binder.getCallingPid()) |
| 8859 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8860 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8861 | .setLogAsInfo(true) |
| 8862 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8863 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8864 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8865 | .build()); |
| 8866 | hasFinePermission = |
| 8867 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8868 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8869 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8870 | if (!renounceCoarseLocationAccess) { |
| 8871 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8872 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8873 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8874 | .setCallingPackage(callingPackage) |
| 8875 | .setCallingFeatureId(callingFeatureId) |
| 8876 | .setCallingPid(Binder.getCallingPid()) |
| 8877 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8878 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8879 | .setLogAsInfo(true) |
| 8880 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8881 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8882 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8883 | .build()); |
| 8884 | hasCoarsePermission = |
| 8885 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8886 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8887 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8888 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8889 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8890 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8891 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8892 | if (subInfo != null && !subInfo.isActive()) { |
| 8893 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8894 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8895 | } |
| 8896 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8897 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8898 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8899 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8900 | |
| 8901 | // Scrub out the location info in ServiceState depending on what level of access |
| 8902 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8903 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8904 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8905 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8906 | } finally { |
| 8907 | Binder.restoreCallingIdentity(identity); |
| 8908 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8909 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8910 | |
| 8911 | /** |
| 8912 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8913 | * |
| 8914 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8915 | * voicemail ringtone. |
| 8916 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8917 | * PhoneAccount. |
| 8918 | */ |
| 8919 | @Override |
| 8920 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8921 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8922 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8923 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8924 | final long identity = Binder.clearCallingIdentity(); |
| 8925 | try { |
| 8926 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8927 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8928 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8929 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8930 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8931 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8932 | } finally { |
| 8933 | Binder.restoreCallingIdentity(identity); |
| 8934 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8935 | } |
| 8936 | |
| 8937 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8938 | * Sets the per-account voicemail ringtone. |
| 8939 | * |
| 8940 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8941 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8942 | * |
| 8943 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8944 | * voicemail ringtone. |
| 8945 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8946 | * PhoneAccount. |
| 8947 | */ |
| 8948 | @Override |
| 8949 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8950 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8951 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8952 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8953 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8954 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8956 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8957 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8958 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8959 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8960 | enforceTelephonyFeatureWithException(callingPackage, |
| 8961 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8963 | final long identity = Binder.clearCallingIdentity(); |
| 8964 | try { |
| 8965 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8966 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8967 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8968 | } |
| 8969 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8970 | } finally { |
| 8971 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8972 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8973 | } |
| 8974 | |
| 8975 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8976 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8977 | * |
| 8978 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8979 | * voicemail vibration setting. |
| 8980 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8981 | */ |
| 8982 | @Override |
| 8983 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8984 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8985 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8987 | final long identity = Binder.clearCallingIdentity(); |
| 8988 | try { |
| 8989 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8990 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8991 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8992 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8994 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8995 | } finally { |
| 8996 | Binder.restoreCallingIdentity(identity); |
| 8997 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8998 | } |
| 8999 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9000 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9001 | * Sets the per-account voicemail vibration. |
| 9002 | * |
| 9003 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9004 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9005 | * |
| 9006 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9007 | * voicemail vibration setting. |
| 9008 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9009 | * specific PhoneAccount. |
| 9010 | */ |
| 9011 | @Override |
| 9012 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9013 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9014 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9016 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9017 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9019 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9020 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9021 | } |
| 9022 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9023 | enforceTelephonyFeatureWithException(callingPackage, |
| 9024 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9026 | final long identity = Binder.clearCallingIdentity(); |
| 9027 | try { |
| 9028 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9029 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9030 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9031 | } |
| 9032 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9033 | } finally { |
| 9034 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9035 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9036 | } |
| 9037 | |
| 9038 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9039 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9040 | * |
| 9041 | * @throws SecurityException if the caller does not have the required permission |
| 9042 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9043 | @VisibleForTesting |
| 9044 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9045 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9046 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9047 | } |
| 9048 | |
| 9049 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9050 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9051 | * permission. |
| 9052 | * |
| 9053 | * @throws SecurityException if the caller does not have the required permission |
| 9054 | */ |
| 9055 | private void enforceSendSmsPermission() { |
| 9056 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9057 | } |
| 9058 | |
| 9059 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9060 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9061 | * users permission. |
| 9062 | * |
| 9063 | * @throws SecurityException if the caller does not have the required permission |
| 9064 | */ |
| 9065 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9066 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9067 | } |
| 9068 | |
| 9069 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9070 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9071 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9072 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9073 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9074 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9075 | final long identity = Binder.clearCallingIdentity(); |
| 9076 | try { |
| 9077 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9078 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9079 | if (componentName == null) { |
| 9080 | throw new SecurityException( |
| 9081 | "Caller not current active visual voicemail package[null]"); |
| 9082 | } |
| 9083 | String vvmPackage = componentName.getPackageName(); |
| 9084 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9085 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9086 | } |
| 9087 | } finally { |
| 9088 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9089 | } |
| 9090 | } |
| 9091 | |
| 9092 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9093 | * Return the application ID for the app type. |
| 9094 | * |
| 9095 | * @param subId the subscription ID that this request applies to. |
| 9096 | * @param appType the uicc app type. |
| 9097 | * @return Application ID for specificied app type, or null if no uicc. |
| 9098 | */ |
| 9099 | @Override |
| 9100 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9101 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9102 | |
| 9103 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9104 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9105 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9106 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9107 | |
| 9108 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9109 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9110 | if (phone == null) { |
| 9111 | return null; |
| 9112 | } |
| 9113 | String aid = null; |
| 9114 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9115 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9116 | .getApplicationByType(appType).getAid(); |
| 9117 | } catch (Exception e) { |
| 9118 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9119 | } |
| 9120 | return aid; |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9123 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9124 | } |
| 9125 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9126 | /** |
| 9127 | * Return the Electronic Serial Number. |
| 9128 | * |
| 9129 | * @param subId the subscription ID that this request applies to. |
| 9130 | * @return ESN or null if error. |
| 9131 | */ |
| 9132 | @Override |
| 9133 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9134 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -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 | 4001d25 | 2016-05-11 10:29:41 -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 esn = null; |
| 9143 | try { |
| 9144 | esn = phone.getEsn(); |
| 9145 | } catch (Exception e) { |
| 9146 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9147 | } |
| 9148 | return esn; |
| 9149 | } finally { |
| 9150 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9151 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9152 | } |
| 9153 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9154 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9155 | * Return the Preferred Roaming List Version. |
| 9156 | * |
| 9157 | * @param subId the subscription ID that this request applies to. |
| 9158 | * @return PRLVersion or null if error. |
| 9159 | */ |
| 9160 | @Override |
| 9161 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9162 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9163 | |
| 9164 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9165 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9166 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9167 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9168 | |
| 9169 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9170 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9171 | if (phone == null) { |
| 9172 | return null; |
| 9173 | } |
| 9174 | String cdmaPrlVersion = null; |
| 9175 | try { |
| 9176 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9177 | } catch (Exception e) { |
| 9178 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9179 | } |
| 9180 | return cdmaPrlVersion; |
| 9181 | } finally { |
| 9182 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9183 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9184 | } |
| 9185 | |
| 9186 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9187 | * Get snapshot of Telephony histograms |
| 9188 | * @return List of Telephony histograms |
| 9189 | * @hide |
| 9190 | */ |
| 9191 | @Override |
| 9192 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9193 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9194 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9195 | |
| 9196 | final long identity = Binder.clearCallingIdentity(); |
| 9197 | try { |
| 9198 | return RIL.getTelephonyRILTimingHistograms(); |
| 9199 | } finally { |
| 9200 | Binder.restoreCallingIdentity(identity); |
| 9201 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9202 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9203 | |
| 9204 | /** |
| 9205 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9206 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9207 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9208 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9209 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9210 | * @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] | 9211 | */ |
| 9212 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9213 | @TelephonyManager.SetCarrierRestrictionResult |
| 9214 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9215 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9216 | |
| 9217 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9218 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9219 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9220 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9221 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9222 | if (carrierRestrictionRules == null) { |
| 9223 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9224 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9226 | final long identity = Binder.clearCallingIdentity(); |
| 9227 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9228 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9229 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9230 | } finally { |
| 9231 | Binder.restoreCallingIdentity(identity); |
| 9232 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9233 | } |
| 9234 | |
| 9235 | /** |
| 9236 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9237 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9238 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9239 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9240 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9241 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9242 | */ |
| 9243 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9244 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9245 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9246 | |
| 9247 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9248 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9249 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9250 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9251 | |
| 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9254 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9255 | if (response instanceof CarrierRestrictionRules) { |
| 9256 | return (CarrierRestrictionRules) response; |
| 9257 | } |
| 9258 | // Response is an Exception of some kind, |
| 9259 | // which is signalled to the user as a NULL retval |
| 9260 | return null; |
| 9261 | } catch (Exception e) { |
| 9262 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9263 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9264 | } finally { |
| 9265 | Binder.restoreCallingIdentity(identity); |
| 9266 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9267 | } |
| 9268 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9269 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9270 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9271 | * through the callback. |
| 9272 | * |
| 9273 | * @param callback The callback that will be used to send the result. |
| 9274 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9275 | * the caller is not allowlisted. |
| 9276 | */ |
| 9277 | @Override |
| 9278 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9279 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9280 | |
| 9281 | enforceTelephonyFeatureWithException(packageName, |
| 9282 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9283 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9284 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9285 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9286 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9287 | throw new SecurityException("Not an authorized caller"); |
| 9288 | } |
| 9289 | final long identity = Binder.clearCallingIdentity(); |
| 9290 | try { |
| 9291 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9292 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9293 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9294 | } finally { |
| 9295 | Binder.restoreCallingIdentity(identity); |
| 9296 | } |
| 9297 | } |
| 9298 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9299 | @Override |
| 9300 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9301 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9302 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9303 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9304 | } |
| 9305 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9306 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9307 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9308 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9309 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9310 | } |
| 9311 | |
| 9312 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9313 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9314 | * @param subId the subscription ID that this action applies to. |
| 9315 | * @param enabled control enable or disable radio. |
| 9316 | * {@hide} |
| 9317 | */ |
| 9318 | @Override |
| 9319 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9320 | enforceModifyPermission(); |
| 9321 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9322 | |
| 9323 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9324 | if (phone == null) { |
| 9325 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9326 | return; |
| 9327 | } |
| 9328 | try { |
| 9329 | phone.carrierActionSetRadioEnabled(enabled); |
| 9330 | } catch (Exception e) { |
| 9331 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9332 | } finally { |
| 9333 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9334 | } |
| 9335 | } |
| 9336 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9337 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9338 | * Enable or disable Voice over NR (VoNR) |
| 9339 | * @param subId the subscription ID that this action applies to. |
| 9340 | * @param enabled enable or disable VoNR. |
| 9341 | * @return operation result. |
| 9342 | */ |
| 9343 | @Override |
| 9344 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9345 | enforceModifyPermission(); |
| 9346 | final Phone phone = getPhone(subId); |
| 9347 | |
| 9348 | final long identity = Binder.clearCallingIdentity(); |
| 9349 | if (phone == null) { |
| 9350 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9351 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9352 | } |
| 9353 | |
| 9354 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9355 | try { |
| 9356 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9357 | workSource); |
| 9358 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9359 | |
| 9360 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9361 | if (DBG) { |
| 9362 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9363 | } |
| 9364 | SubscriptionManager.setSubscriptionProperty( |
| 9365 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9366 | (enabled ? "1" : "0")); |
| 9367 | } |
| 9368 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9369 | return result; |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
| 9376 | * Is voice over NR enabled |
| 9377 | * @return true if VoNR is enabled else false |
| 9378 | */ |
| 9379 | @Override |
| 9380 | public boolean isVoNrEnabled(int subId) { |
| 9381 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9382 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9383 | final long identity = Binder.clearCallingIdentity(); |
| 9384 | try { |
| 9385 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9386 | null, subId, workSource); |
| 9387 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9388 | return isEnabled; |
| 9389 | } finally { |
| 9390 | Binder.restoreCallingIdentity(identity); |
| 9391 | } |
| 9392 | } |
| 9393 | |
| 9394 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9395 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9396 | * network status based on which carrier apps could apply actions accordingly, |
| 9397 | * enable/disable default url handler for example. |
| 9398 | * |
| 9399 | * @param subId the subscription ID that this action applies to. |
| 9400 | * @param report control start/stop reporting the default network status. |
| 9401 | * {@hide} |
| 9402 | */ |
| 9403 | @Override |
| 9404 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9405 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9406 | |
| 9407 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9408 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9409 | "carrierActionReportDefaultNetworkStatus"); |
| 9410 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9411 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9414 | if (phone == null) { |
| 9415 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9416 | return; |
| 9417 | } |
| 9418 | try { |
| 9419 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9420 | } catch (Exception e) { |
| 9421 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9422 | } finally { |
| 9423 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9424 | } |
| 9425 | } |
| 9426 | |
| 9427 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9428 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9429 | * @param subId the subscription ID that this action applies to. |
| 9430 | * {@hide} |
| 9431 | */ |
| 9432 | @Override |
| 9433 | public void carrierActionResetAll(int subId) { |
| 9434 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9435 | |
| 9436 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9437 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9438 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9439 | final Phone phone = getPhone(subId); |
| 9440 | if (phone == null) { |
| 9441 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9442 | return; |
| 9443 | } |
| 9444 | try { |
| 9445 | phone.carrierActionResetAll(); |
| 9446 | } catch (Exception e) { |
| 9447 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9448 | } |
| 9449 | } |
| 9450 | |
| 9451 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9452 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9453 | * bug report is being generated. |
| 9454 | */ |
| 9455 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9456 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9457 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9458 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9459 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9460 | + Binder.getCallingPid() |
| 9461 | + ", uid=" + Binder.getCallingUid() |
| 9462 | + "without permission " |
| 9463 | + android.Manifest.permission.DUMP); |
| 9464 | return; |
| 9465 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9466 | try { |
| 9467 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9468 | } catch (Exception e) { |
| 9469 | writer.println("Failed to dump phone information: " + e); |
| 9470 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9471 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9472 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9473 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9474 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9475 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9476 | @NonNull String[] args) { |
| 9477 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9478 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9479 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9480 | } |
| 9481 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9482 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9483 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9484 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9485 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9486 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9487 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9488 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9489 | */ |
| 9490 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9491 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9492 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9493 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9494 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9495 | try { |
| 9496 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9497 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9498 | } catch (SecurityException se) { |
| 9499 | enforceModifyPermission(); |
| 9500 | } |
| 9501 | } else { |
| 9502 | enforceModifyPermission(); |
| 9503 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9504 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9505 | enforceTelephonyFeatureWithException(callingPackage, |
| 9506 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9507 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9508 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9509 | final long identity = Binder.clearCallingIdentity(); |
| 9510 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9511 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9512 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9513 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9514 | callingUid, callingPackage, null, null); |
| 9515 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9516 | Phone phone = getPhone(subId); |
| 9517 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9518 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9519 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9520 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9521 | phone.getDataSettingsManager().setDataEnabled( |
| 9522 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9523 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9524 | } |
| 9525 | } finally { |
| 9526 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9527 | } |
| 9528 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9529 | |
| 9530 | /** |
| 9531 | * Get Client request stats |
| 9532 | * @return List of Client Request Stats |
| 9533 | * @hide |
| 9534 | */ |
| 9535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9536 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9537 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9539 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9540 | return null; |
| 9541 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9542 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9544 | final long identity = Binder.clearCallingIdentity(); |
| 9545 | try { |
| 9546 | if (phone != null) { |
| 9547 | return phone.getClientRequestStats(); |
| 9548 | } |
| 9549 | |
| 9550 | return null; |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9554 | } |
| 9555 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9556 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9557 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9558 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9559 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9560 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9561 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9562 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9563 | // commands that plumb through the RIL as root, like so: |
| 9564 | // $ adb root |
| 9565 | // $ adb shell cmd phone ... |
| 9566 | packageName = "root"; |
| 9567 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9568 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9569 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9570 | |
| 9571 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9572 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9573 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9574 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9575 | * @param state State of SIM (power down, power up, pass through) |
| 9576 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9577 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9578 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9579 | * |
| 9580 | **/ |
| 9581 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9582 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9583 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9584 | |
| 9585 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9586 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9587 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9588 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9589 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9590 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9592 | final long identity = Binder.clearCallingIdentity(); |
| 9593 | try { |
| 9594 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9595 | phone.setSimPowerState(state, null, workSource); |
| 9596 | } |
| 9597 | } finally { |
| 9598 | Binder.restoreCallingIdentity(identity); |
| 9599 | } |
| 9600 | } |
| 9601 | |
| 9602 | /** |
| 9603 | * Set SIM card power state. |
| 9604 | * |
| 9605 | * @param slotIndex SIM slot id. |
| 9606 | * @param state State of SIM (power down, power up, pass through) |
| 9607 | * @param callback callback to trigger after success or failure |
| 9608 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9609 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9610 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9611 | * |
| 9612 | **/ |
| 9613 | @Override |
| 9614 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9615 | IIntegerConsumer callback) { |
| 9616 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9617 | |
| 9618 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9619 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9620 | "setSimPowerStateForSlotWithCallback"); |
| 9621 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9622 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9623 | |
| 9624 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9625 | |
| 9626 | final long identity = Binder.clearCallingIdentity(); |
| 9627 | try { |
| 9628 | if (phone != null) { |
| 9629 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9630 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9631 | } |
| 9632 | } finally { |
| 9633 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9634 | } |
| 9635 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9636 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9637 | private boolean isUssdApiAllowed(int subId) { |
| 9638 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9639 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9640 | if (configManager == null) { |
| 9641 | return false; |
| 9642 | } |
| 9643 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9644 | if (pb == null) { |
| 9645 | return false; |
| 9646 | } |
| 9647 | return pb.getBoolean( |
| 9648 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9649 | } |
| 9650 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9651 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9652 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9653 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9654 | * @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] | 9655 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9656 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9657 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9658 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9659 | |
| 9660 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9661 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9662 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9663 | final long identity = Binder.clearCallingIdentity(); |
| 9664 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9665 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9668 | } |
| 9669 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9670 | |
| 9671 | /** |
| 9672 | * Get the current signal strength information for the given subscription. |
| 9673 | * Because this information is not updated when the device is in a low power state |
| 9674 | * it should not be relied-upon to be current. |
| 9675 | * @param subId Subscription index |
| 9676 | * @return the most recent cached signal strength info from the modem |
| 9677 | */ |
| 9678 | @Override |
| 9679 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9680 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9681 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9683 | final long identity = Binder.clearCallingIdentity(); |
| 9684 | try { |
| 9685 | Phone p = getPhone(subId); |
| 9686 | if (p == null) { |
| 9687 | return null; |
| 9688 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9690 | return p.getSignalStrength(); |
| 9691 | } finally { |
| 9692 | Binder.restoreCallingIdentity(identity); |
| 9693 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9694 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9695 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9696 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9697 | * Get the current modem radio state for the given slot. |
| 9698 | * @param slotIndex slot index. |
| 9699 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9700 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9701 | * @return the current radio power state from the modem |
| 9702 | */ |
| 9703 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9704 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9705 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9706 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9708 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9709 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9710 | } |
| 9711 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9712 | enforceTelephonyFeatureWithException(callingPackage, |
| 9713 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9714 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9715 | final long identity = Binder.clearCallingIdentity(); |
| 9716 | try { |
| 9717 | return phone.getRadioPowerState(); |
| 9718 | } finally { |
| 9719 | Binder.restoreCallingIdentity(identity); |
| 9720 | } |
| 9721 | } |
| 9722 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9723 | } |
| 9724 | |
| 9725 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9726 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9727 | * |
| 9728 | * <p>Requires one of the following permissions: |
| 9729 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9730 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9731 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9732 | * privileges. |
| 9733 | * |
| 9734 | * @param subId subscription id |
| 9735 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9736 | * {@code false}. |
| 9737 | */ |
| 9738 | @Override |
| 9739 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9740 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9741 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9742 | try { |
| 9743 | mApp.enforceCallingOrSelfPermission( |
| 9744 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9745 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9746 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9747 | mApp.enforceCallingOrSelfPermission( |
| 9748 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9749 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9750 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9751 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9752 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9753 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9754 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9755 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9756 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9757 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9758 | boolean isEnabled = false; |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9760 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9761 | Phone phone = getPhone(subId); |
| 9762 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9763 | } finally { |
| 9764 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9766 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9767 | } |
| 9768 | |
| 9769 | |
| 9770 | /** |
| 9771 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9772 | * |
| 9773 | * <p> Requires permission: |
| 9774 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9775 | * privileges. |
| 9776 | * |
| 9777 | * @param subId subscription id |
| 9778 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9779 | */ |
| 9780 | @Override |
| 9781 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9783 | mApp, subId, "setDataRoamingEnabled"); |
| 9784 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9785 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9786 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9787 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9788 | final long identity = Binder.clearCallingIdentity(); |
| 9789 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9790 | Phone phone = getPhone(subId); |
| 9791 | if (phone != null) { |
| 9792 | phone.setDataRoamingEnabled(isEnabled); |
| 9793 | } |
| 9794 | } finally { |
| 9795 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9796 | } |
| 9797 | } |
| 9798 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9799 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9800 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9801 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9802 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9803 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9804 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9805 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9806 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9807 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9808 | boolean isAllowed = true; |
| 9809 | final long identity = Binder.clearCallingIdentity(); |
| 9810 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9811 | Phone phone = getPhone(subId); |
| 9812 | if (phone != null) { |
| 9813 | isAllowed = phone.isCspPlmnEnabled(); |
| 9814 | } |
| 9815 | } finally { |
| 9816 | Binder.restoreCallingIdentity(identity); |
| 9817 | } |
| 9818 | return isAllowed; |
| 9819 | } |
| 9820 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9821 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9822 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9823 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9824 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9825 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9826 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9827 | if (phone == null) { |
| 9828 | return false; |
| 9829 | } |
| 9830 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9831 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9832 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9833 | } |
| 9834 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9835 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9836 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9837 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9838 | mApp.getSystemService(AppOpsManager.class) |
| 9839 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9840 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9841 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9842 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9843 | try { |
| 9844 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9845 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9846 | } catch (SecurityException e) { |
| 9847 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9848 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9849 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9850 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9851 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9852 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9853 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9854 | |
| 9855 | enforceTelephonyFeatureWithException(callingPackage, |
| 9856 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9857 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9858 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9859 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9860 | Binder.getCallingUid())) { |
| 9861 | isIccIdAccessRestricted = true; |
| 9862 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9863 | final long identity = Binder.clearCallingIdentity(); |
| 9864 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9865 | UiccController uiccController = UiccController.getInstance(); |
| 9866 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9867 | if (hasReadPermission) { |
| 9868 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9869 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9870 | |
| 9871 | // Remove private info if the caller doesn't have access |
| 9872 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9873 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9874 | //setting the value after compatibility check |
| 9875 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9876 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9877 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9878 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9879 | if (card == null) { |
| 9880 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9881 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9882 | continue; |
| 9883 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9884 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9885 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9886 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9887 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9888 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9889 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9890 | for (UiccPortInfo portInfo : portInfos) { |
| 9891 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9892 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9893 | if (port == null) { |
| 9894 | // assume no access if port is null |
| 9895 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9896 | continue; |
| 9897 | } |
| 9898 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9899 | uiccPortInfos.add(portInfo); |
| 9900 | } else { |
| 9901 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9902 | } |
| 9903 | } |
| 9904 | filteredInfos.add(new UiccCardInfo( |
| 9905 | cardInfo.isEuicc(), |
| 9906 | cardInfo.getCardId(), |
| 9907 | null, |
| 9908 | cardInfo.getPhysicalSlotIndex(), |
| 9909 | cardInfo.isRemovable(), |
| 9910 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9911 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9912 | } |
| 9913 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9914 | } finally { |
| 9915 | Binder.restoreCallingIdentity(identity); |
| 9916 | } |
| 9917 | } |
| 9918 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9919 | /** |
| 9920 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9921 | * generally private and require carrier privileges to view. |
| 9922 | * |
| 9923 | * @hide |
| 9924 | */ |
| 9925 | @NonNull |
| 9926 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9927 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9928 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9929 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9930 | } |
| 9931 | return new UiccCardInfo( |
| 9932 | cardInfo.isEuicc(), |
| 9933 | cardInfo.getCardId(), |
| 9934 | null, |
| 9935 | cardInfo.getPhysicalSlotIndex(), |
| 9936 | cardInfo.isRemovable(), |
| 9937 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9938 | portinfo |
| 9939 | ); |
| 9940 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9941 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9942 | /** |
| 9943 | * @hide |
| 9944 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9945 | * These values are generally private and require carrier privileges to view. |
| 9946 | */ |
| 9947 | @NonNull |
| 9948 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9949 | return new UiccPortInfo( |
| 9950 | UiccPortInfo.ICCID_REDACTED, |
| 9951 | portInfo.getPortIndex(), |
| 9952 | portInfo.getLogicalSlotIndex(), |
| 9953 | portInfo.isActive() |
| 9954 | ); |
| 9955 | } |
| 9956 | @Override |
| 9957 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9958 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9959 | mApp.getSystemService(AppOpsManager.class) |
| 9960 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9961 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9962 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9963 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9964 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9965 | // we are reading iccId which is PII data. |
| 9966 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9967 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9968 | enforceTelephonyFeatureWithException(callingPackage, |
| 9969 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9970 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9971 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9972 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9973 | Binder.getCallingUid())) { |
| 9974 | isLogicalSlotAccessRestricted = true; |
| 9975 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9976 | final long identity = Binder.clearCallingIdentity(); |
| 9977 | try { |
| 9978 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9979 | if (slots == null || slots.length == 0) { |
| 9980 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9981 | return null; |
| 9982 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9983 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9984 | for (int i = 0; i < slots.length; i++) { |
| 9985 | UiccSlot slot = slots[i]; |
| 9986 | if (slot == null) { |
| 9987 | continue; |
| 9988 | } |
| 9989 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9990 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9991 | UiccCard card = slot.getUiccCard(); |
| 9992 | if (card != null) { |
| 9993 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9994 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9995 | cardId = slot.getEid(); |
| 9996 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9997 | // If cardId is null, use iccId of default port as cardId. |
| 9998 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10000 | } |
| 10001 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10002 | if (cardId != null) { |
| 10003 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10004 | // if cardId is an EID, it's all digits so this is fine |
| 10005 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10006 | } |
| 10007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10008 | int cardState = 0; |
| 10009 | switch (slot.getCardState()) { |
| 10010 | case CARDSTATE_ABSENT: |
| 10011 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10012 | break; |
| 10013 | case CARDSTATE_PRESENT: |
| 10014 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10015 | break; |
| 10016 | case CARDSTATE_ERROR: |
| 10017 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10018 | break; |
| 10019 | case CARDSTATE_RESTRICTED: |
| 10020 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10021 | break; |
| 10022 | default: |
| 10023 | break; |
| 10024 | |
| 10025 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10026 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10027 | int[] portIndexes = slot.getPortList(); |
| 10028 | for (int portIdx : portIndexes) { |
| 10029 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10030 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10031 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10032 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10034 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10035 | slot.isEuicc(), |
| 10036 | cardId, |
| 10037 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10038 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10039 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10040 | //setting the value after compatibility check |
| 10041 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10042 | } |
| 10043 | return infos; |
| 10044 | } finally { |
| 10045 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10046 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10047 | } |
| 10048 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10049 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10050 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10051 | boolean hasReadPermission) { |
| 10052 | String iccId = slot.getIccId(portIndex); |
| 10053 | if (hasReadPermission) { // if has read permission |
| 10054 | return iccId; |
| 10055 | } else { |
| 10056 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10057 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10058 | // if no read permission, checking carrier privilege access |
| 10059 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10060 | return iccId; |
| 10061 | } |
| 10062 | } |
| 10063 | } |
| 10064 | // No read permission or carrier privilege access. |
| 10065 | return UiccPortInfo.ICCID_REDACTED; |
| 10066 | } |
| 10067 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10068 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10069 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10070 | public boolean switchSlots(int[] physicalSlots) { |
| 10071 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10072 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10073 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10074 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10075 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10076 | final long identity = Binder.clearCallingIdentity(); |
| 10077 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10078 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10079 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10080 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10081 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10082 | physicalSlots[i], i)); |
| 10083 | } |
| 10084 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10085 | } finally { |
| 10086 | Binder.restoreCallingIdentity(identity); |
| 10087 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10088 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10089 | |
| 10090 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10091 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10092 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10093 | enforceModifyPermission(); |
| 10094 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10095 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10096 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10097 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10098 | final long identity = Binder.clearCallingIdentity(); |
| 10099 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10100 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10101 | } finally { |
| 10102 | Binder.restoreCallingIdentity(identity); |
| 10103 | } |
| 10104 | } |
| 10105 | |
| 10106 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10107 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10108 | enforceTelephonyFeatureWithException(callingPackage, |
| 10109 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10110 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10111 | final long identity = Binder.clearCallingIdentity(); |
| 10112 | try { |
| 10113 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10114 | } finally { |
| 10115 | Binder.restoreCallingIdentity(identity); |
| 10116 | } |
| 10117 | } |
| 10118 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10119 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10120 | * A test API to reload the UICC profile. |
| 10121 | * |
| 10122 | * <p>Requires that the calling app has permission |
| 10123 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10124 | * @hide |
| 10125 | */ |
| 10126 | @Override |
| 10127 | public void refreshUiccProfile(int subId) { |
| 10128 | enforceModifyPermission(); |
| 10129 | |
| 10130 | final long identity = Binder.clearCallingIdentity(); |
| 10131 | try { |
| 10132 | Phone phone = getPhone(subId); |
| 10133 | if (phone == null) { |
| 10134 | return; |
| 10135 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10136 | UiccPort uiccPort = phone.getUiccPort(); |
| 10137 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10138 | return; |
| 10139 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10140 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10141 | if (uiccProfile == null) { |
| 10142 | return; |
| 10143 | } |
| 10144 | uiccProfile.refresh(); |
| 10145 | } finally { |
| 10146 | Binder.restoreCallingIdentity(identity); |
| 10147 | } |
| 10148 | } |
| 10149 | |
| 10150 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10151 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10152 | */ |
| 10153 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10154 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
| 10157 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10158 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10159 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10160 | */ |
| 10161 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10162 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10163 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10164 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10165 | return list.get(phoneId); |
| 10166 | } |
| 10167 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10168 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10169 | |
| 10170 | @Override |
| 10171 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10172 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10173 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10174 | |
| 10175 | final long identity = Binder.clearCallingIdentity(); |
| 10176 | try { |
| 10177 | final Phone phone = getPhone(subId); |
| 10178 | if (phone == null) { |
| 10179 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10180 | return; |
| 10181 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10182 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10183 | if (cpt != null) { |
| 10184 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10185 | } |
| 10186 | // 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] | 10187 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10188 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10189 | if (carrierPrivilegeRules == null) { |
| 10190 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10191 | } else { |
| 10192 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10194 | } finally { |
| 10195 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10196 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10197 | } |
| 10198 | |
| 10199 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10200 | public void setCarrierServicePackageOverride( |
| 10201 | int subId, String carrierServicePackage, String callingPackage) { |
| 10202 | TelephonyPermissions.enforceShellOnly( |
| 10203 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10204 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10205 | final long identity = Binder.clearCallingIdentity(); |
| 10206 | try { |
| 10207 | final Phone phone = getPhone(subId); |
| 10208 | if (phone == null || phone.getSubId() != subId) { |
| 10209 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10210 | throw new IllegalArgumentException("No phone for subid"); |
| 10211 | } |
| 10212 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10213 | if (cpt == null) { |
| 10214 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10215 | throw new IllegalStateException("No CPT for phone"); |
| 10216 | } |
| 10217 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10218 | } finally { |
| 10219 | Binder.restoreCallingIdentity(identity); |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10224 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10225 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10226 | |
| 10227 | final long identity = Binder.clearCallingIdentity(); |
| 10228 | try { |
| 10229 | final Phone phone = getPhone(subId); |
| 10230 | if (phone == null) { |
| 10231 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10232 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10233 | } |
| 10234 | return phone.getCarrierIdListVersion(); |
| 10235 | } finally { |
| 10236 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10237 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10238 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10239 | |
| 10240 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10241 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10242 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10243 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10244 | mApp, subId, callingPackage, callingFeatureId, |
| 10245 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10246 | return -1; |
| 10247 | } |
| 10248 | |
| 10249 | final long identity = Binder.clearCallingIdentity(); |
| 10250 | try { |
| 10251 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10252 | } finally { |
| 10253 | Binder.restoreCallingIdentity(identity); |
| 10254 | } |
| 10255 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10256 | |
| 10257 | @Override |
| 10258 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10259 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10260 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10261 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10262 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10264 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10265 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10266 | final long identity = Binder.clearCallingIdentity(); |
| 10267 | try { |
| 10268 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10269 | } finally { |
| 10270 | Binder.restoreCallingIdentity(identity); |
| 10271 | } |
| 10272 | } |
| 10273 | |
| 10274 | @Override |
| 10275 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10277 | mApp, subId, "setCdmaRoamingMode"); |
| 10278 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10279 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10280 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10281 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10282 | final long identity = Binder.clearCallingIdentity(); |
| 10283 | try { |
| 10284 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10285 | } finally { |
| 10286 | Binder.restoreCallingIdentity(identity); |
| 10287 | } |
| 10288 | } |
| 10289 | |
| 10290 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10291 | public int getCdmaSubscriptionMode(int subId) { |
| 10292 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10293 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10294 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10295 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10296 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10297 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10298 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10299 | final long identity = Binder.clearCallingIdentity(); |
| 10300 | try { |
| 10301 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10302 | } finally { |
| 10303 | Binder.restoreCallingIdentity(identity); |
| 10304 | } |
| 10305 | } |
| 10306 | |
| 10307 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10308 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10310 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10311 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10312 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10313 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10314 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10315 | final long identity = Binder.clearCallingIdentity(); |
| 10316 | try { |
| 10317 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10318 | } finally { |
| 10319 | Binder.restoreCallingIdentity(identity); |
| 10320 | } |
| 10321 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10322 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10323 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10324 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10325 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10327 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10328 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10329 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10330 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10331 | |
| 10332 | enforceTelephonyFeatureWithException(callingPackage, |
| 10333 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10334 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10335 | final long identity = Binder.clearCallingIdentity(); |
| 10336 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10337 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10338 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10339 | if (phone.getEmergencyNumberTracker() != null |
| 10340 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10341 | emergencyNumberListInternal.put( |
| 10342 | phone.getSubId(), |
| 10343 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10344 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10345 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10346 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10347 | } finally { |
| 10348 | Binder.restoreCallingIdentity(identity); |
| 10349 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10350 | } |
| 10351 | |
| 10352 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10353 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10354 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10355 | if (!exactMatch) { |
| 10356 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10357 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10358 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10359 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10360 | |
| 10361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10362 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10363 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10364 | final long identity = Binder.clearCallingIdentity(); |
| 10365 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10366 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10367 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10368 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10369 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10370 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10371 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10372 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10373 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10374 | } |
| 10375 | return false; |
| 10376 | } finally { |
| 10377 | Binder.restoreCallingIdentity(identity); |
| 10378 | } |
| 10379 | } |
| 10380 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10381 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10382 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10383 | */ |
| 10384 | @Override |
| 10385 | public void startEmergencyCallbackMode() { |
| 10386 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10387 | "startEmergencyCallbackMode"); |
| 10388 | enforceModifyPermission(); |
| 10389 | final long identity = Binder.clearCallingIdentity(); |
| 10390 | try { |
| 10391 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10392 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10393 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10394 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10395 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10396 | gsmCdmaPhone.obtainMessage( |
| 10397 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10398 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10399 | } |
| 10400 | } |
| 10401 | } finally { |
| 10402 | Binder.restoreCallingIdentity(identity); |
| 10403 | } |
| 10404 | } |
| 10405 | |
| 10406 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10407 | * Update emergency number list for test mode. |
| 10408 | */ |
| 10409 | @Override |
| 10410 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10411 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10412 | "updateEmergencyNumberListTestMode"); |
| 10413 | |
| 10414 | final long identity = Binder.clearCallingIdentity(); |
| 10415 | try { |
| 10416 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10417 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10418 | if (tracker != null) { |
| 10419 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10420 | } |
| 10421 | } |
| 10422 | } finally { |
| 10423 | Binder.restoreCallingIdentity(identity); |
| 10424 | } |
| 10425 | } |
| 10426 | |
| 10427 | /** |
| 10428 | * Get the full emergency number list for test mode. |
| 10429 | */ |
| 10430 | @Override |
| 10431 | public List<String> getEmergencyNumberListTestMode() { |
| 10432 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10433 | "getEmergencyNumberListTestMode"); |
| 10434 | |
| 10435 | final long identity = Binder.clearCallingIdentity(); |
| 10436 | try { |
| 10437 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10438 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10439 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10440 | if (tracker != null) { |
| 10441 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10442 | emergencyNumbers.add(num.getNumber()); |
| 10443 | } |
| 10444 | } |
| 10445 | } |
| 10446 | return new ArrayList<>(emergencyNumbers); |
| 10447 | } finally { |
| 10448 | Binder.restoreCallingIdentity(identity); |
| 10449 | } |
| 10450 | } |
| 10451 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10452 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10453 | public int getEmergencyNumberDbVersion(int subId) { |
| 10454 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10455 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10456 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10457 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10458 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10459 | final long identity = Binder.clearCallingIdentity(); |
| 10460 | try { |
| 10461 | final Phone phone = getPhone(subId); |
| 10462 | if (phone == null) { |
| 10463 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10464 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10465 | } |
| 10466 | return phone.getEmergencyNumberDbVersion(); |
| 10467 | } finally { |
| 10468 | Binder.restoreCallingIdentity(identity); |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | @Override |
| 10473 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10474 | enforceModifyPermission(); |
| 10475 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10476 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10477 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10478 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10479 | final long identity = Binder.clearCallingIdentity(); |
| 10480 | try { |
| 10481 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10482 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10483 | if (tracker != null) { |
| 10484 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10485 | } |
| 10486 | } |
| 10487 | } finally { |
| 10488 | Binder.restoreCallingIdentity(identity); |
| 10489 | } |
| 10490 | } |
| 10491 | |
| 10492 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10493 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10494 | enforceActiveEmergencySessionPermission(); |
| 10495 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10496 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10497 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10498 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10502 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10503 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10504 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10505 | } |
| 10506 | } |
| 10507 | } finally { |
| 10508 | Binder.restoreCallingIdentity(identity); |
| 10509 | } |
| 10510 | } |
| 10511 | |
| 10512 | @Override |
| 10513 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10514 | enforceActiveEmergencySessionPermission(); |
| 10515 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10516 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10517 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10518 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10519 | final long identity = Binder.clearCallingIdentity(); |
| 10520 | try { |
| 10521 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10522 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10523 | if (tracker != null) { |
| 10524 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10525 | } |
| 10526 | } |
| 10527 | } finally { |
| 10528 | Binder.restoreCallingIdentity(identity); |
| 10529 | } |
| 10530 | } |
| 10531 | |
| 10532 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10533 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10534 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10535 | Phone phone = getPhone(subId); |
| 10536 | if (phone == null) { |
| 10537 | return null; |
| 10538 | } |
| 10539 | final long identity = Binder.clearCallingIdentity(); |
| 10540 | try { |
| 10541 | UiccProfile profile = UiccController.getInstance() |
| 10542 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10543 | if (profile != null) { |
| 10544 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10545 | } |
| 10546 | } finally { |
| 10547 | Binder.restoreCallingIdentity(identity); |
| 10548 | } |
| 10549 | return null; |
| 10550 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10551 | |
| 10552 | /** |
| 10553 | * Enable or disable a modem stack. |
| 10554 | */ |
| 10555 | @Override |
| 10556 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10557 | enforceModifyPermission(); |
| 10558 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10559 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10560 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10561 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10562 | final long identity = Binder.clearCallingIdentity(); |
| 10563 | try { |
| 10564 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10565 | if (phone == null) { |
| 10566 | return false; |
| 10567 | } else { |
| 10568 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10569 | } |
| 10570 | } finally { |
| 10571 | Binder.restoreCallingIdentity(identity); |
| 10572 | } |
| 10573 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10574 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10575 | /** |
| 10576 | * Whether a modem stack is enabled or not. |
| 10577 | */ |
| 10578 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10579 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10580 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10581 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10582 | if (phone == null) return false; |
| 10583 | |
| 10584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10585 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10586 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10587 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10588 | } |
| 10589 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10590 | enforceTelephonyFeatureWithException(callingPackage, |
| 10591 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10592 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10593 | final long identity = Binder.clearCallingIdentity(); |
| 10594 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10595 | try { |
| 10596 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10597 | } catch (NoSuchElementException ex) { |
| 10598 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10599 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10600 | } finally { |
| 10601 | Binder.restoreCallingIdentity(identity); |
| 10602 | } |
| 10603 | } |
| 10604 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10605 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10606 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10607 | enforceModifyPermission(); |
| 10608 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10609 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10610 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10611 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10612 | final long identity = Binder.clearCallingIdentity(); |
| 10613 | try { |
| 10614 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10615 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10616 | .commit(); |
| 10617 | } finally { |
| 10618 | Binder.restoreCallingIdentity(identity); |
| 10619 | } |
| 10620 | } |
| 10621 | |
| 10622 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10623 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10624 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10626 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10627 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10628 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10629 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10630 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10631 | enforceTelephonyFeatureWithException(callingPackage, |
| 10632 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10633 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10634 | final long identity = Binder.clearCallingIdentity(); |
| 10635 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10636 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10637 | } finally { |
| 10638 | Binder.restoreCallingIdentity(identity); |
| 10639 | } |
| 10640 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10641 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10642 | @TelephonyManager.IsMultiSimSupportedResult |
| 10643 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10644 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10645 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10646 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10647 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10648 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10649 | } |
| 10650 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10651 | // supported by the modem, indicate that it is restricted. |
| 10652 | PhoneCapability staticCapability = |
| 10653 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10654 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10655 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10656 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10657 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10658 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10659 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10660 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10661 | } |
| 10662 | // Check if support of multiple SIMs is restricted by carrier |
| 10663 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10664 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10665 | } |
| 10666 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10667 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10668 | } |
| 10669 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10670 | /** |
| 10671 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10672 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10673 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10674 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10675 | * @param numOfSims number of active sims we want to switch to |
| 10676 | */ |
| 10677 | @Override |
| 10678 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10679 | if (numOfSims == 1) { |
| 10680 | enforceModifyPermission(); |
| 10681 | } else { |
| 10682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10683 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10684 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10685 | |
| 10686 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10687 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10688 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10689 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10690 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10691 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10692 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10693 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10694 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10695 | return; |
| 10696 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10697 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10698 | } finally { |
| 10699 | Binder.restoreCallingIdentity(identity); |
| 10700 | } |
| 10701 | } |
| 10702 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10703 | @Override |
| 10704 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10705 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10706 | |
| 10707 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10708 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10709 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10710 | Phone phone = getPhone(subId); |
| 10711 | if (phone == null) { |
| 10712 | return false; |
| 10713 | } |
| 10714 | final long identity = Binder.clearCallingIdentity(); |
| 10715 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10716 | UiccPort uiccPort = phone.getUiccPort(); |
| 10717 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10718 | return false; |
| 10719 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10720 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10721 | if (uiccProfile == null) { |
| 10722 | return false; |
| 10723 | } |
| 10724 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10725 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10726 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10727 | } |
| 10728 | return false; |
| 10729 | } finally { |
| 10730 | Binder.restoreCallingIdentity(identity); |
| 10731 | } |
| 10732 | } |
| 10733 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10734 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10735 | * Get whether making changes to modem configurations will trigger reboot. |
| 10736 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10737 | */ |
| 10738 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10739 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10740 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10741 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10742 | mApp, subId, callingPackage, callingFeatureId, |
| 10743 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10744 | return false; |
| 10745 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10746 | |
| 10747 | enforceTelephonyFeatureWithException(callingPackage, |
| 10748 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10749 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10750 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10751 | final long identity = Binder.clearCallingIdentity(); |
| 10752 | try { |
| 10753 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10754 | } finally { |
| 10755 | Binder.restoreCallingIdentity(identity); |
| 10756 | } |
| 10757 | } |
| 10758 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10759 | private void updateModemStateMetrics() { |
| 10760 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10761 | // TODO: check the state for each modem if the api is ready. |
| 10762 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10763 | } |
| 10764 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10765 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10766 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10767 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10768 | // Verify that the callingPackage belongs to the calling UID |
| 10769 | mApp.getSystemService(AppOpsManager.class) |
| 10770 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10771 | |
| 10772 | enforceTelephonyFeatureWithException(callingPackage, |
| 10773 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10774 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10775 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10776 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10777 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10778 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10779 | if (slotInfos != null) { |
| 10780 | for (int i = 0; i < slotInfos.length; i++) { |
| 10781 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10782 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10783 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10784 | portInfo.getLogicalSlotIndex())); |
| 10785 | } |
| 10786 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10787 | } |
| 10788 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10789 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10790 | } finally { |
| 10791 | Binder.restoreCallingIdentity(identity); |
| 10792 | } |
| 10793 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10794 | |
| 10795 | /** |
| 10796 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10797 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10798 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10799 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10800 | @Override |
| 10801 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10802 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10803 | } |
| 10804 | |
| 10805 | /** |
| 10806 | * Get the HAL Version of a specific service |
| 10807 | */ |
| 10808 | @Override |
| 10809 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10810 | Phone phone = getDefaultPhone(); |
| 10811 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10812 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10813 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10814 | return hv.major * 100 + hv.minor; |
| 10815 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10816 | |
| 10817 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10818 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10819 | * |
| 10820 | * @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] | 10821 | */ |
| 10822 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10823 | public @Nullable String getCurrentPackageName() { |
| 10824 | PackageManager pm = mApp.getPackageManager(); |
| 10825 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10826 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10827 | } |
| 10828 | |
| 10829 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10830 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10831 | * corresponding network requests on a subId. |
| 10832 | * |
| 10833 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10834 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10835 | * 2) APN is un-metered for this subscription, or |
| 10836 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10837 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10838 | * |
| 10839 | * @return whether data is allowed for a apn type. |
| 10840 | * |
| 10841 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10842 | */ |
| 10843 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10844 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10845 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10846 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10847 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10848 | enforceTelephonyFeatureWithException(callingPackage, |
| 10849 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10850 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10851 | // Now that all security checks passes, perform the operation as ourselves. |
| 10852 | final long identity = Binder.clearCallingIdentity(); |
| 10853 | try { |
| 10854 | Phone phone = getPhone(subId); |
| 10855 | if (phone == null) return false; |
| 10856 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10857 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10858 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10859 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10860 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10861 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10862 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10863 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10864 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10865 | } finally { |
| 10866 | Binder.restoreCallingIdentity(identity); |
| 10867 | } |
| 10868 | } |
| 10869 | |
| 10870 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10871 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10872 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10873 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10874 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10875 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10876 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10877 | // Now that all security checks passes, perform the operation as ourselves. |
| 10878 | final long identity = Binder.clearCallingIdentity(); |
| 10879 | try { |
| 10880 | Phone phone = getPhone(subId); |
| 10881 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10882 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10883 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10884 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10885 | } finally { |
| 10886 | Binder.restoreCallingIdentity(identity); |
| 10887 | } |
| 10888 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10889 | |
| 10890 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10891 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10892 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10893 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10894 | |
| 10895 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10896 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10897 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10898 | long token = Binder.clearCallingIdentity(); |
| 10899 | try { |
| 10900 | Phone phone = getPhone(subscriptionId); |
| 10901 | if (phone == null) { |
| 10902 | try { |
| 10903 | if (resultCallback != null) { |
| 10904 | resultCallback.accept(false); |
| 10905 | } |
| 10906 | } catch (RemoteException e) { |
| 10907 | // ignore |
| 10908 | } |
| 10909 | return; |
| 10910 | } |
| 10911 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10912 | Pair.create(specifiers, (x) -> { |
| 10913 | try { |
| 10914 | if (resultCallback != null) { |
| 10915 | resultCallback.accept(x); |
| 10916 | } |
| 10917 | } catch (RemoteException e) { |
| 10918 | // ignore |
| 10919 | } |
| 10920 | }); |
| 10921 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10922 | } finally { |
| 10923 | Binder.restoreCallingIdentity(token); |
| 10924 | } |
| 10925 | } |
| 10926 | |
| 10927 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10928 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10929 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10930 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10931 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10932 | |
| 10933 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10934 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10935 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10936 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10937 | final long identity = Binder.clearCallingIdentity(); |
| 10938 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10939 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10940 | if (result instanceof IllegalStateException) { |
| 10941 | throw (IllegalStateException) result; |
| 10942 | } |
| 10943 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10944 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10945 | return specifiers; |
| 10946 | } finally { |
| 10947 | Binder.restoreCallingIdentity(identity); |
| 10948 | } |
| 10949 | } |
| 10950 | |
| 10951 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10952 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10953 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10954 | |
| 10955 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10956 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10957 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10958 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10959 | } |
| 10960 | |
| 10961 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10962 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10963 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10964 | if (callingPackage == null) { |
| 10965 | callingPackage = getCurrentPackageName(); |
| 10966 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10967 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10968 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10969 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10970 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10971 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10972 | } |
| 10973 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10974 | Intent intent = new Intent(); |
| 10975 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10976 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10977 | // Bring up choose default SMS subscription dialog right now |
| 10978 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10979 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10980 | mApp.startActivity(intent); |
| 10981 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10982 | |
| 10983 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10984 | public void showSwitchToManagedProfileDialog() { |
| 10985 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10986 | try { |
| 10987 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10988 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10989 | // for work telephony. |
| 10990 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10991 | intent.setData(Uri.parse("smsto:")); |
| 10992 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10993 | mApp.startActivity(intent); |
| 10994 | } catch (ActivityNotFoundException e) { |
| 10995 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10996 | Intent intent = new Intent(); |
| 10997 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10998 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10999 | mApp.startActivity(intent); |
| 11000 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11001 | } |
| 11002 | |
| 11003 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11004 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11005 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11006 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11007 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11008 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11009 | final long identity = Binder.clearCallingIdentity(); |
| 11010 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11011 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11012 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11013 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11014 | return carrierUAProfUrl; |
| 11015 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11016 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11017 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11018 | } finally { |
| 11019 | Binder.restoreCallingIdentity(identity); |
| 11020 | } |
| 11021 | } |
| 11022 | |
| 11023 | @Override |
| 11024 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11026 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11027 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11028 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11029 | final long identity = Binder.clearCallingIdentity(); |
| 11030 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11031 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11032 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11033 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11034 | return carrierUserAgent; |
| 11035 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11036 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11037 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11038 | } finally { |
| 11039 | Binder.restoreCallingIdentity(identity); |
| 11040 | } |
| 11041 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11042 | |
| 11043 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11044 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11045 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11046 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11047 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11048 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11049 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11050 | final long identity = Binder.clearCallingIdentity(); |
| 11051 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11052 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11053 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11054 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11055 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11056 | } finally { |
| 11057 | Binder.restoreCallingIdentity(identity); |
| 11058 | } |
| 11059 | } |
| 11060 | |
| 11061 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11062 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11063 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11064 | enforceModifyPermission(); |
| 11065 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11066 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11067 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11068 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11071 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11072 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11073 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11074 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11075 | } finally { |
| 11076 | Binder.restoreCallingIdentity(identity); |
| 11077 | } |
| 11078 | } |
| 11079 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11080 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11081 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11082 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11083 | * otherwise. |
| 11084 | */ |
| 11085 | @Override |
| 11086 | public void setCepEnabled(boolean isCepEnabled) { |
| 11087 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11088 | |
| 11089 | final long identity = Binder.clearCallingIdentity(); |
| 11090 | try { |
| 11091 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11092 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11093 | Phone defaultPhone = phone.getImsPhone(); |
| 11094 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11095 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11096 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11097 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11098 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11099 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11100 | + imsPhone.getMsisdn()); |
| 11101 | } |
| 11102 | } |
| 11103 | } finally { |
| 11104 | Binder.restoreCallingIdentity(identity); |
| 11105 | } |
| 11106 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11107 | |
| 11108 | /** |
| 11109 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11110 | * |
| 11111 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11112 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11113 | * before being read. |
| 11114 | */ |
| 11115 | @Override |
| 11116 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11117 | isCompressed) { |
| 11118 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11119 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11120 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11121 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11122 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11123 | |
| 11124 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11125 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11126 | Binder.getCallingUserHandle())) { |
| 11127 | if (!isImsAvailableOnDevice()) { |
| 11128 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11129 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11130 | throw new IllegalStateException("IMS not available on device."); |
| 11131 | } |
| 11132 | } else { |
| 11133 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11134 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11135 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11136 | } |
| 11137 | |
| 11138 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11139 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11140 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11141 | } finally { |
| 11142 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11143 | } |
| 11144 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11145 | |
| 11146 | @Override |
| 11147 | public boolean isIccLockEnabled(int subId) { |
| 11148 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11149 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11150 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11151 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11152 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11153 | // Now that all security checks passes, perform the operation as ourselves. |
| 11154 | final long identity = Binder.clearCallingIdentity(); |
| 11155 | try { |
| 11156 | Phone phone = getPhone(subId); |
| 11157 | if (phone != null && phone.getIccCard() != null) { |
| 11158 | return phone.getIccCard().getIccLockEnabled(); |
| 11159 | } else { |
| 11160 | return false; |
| 11161 | } |
| 11162 | } finally { |
| 11163 | Binder.restoreCallingIdentity(identity); |
| 11164 | } |
| 11165 | } |
| 11166 | |
| 11167 | /** |
| 11168 | * Set the ICC pin lock enabled or disabled. |
| 11169 | * |
| 11170 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11171 | * three cases: |
| 11172 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11173 | * successfully. |
| 11174 | * - Positive number and zero for remaining password attempts. |
| 11175 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11176 | * |
| 11177 | */ |
| 11178 | @Override |
| 11179 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11180 | enforceModifyPermission(); |
| 11181 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11182 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11183 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11184 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11185 | Phone phone = getPhone(subId); |
| 11186 | if (phone == null) { |
| 11187 | return 0; |
| 11188 | } |
| 11189 | // Now that all security checks passes, perform the operation as ourselves. |
| 11190 | final long identity = Binder.clearCallingIdentity(); |
| 11191 | try { |
| 11192 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11193 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11194 | return attemptsRemaining; |
| 11195 | |
| 11196 | } catch (Exception e) { |
| 11197 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11198 | } finally { |
| 11199 | Binder.restoreCallingIdentity(identity); |
| 11200 | } |
| 11201 | return 0; |
| 11202 | } |
| 11203 | |
| 11204 | /** |
| 11205 | * Change the ICC password used in ICC pin lock. |
| 11206 | * |
| 11207 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11208 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11209 | * - Positive number and zero for remaining password attempts. |
| 11210 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11211 | * |
| 11212 | */ |
| 11213 | @Override |
| 11214 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11215 | enforceModifyPermission(); |
| 11216 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11217 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11218 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11219 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11220 | Phone phone = getPhone(subId); |
| 11221 | if (phone == null) { |
| 11222 | return 0; |
| 11223 | } |
| 11224 | // Now that all security checks passes, perform the operation as ourselves. |
| 11225 | final long identity = Binder.clearCallingIdentity(); |
| 11226 | try { |
| 11227 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11228 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11229 | return attemptsRemaining; |
| 11230 | |
| 11231 | } catch (Exception e) { |
| 11232 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11233 | } finally { |
| 11234 | Binder.restoreCallingIdentity(identity); |
| 11235 | } |
| 11236 | return 0; |
| 11237 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11238 | |
| 11239 | /** |
| 11240 | * Request for receiving user activity notification |
| 11241 | */ |
| 11242 | @Override |
| 11243 | public void requestUserActivityNotification() { |
| 11244 | if (!mNotifyUserActivity.get() |
| 11245 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11246 | mNotifyUserActivity.set(true); |
| 11247 | } |
| 11248 | } |
| 11249 | |
| 11250 | /** |
| 11251 | * Called when userActivity is signalled in the power manager. |
| 11252 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11253 | */ |
| 11254 | @Override |
| 11255 | public void userActivity() { |
| 11256 | // *************************************** |
| 11257 | // * Inherited from PhoneWindowManager * |
| 11258 | // *************************************** |
| 11259 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11260 | // WITH ITS LOCKS HELD. |
| 11261 | // |
| 11262 | // This code must be VERY careful about the locks |
| 11263 | // it acquires. |
| 11264 | // In fact, the current code acquires way too many, |
| 11265 | // and probably has lurking deadlocks. |
| 11266 | |
| 11267 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11268 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11269 | } |
| 11270 | |
| 11271 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11272 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11273 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11274 | } |
| 11275 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11276 | |
| 11277 | @Override |
| 11278 | public boolean canConnectTo5GInDsdsMode() { |
| 11279 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11280 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11281 | |
| 11282 | @Override |
| 11283 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11284 | String callingFeatureId) { |
| 11285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11286 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11287 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11288 | } |
| 11289 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11290 | enforceTelephonyFeatureWithException(callingPackage, |
| 11291 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11292 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11293 | Phone phone = getPhone(subId); |
| 11294 | if (phone == null) { |
| 11295 | throw new RuntimeException("phone is not available"); |
| 11296 | } |
| 11297 | // Now that all security checks passes, perform the operation as ourselves. |
| 11298 | final long identity = Binder.clearCallingIdentity(); |
| 11299 | try { |
| 11300 | return phone.getEquivalentHomePlmns(); |
| 11301 | } finally { |
| 11302 | Binder.restoreCallingIdentity(identity); |
| 11303 | } |
| 11304 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11305 | |
| 11306 | @Override |
| 11307 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11308 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11309 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11310 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11311 | "isRadioInterfaceCapabilitySupported"); |
| 11312 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11313 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11314 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11315 | if (radioInterfaceCapabilities == null) { |
| 11316 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11317 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11318 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11319 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11320 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11321 | @Override |
| 11322 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11323 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11324 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11325 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11326 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11327 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11328 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11329 | |
| 11330 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11331 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11332 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11333 | if (DBG) { |
| 11334 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11335 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11336 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11337 | } |
| 11338 | |
| 11339 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11340 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11341 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11342 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11343 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11344 | if (callback != null) { |
| 11345 | try { |
| 11346 | callback.onAuthenticationFailure( |
| 11347 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11348 | } catch (RemoteException exception) { |
| 11349 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11350 | } |
| 11351 | return; |
| 11352 | } |
| 11353 | } |
| 11354 | |
| 11355 | final long token = Binder.clearCallingIdentity(); |
| 11356 | try { |
| 11357 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11358 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11359 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11360 | } finally { |
| 11361 | Binder.restoreCallingIdentity(token); |
| 11362 | } |
| 11363 | } |
| 11364 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11365 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11366 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11367 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11368 | * requested radio power state will actually be set. See {@link |
| 11369 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11370 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11371 | * @param enable {@code true} if trying to turn radio on. |
| 11372 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11373 | * false}. |
| 11374 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11375 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11376 | boolean isPhoneAvailable = false; |
| 11377 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11378 | Phone phone = PhoneFactory.getPhone(i); |
| 11379 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11380 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11381 | isPhoneAvailable = true; |
| 11382 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11383 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11384 | |
| 11385 | // return true if successfully informed the phone object about the thermal radio power |
| 11386 | // request. |
| 11387 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11388 | } |
| 11389 | |
| 11390 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11391 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11392 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11393 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11394 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11395 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11396 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11397 | } |
| 11398 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11399 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11400 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11401 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11402 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11403 | } |
| 11404 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11405 | setDataEnabledForReason( |
| 11406 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11407 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11408 | if (isDataThrottlingSupported) { |
| 11409 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11410 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11411 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11412 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11413 | } else if (thermalMitigationResult |
| 11414 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11415 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11416 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11417 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11418 | } |
| 11419 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11420 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11421 | |
| 11422 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11423 | } |
| 11424 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11425 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11426 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11427 | for (String pckg : context.getResources() |
| 11428 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11429 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11430 | } |
| 11431 | } |
| 11432 | |
| 11433 | return sThermalMitigationAllowlistedPackages; |
| 11434 | } |
| 11435 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11436 | private boolean isAnyPhoneInEmergencyState() { |
| 11437 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11438 | if (tm.isInEmergencyCall()) { |
| 11439 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11440 | return true; |
| 11441 | } |
| 11442 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11443 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11444 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11445 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11446 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11447 | return true; |
| 11448 | } |
| 11449 | } |
| 11450 | |
| 11451 | return false; |
| 11452 | } |
| 11453 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11454 | /** |
| 11455 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11456 | * @param packageName name of package to be allowlisted |
| 11457 | * @param context |
| 11458 | */ |
| 11459 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11460 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11461 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11462 | } |
| 11463 | |
| 11464 | /** |
| 11465 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11466 | * @param packageName name of package to remove from allowlist |
| 11467 | * @param context |
| 11468 | */ |
| 11469 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11470 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11471 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11472 | } |
| 11473 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11474 | /** |
| 11475 | * Thermal mitigation request to control functionalities at modem. |
| 11476 | * |
| 11477 | * @param subId the id of the subscription. |
| 11478 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11479 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11480 | * |
| 11481 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11482 | */ |
| 11483 | @Override |
| 11484 | @ThermalMitigationResult |
| 11485 | public int sendThermalMitigationRequest( |
| 11486 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11487 | ThermalMitigationRequest thermalMitigationRequest, |
| 11488 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11489 | enforceModifyPermission(); |
| 11490 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11491 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11492 | |
| 11493 | enforceTelephonyFeatureWithException(callingPackage, |
| 11494 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11495 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11496 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11497 | .contains(callingPackage)) { |
| 11498 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11499 | + "calling package: " + callingPackage); |
| 11500 | } |
| 11501 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11502 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11503 | final long identity = Binder.clearCallingIdentity(); |
| 11504 | |
| 11505 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11506 | try { |
| 11507 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11508 | switch (thermalMitigationAction) { |
| 11509 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11510 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11511 | handleDataThrottlingRequest(subId, |
| 11512 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11513 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11514 | break; |
| 11515 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11516 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11517 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11518 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11519 | } |
| 11520 | |
| 11521 | // Ensure that radio is on. If not able to power on due to phone being |
| 11522 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11523 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11524 | thermalMitigationResult = |
| 11525 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11526 | break; |
| 11527 | } |
| 11528 | |
| 11529 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11530 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11531 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11532 | break; |
| 11533 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11534 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11535 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11536 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11537 | } |
| 11538 | |
| 11539 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11540 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11541 | Phone phone = getPhone(subId); |
| 11542 | if (phone == null) { |
| 11543 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11544 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11545 | break; |
| 11546 | } |
| 11547 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11548 | TelephonyConnectionService service = |
| 11549 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11550 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11551 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11552 | thermalMitigationResult = |
| 11553 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11554 | break; |
| 11555 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11556 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11557 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11558 | break; |
| 11559 | } |
| 11560 | } else { |
| 11561 | thermalMitigationResult = |
| 11562 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11563 | break; |
| 11564 | } |
| 11565 | |
| 11566 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11567 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11568 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11569 | thermalMitigationResult = |
| 11570 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11571 | break; |
| 11572 | } |
| 11573 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11574 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11575 | break; |
| 11576 | default: |
| 11577 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11578 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11579 | } |
| 11580 | } catch (IllegalArgumentException e) { |
| 11581 | throw e; |
| 11582 | } catch (Exception e) { |
| 11583 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11584 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11585 | } finally { |
| 11586 | Binder.restoreCallingIdentity(identity); |
| 11587 | } |
| 11588 | |
| 11589 | if (DBG) { |
| 11590 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11591 | + thermalMitigationResult); |
| 11592 | } |
| 11593 | |
| 11594 | return thermalMitigationResult; |
| 11595 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11596 | |
| 11597 | /** |
| 11598 | * Set the GbaService Package Name that Telephony will bind to. |
| 11599 | * |
| 11600 | * @param subId The sim that the GbaService is associated with. |
| 11601 | * @param packageName The name of the package to be replaced with. |
| 11602 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11603 | */ |
| 11604 | @Override |
| 11605 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11606 | enforceModifyPermission(); |
| 11607 | |
| 11608 | final long identity = Binder.clearCallingIdentity(); |
| 11609 | try { |
| 11610 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11611 | } finally { |
| 11612 | Binder.restoreCallingIdentity(identity); |
| 11613 | } |
| 11614 | } |
| 11615 | |
| 11616 | /** |
| 11617 | * Return the package name of the currently bound GbaService. |
| 11618 | * |
| 11619 | * @param subId The sim that the GbaService is associated with. |
| 11620 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11621 | */ |
| 11622 | @Override |
| 11623 | public String getBoundGbaService(int subId) { |
| 11624 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11625 | |
| 11626 | final long identity = Binder.clearCallingIdentity(); |
| 11627 | try { |
| 11628 | return getGbaManager(subId).getServicePackage(); |
| 11629 | } finally { |
| 11630 | Binder.restoreCallingIdentity(identity); |
| 11631 | } |
| 11632 | } |
| 11633 | |
| 11634 | /** |
| 11635 | * Set the release time for telephony to unbind GbaService. |
| 11636 | * |
| 11637 | * @param subId The sim that the GbaService is associated with. |
| 11638 | * @param interval The release time to unbind GbaService by millisecond. |
| 11639 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11640 | */ |
| 11641 | @Override |
| 11642 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11643 | enforceModifyPermission(); |
| 11644 | |
| 11645 | final long identity = Binder.clearCallingIdentity(); |
| 11646 | try { |
| 11647 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11648 | } finally { |
| 11649 | Binder.restoreCallingIdentity(identity); |
| 11650 | } |
| 11651 | } |
| 11652 | |
| 11653 | /** |
| 11654 | * Return the release time for telephony to unbind GbaService. |
| 11655 | * |
| 11656 | * @param subId The sim that the GbaService is associated with. |
| 11657 | * @return The release time to unbind GbaService by millisecond. |
| 11658 | */ |
| 11659 | @Override |
| 11660 | public int getGbaReleaseTime(int subId) { |
| 11661 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11662 | |
| 11663 | final long identity = Binder.clearCallingIdentity(); |
| 11664 | try { |
| 11665 | return getGbaManager(subId).getReleaseTime(); |
| 11666 | } finally { |
| 11667 | Binder.restoreCallingIdentity(identity); |
| 11668 | } |
| 11669 | } |
| 11670 | |
| 11671 | private GbaManager getGbaManager(int subId) { |
| 11672 | GbaManager instance = GbaManager.getInstance(subId); |
| 11673 | if (instance == null) { |
| 11674 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11675 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11676 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11677 | } |
| 11678 | return instance; |
| 11679 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11680 | |
| 11681 | /** |
| 11682 | * indicate whether the device and the carrier can support |
| 11683 | * RCS VoLTE single registration. |
| 11684 | */ |
| 11685 | @Override |
| 11686 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11687 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11688 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11689 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11690 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11691 | |
| 11692 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11693 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11694 | } |
| 11695 | |
| 11696 | final long identity = Binder.clearCallingIdentity(); |
| 11697 | try { |
| 11698 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11699 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11700 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11701 | if (isCapable != null) { |
| 11702 | return isCapable; |
| 11703 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11704 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11705 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11706 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11707 | } finally { |
| 11708 | Binder.restoreCallingIdentity(identity); |
| 11709 | } |
| 11710 | } |
| 11711 | |
| 11712 | /** |
| 11713 | * Register RCS provisioning callback. |
| 11714 | */ |
| 11715 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11716 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11717 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11718 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11719 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11720 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11721 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11722 | |
| 11723 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11724 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11725 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11726 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11727 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11728 | Binder.getCallingUserHandle())) { |
| 11729 | if (!isImsAvailableOnDevice()) { |
| 11730 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11731 | "IMS not available on device."); |
| 11732 | } |
| 11733 | } else { |
| 11734 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11735 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11736 | } |
| 11737 | |
| 11738 | final long identity = Binder.clearCallingIdentity(); |
| 11739 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11740 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11741 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11742 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11743 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11744 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11745 | } finally { |
| 11746 | Binder.restoreCallingIdentity(identity); |
| 11747 | } |
| 11748 | } |
| 11749 | |
| 11750 | /** |
| 11751 | * Unregister RCS provisioning callback. |
| 11752 | */ |
| 11753 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11754 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11755 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11756 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11757 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11758 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11759 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11760 | |
| 11761 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11762 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11763 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11764 | |
| 11765 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11766 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11767 | Binder.getCallingUserHandle())) { |
| 11768 | if (!isImsAvailableOnDevice()) { |
| 11769 | // operation failed silently |
| 11770 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11771 | return; |
| 11772 | } |
| 11773 | } else { |
| 11774 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11775 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11776 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11777 | } |
| 11778 | |
| 11779 | final long identity = Binder.clearCallingIdentity(); |
| 11780 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11781 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11782 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11783 | } finally { |
| 11784 | Binder.restoreCallingIdentity(identity); |
| 11785 | } |
| 11786 | } |
| 11787 | |
| 11788 | /** |
| 11789 | * trigger RCS reconfiguration. |
| 11790 | */ |
| 11791 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11792 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11793 | "triggerRcsReconfiguration", |
| 11794 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11795 | |
| 11796 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11797 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11798 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11799 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11800 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11801 | Binder.getCallingUserHandle())) { |
| 11802 | if (!isImsAvailableOnDevice()) { |
| 11803 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11804 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11805 | throw new IllegalStateException("IMS not available on device."); |
| 11806 | } |
| 11807 | } else { |
| 11808 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11809 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | } |
| 11811 | |
| 11812 | final long identity = Binder.clearCallingIdentity(); |
| 11813 | try { |
| 11814 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11815 | } finally { |
| 11816 | Binder.restoreCallingIdentity(identity); |
| 11817 | } |
| 11818 | } |
| 11819 | |
| 11820 | /** |
| 11821 | * Provide the client configuration parameters of the RCS application. |
| 11822 | */ |
| 11823 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11824 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11825 | "setRcsClientConfiguration", |
| 11826 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11827 | |
| 11828 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11829 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11830 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11831 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11832 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11833 | Binder.getCallingUserHandle())) { |
| 11834 | if (!isImsAvailableOnDevice()) { |
| 11835 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11836 | "IMS not available on device."); |
| 11837 | } |
| 11838 | } else { |
| 11839 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11840 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11841 | } |
| 11842 | |
| 11843 | final long identity = Binder.clearCallingIdentity(); |
| 11844 | |
| 11845 | try { |
| 11846 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11847 | if (configBinder == null) { |
| 11848 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11849 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11850 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11851 | } else { |
| 11852 | configBinder.setRcsClientConfiguration(rcc); |
| 11853 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11854 | |
| 11855 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11856 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11857 | } catch (RemoteException e) { |
| 11858 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11859 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11860 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11861 | } finally { |
| 11862 | Binder.restoreCallingIdentity(identity); |
| 11863 | } |
| 11864 | } |
| 11865 | |
| 11866 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11867 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11868 | */ |
| 11869 | @Override |
| 11870 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11871 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11872 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11873 | |
| 11874 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11875 | } |
| 11876 | |
| 11877 | /** |
| 11878 | * Gets the test mode for RCS VoLTE single registration. |
| 11879 | */ |
| 11880 | @Override |
| 11881 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11882 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11883 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11884 | |
| 11885 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11886 | } |
| 11887 | |
| 11888 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11889 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11890 | */ |
| 11891 | @Override |
| 11892 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11893 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11894 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11895 | enforceModifyPermission(); |
| 11896 | |
| 11897 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11898 | : Boolean.parseBoolean(enabledStr); |
| 11899 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11900 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11901 | } |
| 11902 | |
| 11903 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11904 | * Sends a device to device communication message. Only usable via shell. |
| 11905 | * @param message message to send. |
| 11906 | * @param value message value. |
| 11907 | */ |
| 11908 | @Override |
| 11909 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11910 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11911 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11912 | enforceModifyPermission(); |
| 11913 | |
| 11914 | final long identity = Binder.clearCallingIdentity(); |
| 11915 | try { |
| 11916 | TelephonyConnectionService service = |
| 11917 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11918 | if (service == null) { |
| 11919 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11920 | return; |
| 11921 | } |
| 11922 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11923 | } finally { |
| 11924 | Binder.restoreCallingIdentity(identity); |
| 11925 | } |
| 11926 | } |
| 11927 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11928 | /** |
| 11929 | * Sets the specified device to device transport active. |
| 11930 | * @param transport The transport to set active. |
| 11931 | */ |
| 11932 | @Override |
| 11933 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11934 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11935 | "setActiveDeviceToDeviceTransport"); |
| 11936 | enforceModifyPermission(); |
| 11937 | |
| 11938 | final long identity = Binder.clearCallingIdentity(); |
| 11939 | try { |
| 11940 | TelephonyConnectionService service = |
| 11941 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11942 | if (service == null) { |
| 11943 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11944 | return; |
| 11945 | } |
| 11946 | service.setActiveDeviceToDeviceTransport(transport); |
| 11947 | } finally { |
| 11948 | Binder.restoreCallingIdentity(identity); |
| 11949 | } |
| 11950 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11951 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11952 | @Override |
| 11953 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11955 | "setDeviceToDeviceForceEnabled"); |
| 11956 | |
| 11957 | final long identity = Binder.clearCallingIdentity(); |
| 11958 | try { |
| 11959 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11960 | p -> { |
| 11961 | Phone thePhone = p.getImsPhone(); |
| 11962 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11963 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11964 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11965 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11966 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11967 | (ImsPhoneCallTracker) tracker; |
| 11968 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11969 | } |
| 11970 | } |
| 11971 | } |
| 11972 | ); |
| 11973 | } finally { |
| 11974 | Binder.restoreCallingIdentity(identity); |
| 11975 | } |
| 11976 | } |
| 11977 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11978 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11979 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11980 | */ |
| 11981 | @Override |
| 11982 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11983 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11984 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11985 | } |
| 11986 | |
| 11987 | /** |
| 11988 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11989 | */ |
| 11990 | @Override |
| 11991 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11993 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11994 | enforceModifyPermission(); |
| 11995 | |
| 11996 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11997 | : Boolean.parseBoolean(enabledStr); |
| 11998 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11999 | subId, enabled); |
| 12000 | } |
| 12001 | |
| 12002 | /** |
| 12003 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12004 | */ |
| 12005 | @Override |
| 12006 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12007 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12008 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12009 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12010 | |
| 12011 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12012 | * Overrides the ims feature validation result |
| 12013 | */ |
| 12014 | @Override |
| 12015 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12016 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12017 | "setImsFeatureValidationOverride"); |
| 12018 | |
| 12019 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12020 | : Boolean.parseBoolean(enabledStr); |
| 12021 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12022 | subId, enabled); |
| 12023 | } |
| 12024 | |
| 12025 | /** |
| 12026 | * Gets the ims feature validation override value |
| 12027 | */ |
| 12028 | @Override |
| 12029 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12031 | "getImsFeatureValidationOverride"); |
| 12032 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12033 | } |
| 12034 | |
| 12035 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12036 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12037 | * their mobile plan. |
| 12038 | */ |
| 12039 | @Override |
| 12040 | public String getMobileProvisioningUrl() { |
| 12041 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12042 | final long identity = Binder.clearCallingIdentity(); |
| 12043 | try { |
| 12044 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12045 | } finally { |
| 12046 | Binder.restoreCallingIdentity(identity); |
| 12047 | } |
| 12048 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12049 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12050 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12051 | * Get the EAB contact from the EAB database. |
| 12052 | */ |
| 12053 | @Override |
| 12054 | public String getContactFromEab(String contact) { |
| 12055 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12056 | enforceModifyPermission(); |
| 12057 | final long identity = Binder.clearCallingIdentity(); |
| 12058 | try { |
| 12059 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12060 | } finally { |
| 12061 | Binder.restoreCallingIdentity(identity); |
| 12062 | } |
| 12063 | } |
| 12064 | |
| 12065 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12066 | * Get the EAB capability from the EAB database. |
| 12067 | */ |
| 12068 | @Override |
| 12069 | public String getCapabilityFromEab(String contact) { |
| 12070 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12071 | enforceModifyPermission(); |
| 12072 | final long identity = Binder.clearCallingIdentity(); |
| 12073 | try { |
| 12074 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12075 | } finally { |
| 12076 | Binder.restoreCallingIdentity(identity); |
| 12077 | } |
| 12078 | } |
| 12079 | |
| 12080 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12081 | * Remove the EAB contacts from the EAB database. |
| 12082 | */ |
| 12083 | @Override |
| 12084 | public int removeContactFromEab(int subId, String contacts) { |
| 12085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12086 | enforceModifyPermission(); |
| 12087 | final long identity = Binder.clearCallingIdentity(); |
| 12088 | try { |
| 12089 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12090 | } finally { |
| 12091 | Binder.restoreCallingIdentity(identity); |
| 12092 | } |
| 12093 | } |
| 12094 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12095 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12096 | public boolean getDeviceUceEnabled() { |
| 12097 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12098 | final long identity = Binder.clearCallingIdentity(); |
| 12099 | try { |
| 12100 | return mApp.getDeviceUceEnabled(); |
| 12101 | } finally { |
| 12102 | Binder.restoreCallingIdentity(identity); |
| 12103 | } |
| 12104 | } |
| 12105 | |
| 12106 | @Override |
| 12107 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12108 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12109 | final long identity = Binder.clearCallingIdentity(); |
| 12110 | try { |
| 12111 | mApp.setDeviceUceEnabled(isEnabled); |
| 12112 | } finally { |
| 12113 | Binder.restoreCallingIdentity(identity); |
| 12114 | } |
| 12115 | } |
| 12116 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12117 | /** |
| 12118 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12119 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12120 | */ |
| 12121 | // Used for SHELL command only right now. |
| 12122 | @Override |
| 12123 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12124 | List<String> featureTags) { |
| 12125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12126 | "addUceRegistrationOverrideShell"); |
| 12127 | final long identity = Binder.clearCallingIdentity(); |
| 12128 | try { |
| 12129 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12130 | new ArraySet<>(featureTags)); |
| 12131 | } catch (ImsException e) { |
| 12132 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12133 | } finally { |
| 12134 | Binder.restoreCallingIdentity(identity); |
| 12135 | } |
| 12136 | } |
| 12137 | |
| 12138 | /** |
| 12139 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12140 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12141 | */ |
| 12142 | // Used for SHELL command only right now. |
| 12143 | @Override |
| 12144 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12145 | List<String> featureTags) { |
| 12146 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12147 | "removeUceRegistrationOverrideShell"); |
| 12148 | final long identity = Binder.clearCallingIdentity(); |
| 12149 | try { |
| 12150 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12151 | new ArraySet<>(featureTags)); |
| 12152 | } catch (ImsException e) { |
| 12153 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12154 | } finally { |
| 12155 | Binder.restoreCallingIdentity(identity); |
| 12156 | } |
| 12157 | } |
| 12158 | |
| 12159 | /** |
| 12160 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12161 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12162 | */ |
| 12163 | // Used for SHELL command only right now. |
| 12164 | @Override |
| 12165 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12167 | "clearUceRegistrationOverrideShell"); |
| 12168 | final long identity = Binder.clearCallingIdentity(); |
| 12169 | try { |
| 12170 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12171 | } catch (ImsException e) { |
| 12172 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12173 | } finally { |
| 12174 | Binder.restoreCallingIdentity(identity); |
| 12175 | } |
| 12176 | } |
| 12177 | |
| 12178 | /** |
| 12179 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12180 | */ |
| 12181 | // Used for SHELL command only right now. |
| 12182 | @Override |
| 12183 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12184 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12185 | "getLatestRcsContactUceCapabilityShell"); |
| 12186 | final long identity = Binder.clearCallingIdentity(); |
| 12187 | try { |
| 12188 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12189 | } catch (ImsException e) { |
| 12190 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12191 | } finally { |
| 12192 | Binder.restoreCallingIdentity(identity); |
| 12193 | } |
| 12194 | } |
| 12195 | |
| 12196 | /** |
| 12197 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12198 | * device does not have an active PUBLISH. |
| 12199 | */ |
| 12200 | // Used for SHELL command only right now. |
| 12201 | @Override |
| 12202 | public String getLastUcePidfXmlShell(int subId) { |
| 12203 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12204 | final long identity = Binder.clearCallingIdentity(); |
| 12205 | try { |
| 12206 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12207 | } catch (ImsException e) { |
| 12208 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12209 | } finally { |
| 12210 | Binder.restoreCallingIdentity(identity); |
| 12211 | } |
| 12212 | } |
| 12213 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12214 | /** |
| 12215 | * Remove UCE requests cannot be sent to the network status. |
| 12216 | */ |
| 12217 | // Used for SHELL command only right now. |
| 12218 | @Override |
| 12219 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12221 | final long identity = Binder.clearCallingIdentity(); |
| 12222 | try { |
| 12223 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12224 | } catch (ImsException e) { |
| 12225 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12226 | } finally { |
| 12227 | Binder.restoreCallingIdentity(identity); |
| 12228 | } |
| 12229 | } |
| 12230 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12231 | /** |
| 12232 | * Remove UCE requests cannot be sent to the network status. |
| 12233 | */ |
| 12234 | // Used for SHELL command only. |
| 12235 | @Override |
| 12236 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12237 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12238 | final long identity = Binder.clearCallingIdentity(); |
| 12239 | try { |
| 12240 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12241 | } catch (ImsException e) { |
| 12242 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12243 | } finally { |
| 12244 | Binder.restoreCallingIdentity(identity); |
| 12245 | } |
| 12246 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12247 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12248 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12249 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12250 | String callingPackage) { |
| 12251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12252 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12253 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12254 | enforceTelephonyFeatureWithException(callingPackage, |
| 12255 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12256 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12257 | final int callingUid = Binder.getCallingUid(); |
| 12258 | // Verify that tha callingPackage belongs to the calling UID |
| 12259 | mApp.getSystemService(AppOpsManager.class) |
| 12260 | .checkPackage(callingUid, callingPackage); |
| 12261 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12262 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12263 | |
| 12264 | final long identity = Binder.clearCallingIdentity(); |
| 12265 | try { |
| 12266 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12267 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12268 | |
| 12269 | if (result instanceof IllegalStateException) { |
| 12270 | throw (IllegalStateException) result; |
| 12271 | } |
| 12272 | } finally { |
| 12273 | Binder.restoreCallingIdentity(identity); |
| 12274 | } |
| 12275 | } |
| 12276 | |
| 12277 | @Override |
| 12278 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12279 | String callingPackage) { |
| 12280 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12281 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12282 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12283 | enforceTelephonyFeatureWithException(callingPackage, |
| 12284 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12285 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12286 | final int callingUid = Binder.getCallingUid(); |
| 12287 | // Verify that tha callingPackage belongs to the calling UID |
| 12288 | mApp.getSystemService(AppOpsManager.class) |
| 12289 | .checkPackage(callingUid, callingPackage); |
| 12290 | |
| 12291 | final long identity = Binder.clearCallingIdentity(); |
| 12292 | try { |
| 12293 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12294 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12295 | |
| 12296 | if (result instanceof IllegalStateException) { |
| 12297 | throw (IllegalStateException) result; |
| 12298 | } |
| 12299 | } finally { |
| 12300 | Binder.restoreCallingIdentity(identity); |
| 12301 | } |
| 12302 | } |
| 12303 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12304 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12305 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12306 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12307 | // phone/system process do not have further restriction on request |
| 12308 | return; |
| 12309 | } |
| 12310 | |
| 12311 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12312 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12313 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12314 | context.enforceCallingOrSelfPermission( |
| 12315 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12316 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12317 | } |
| 12318 | |
| 12319 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12320 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12321 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12322 | || info.isEnabled()) { |
| 12323 | throw new IllegalArgumentException( |
| 12324 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12325 | } |
| 12326 | |
| 12327 | // Thresholds length for each RAN need in range. This has been validated in |
| 12328 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12329 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12330 | final int[] thresholds = info.getThresholds(); |
| 12331 | Objects.requireNonNull(thresholds); |
| 12332 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12333 | || thresholds.length |
| 12334 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12335 | throw new IllegalArgumentException( |
| 12336 | "thresholds length is out of range: " + thresholds.length); |
| 12337 | } |
| 12338 | } |
| 12339 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12340 | |
| 12341 | /** |
| 12342 | * Gets the current phone capability. |
| 12343 | * |
| 12344 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12345 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12346 | * It's used to evaluate possible phone config change, for example from single |
| 12347 | * SIM device to multi-SIM device. |
| 12348 | */ |
| 12349 | @Override |
| 12350 | public PhoneCapability getPhoneCapability() { |
| 12351 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12352 | |
| 12353 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12354 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12355 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12356 | final long identity = Binder.clearCallingIdentity(); |
| 12357 | try { |
| 12358 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12359 | } finally { |
| 12360 | Binder.restoreCallingIdentity(identity); |
| 12361 | } |
| 12362 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12363 | |
| 12364 | /** |
| 12365 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12366 | * required to be done shortly after the API is invoked. |
| 12367 | */ |
| 12368 | @Override |
| 12369 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12370 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12371 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12372 | enforceRebootPermission(); |
| 12373 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12374 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12375 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12376 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12377 | final long identity = Binder.clearCallingIdentity(); |
| 12378 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12379 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12380 | } finally { |
| 12381 | Binder.restoreCallingIdentity(identity); |
| 12382 | } |
| 12383 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12384 | |
| 12385 | /** |
| 12386 | * Request to get the current slicing configuration including URSP rules and |
| 12387 | * NSSAIs (configured, allowed and rejected). |
| 12388 | * |
| 12389 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12390 | */ |
| 12391 | @Override |
| 12392 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12393 | TelephonyPermissions |
| 12394 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12395 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12396 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12397 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12398 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12399 | "getSlicingConfig"); |
| 12400 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12401 | final long identity = Binder.clearCallingIdentity(); |
| 12402 | try { |
| 12403 | Phone phone = getDefaultPhone(); |
| 12404 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12405 | } finally { |
| 12406 | Binder.restoreCallingIdentity(identity); |
| 12407 | } |
| 12408 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12409 | |
| 12410 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12411 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12412 | * |
| 12413 | * @param capability The premium capability to check. |
| 12414 | * @param subId The subId to check the premium capability for. |
| 12415 | * |
| 12416 | * @return Whether the given premium capability is available to purchase. |
| 12417 | */ |
| 12418 | @Override |
| 12419 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12420 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12421 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12422 | log("Premium capability " |
| 12423 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12424 | + " is not available for purchase due to missing permissions."); |
| 12425 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12426 | + "permission READ_BASIC_PHONE_STATE."); |
| 12427 | } |
| 12428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12430 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12431 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12432 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12433 | if (phone == null) { |
| 12434 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12435 | return false; |
| 12436 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12437 | final long identity = Binder.clearCallingIdentity(); |
| 12438 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12439 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12440 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12441 | } finally { |
| 12442 | Binder.restoreCallingIdentity(identity); |
| 12443 | } |
| 12444 | } |
| 12445 | |
| 12446 | /** |
| 12447 | * Purchase the given premium capability from the carrier. |
| 12448 | * |
| 12449 | * @param capability The premium capability to purchase. |
| 12450 | * @param callback The result of the purchase request. |
| 12451 | * @param subId The subId to purchase the premium capability for. |
| 12452 | */ |
| 12453 | @Override |
| 12454 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12455 | log("purchasePremiumCapability: capability=" |
| 12456 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12457 | + getCurrentPackageName()); |
| 12458 | |
| 12459 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12460 | mApp, "purchasePremiumCapability")) { |
| 12461 | log("purchasePremiumCapability " |
| 12462 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12463 | + " failed due to missing permissions."); |
| 12464 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12465 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12466 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12467 | mApp, "purchasePremiumCapability")) { |
| 12468 | log("purchasePremiumCapability " |
| 12469 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12470 | + " failed due to missing permissions."); |
| 12471 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12472 | } |
| 12473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12475 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12476 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12477 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12478 | if (phone == null) { |
| 12479 | try { |
| 12480 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12481 | callback.accept(result); |
| 12482 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12483 | } catch (RemoteException e) { |
| 12484 | String logStr = "Purchase premium capability " |
| 12485 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12486 | + " failed due to RemoteException handling null phone: " + e; |
| 12487 | if (DBG) log(logStr); |
| 12488 | AnomalyReporter.reportAnomaly( |
| 12489 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12490 | } |
| 12491 | return; |
| 12492 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12493 | |
| 12494 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12495 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12496 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12497 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12498 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12499 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12500 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12501 | |
| 12502 | boolean isVisible = false; |
| 12503 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12504 | if (am != null) { |
| 12505 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12506 | if (processes != null) { |
| 12507 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12508 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12509 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12510 | if (process.processName.equals(callingProcess) && process.importance |
| 12511 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12512 | isVisible = true; |
| 12513 | break; |
| 12514 | } |
| 12515 | } |
| 12516 | } |
| 12517 | } |
| 12518 | |
| 12519 | if (!isVisible) { |
| 12520 | try { |
| 12521 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12522 | callback.accept(result); |
| 12523 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12524 | } catch (RemoteException e) { |
| 12525 | String logStr = "Purchase premium capability " |
| 12526 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12527 | + " failed due to RemoteException handling background application: " + e; |
| 12528 | if (DBG) log(logStr); |
| 12529 | AnomalyReporter.reportAnomaly( |
| 12530 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12531 | } |
| 12532 | return; |
| 12533 | } |
| 12534 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12535 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12536 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12537 | } |
| 12538 | |
| 12539 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12540 | * Register an IMS connection state callback |
| 12541 | */ |
| 12542 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12543 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12544 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12545 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12546 | // ImsMmTelManager |
| 12547 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12548 | TelephonyPermissions |
| 12549 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12550 | mApp, subId, "registerImsStateCallback"); |
| 12551 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12552 | // ImsRcsManager or SipDelegateManager |
| 12553 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12554 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12555 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12556 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12557 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12558 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12559 | } |
| 12560 | |
| 12561 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12562 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12563 | "IMS not available on device."); |
| 12564 | } |
| 12565 | |
| 12566 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12568 | } |
| 12569 | |
| 12570 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12571 | if (controller == null) { |
| 12572 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12573 | "IMS not available on device."); |
| 12574 | } |
| 12575 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12576 | if (callingPackage == null) { |
| 12577 | callingPackage = getCurrentPackageName(); |
| 12578 | } |
| 12579 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12580 | final long token = Binder.clearCallingIdentity(); |
| 12581 | try { |
| 12582 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12583 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12584 | } catch (ImsException e) { |
| 12585 | throw new ServiceSpecificException(e.getCode()); |
| 12586 | } finally { |
| 12587 | Binder.restoreCallingIdentity(token); |
| 12588 | } |
| 12589 | } |
| 12590 | |
| 12591 | /** |
| 12592 | * Unregister an IMS connection state callback |
| 12593 | */ |
| 12594 | @Override |
| 12595 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12596 | final long token = Binder.clearCallingIdentity(); |
| 12597 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12598 | if (controller == null) { |
| 12599 | return; |
| 12600 | } |
| 12601 | try { |
| 12602 | controller.unregisterImsStateCallback(cb); |
| 12603 | } finally { |
| 12604 | Binder.restoreCallingIdentity(token); |
| 12605 | } |
| 12606 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12607 | |
| 12608 | /** |
| 12609 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12610 | * |
| 12611 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12612 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12613 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12614 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12615 | * If there is current registered network this value will be same as the registered cell |
| 12616 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12617 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12618 | * it will be cleared and null will be returned. |
| 12619 | * |
| 12620 | */ |
| 12621 | @Override |
| 12622 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12623 | String callingFeatureId) { |
| 12624 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12625 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12626 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12627 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12628 | .setCallingPackage(callingPackage) |
| 12629 | .setCallingFeatureId(callingFeatureId) |
| 12630 | .setCallingPid(Binder.getCallingPid()) |
| 12631 | .setCallingUid(Binder.getCallingUid()) |
| 12632 | .setMethod("getLastKnownCellIdentity") |
| 12633 | .setLogAsInfo(true) |
| 12634 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12635 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12636 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12637 | .build()); |
| 12638 | |
| 12639 | boolean hasFinePermission = |
| 12640 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12641 | if (!hasFinePermission |
| 12642 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12643 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12644 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12645 | } |
| 12646 | |
| 12647 | final long identity = Binder.clearCallingIdentity(); |
| 12648 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12649 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12650 | if (sst == null) return null; |
| 12651 | return sst.getLastKnownCellIdentity(); |
| 12652 | } finally { |
| 12653 | Binder.restoreCallingIdentity(identity); |
| 12654 | } |
| 12655 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12656 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12657 | /** |
| 12658 | * Sets the modem service class Name that Telephony will bind to. |
| 12659 | * |
| 12660 | * @param serviceName The class name of the modem service. |
| 12661 | * @return true if the operation is succeed, otherwise false. |
| 12662 | */ |
| 12663 | public boolean setModemService(String serviceName) { |
| 12664 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12665 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12666 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12667 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12668 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12669 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12670 | } |
| 12671 | |
| 12672 | /** |
| 12673 | * Return the class name of the currently bounded modem service. |
| 12674 | * |
| 12675 | * @return the class name of the modem service. |
| 12676 | */ |
| 12677 | public String getModemService() { |
| 12678 | String result; |
| 12679 | Log.d(LOG_TAG, "getModemService"); |
| 12680 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12681 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12682 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12683 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12684 | "getModemService"); |
| 12685 | result = mPhoneConfigurationManager.getModemService(); |
| 12686 | Log.d(LOG_TAG, "result = " + result); |
| 12687 | return result; |
| 12688 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12689 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12690 | /** |
| 12691 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12692 | * including carrier config, entitlement server, and config update. |
| 12693 | * |
| 12694 | * @param subId subId The subscription ID of the carrier. |
| 12695 | * |
| 12696 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12697 | * be returned. |
| 12698 | * |
| 12699 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12700 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12701 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12702 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12703 | final long identity = Binder.clearCallingIdentity(); |
| 12704 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12705 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12706 | } finally { |
| 12707 | Binder.restoreCallingIdentity(identity); |
| 12708 | } |
| 12709 | } |
| 12710 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12711 | @Override |
| 12712 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12713 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12714 | mApp.enforceCallingOrSelfPermission( |
| 12715 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12716 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12717 | |
| 12718 | final long identity = Binder.clearCallingIdentity(); |
| 12719 | try { |
| 12720 | Phone phone = getPhone(subId); |
| 12721 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12722 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12723 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12724 | phone.setVoiceServiceStateOverride(hasService); |
| 12725 | } finally { |
| 12726 | Binder.restoreCallingIdentity(identity); |
| 12727 | } |
| 12728 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12729 | |
| 12730 | /** |
| 12731 | * set removable eSIM as default eUICC. |
| 12732 | * |
| 12733 | * @hide |
| 12734 | */ |
| 12735 | @Override |
| 12736 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12737 | enforceModifyPermission(); |
| 12738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12739 | |
| 12740 | final long identity = Binder.clearCallingIdentity(); |
| 12741 | try { |
| 12742 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12743 | } finally { |
| 12744 | Binder.restoreCallingIdentity(identity); |
| 12745 | } |
| 12746 | } |
| 12747 | |
| 12748 | /** |
| 12749 | * Returns whether the removable eSIM is default eUICC or not. |
| 12750 | * |
| 12751 | * @hide |
| 12752 | */ |
| 12753 | @Override |
| 12754 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12755 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12756 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12757 | |
| 12758 | final long identity = Binder.clearCallingIdentity(); |
| 12759 | try { |
| 12760 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12761 | } finally { |
| 12762 | Binder.restoreCallingIdentity(identity); |
| 12763 | } |
| 12764 | } |
| 12765 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12766 | /** |
| 12767 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12768 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12769 | * application currently configured for this user. |
| 12770 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12771 | * {@code null} if the functionality is not supported. |
| 12772 | * @hide |
| 12773 | */ |
| 12774 | @Override |
| 12775 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12776 | boolean updateIfNeeded) { |
| 12777 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12778 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12779 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12780 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12781 | "getDefaultRespondViaMessageApplication"); |
| 12782 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12783 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12784 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12785 | UserHandle userHandle = null; |
| 12786 | final long identity = Binder.clearCallingIdentity(); |
| 12787 | try { |
| 12788 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12789 | } finally { |
| 12790 | Binder.restoreCallingIdentity(identity); |
| 12791 | } |
| 12792 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12793 | updateIfNeeded, userHandle); |
| 12794 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12795 | |
| 12796 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12797 | * Set whether the device is able to connect with null ciphering or integrity |
| 12798 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12799 | * and all new subscriptions after this. |
| 12800 | * |
| 12801 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12802 | * @hide |
| 12803 | */ |
| 12804 | @Override |
| 12805 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12806 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12807 | enforceModifyPermission(); |
| 12808 | checkForNullCipherAndIntegritySupport(); |
| 12809 | |
| 12810 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12811 | // for listening to these preference changes and applying them immediately. |
| 12812 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12813 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12814 | editor.apply(); |
| 12815 | |
| 12816 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12817 | phone.handleNullCipherEnabledChange(); |
| 12818 | } |
| 12819 | } |
| 12820 | |
| 12821 | |
| 12822 | /** |
| 12823 | * Get whether the device is able to connect with null ciphering or integrity |
| 12824 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12825 | * the state of the radio. |
| 12826 | * |
| 12827 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12828 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12829 | * version for this feature. |
| 12830 | * @hide |
| 12831 | */ |
| 12832 | @Override |
| 12833 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12834 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12835 | enforceReadPermission(); |
| 12836 | checkForNullCipherAndIntegritySupport(); |
| 12837 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12838 | } |
| 12839 | |
| 12840 | private void checkForNullCipherAndIntegritySupport() { |
| 12841 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12842 | throw new UnsupportedOperationException( |
| 12843 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12844 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12845 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12846 | throw new UnsupportedOperationException( |
| 12847 | "Null cipher and integrity operations unsupported by modem"); |
| 12848 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12849 | } |
| 12850 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12851 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12852 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12853 | throw new UnsupportedOperationException( |
| 12854 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12855 | + "above"); |
| 12856 | } |
| 12857 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12858 | throw new UnsupportedOperationException( |
| 12859 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12860 | } |
| 12861 | } |
| 12862 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12863 | private void checkForNullCipherNotificationSupport() { |
| 12864 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12865 | throw new UnsupportedOperationException( |
| 12866 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12867 | } |
| 12868 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12869 | throw new UnsupportedOperationException( |
| 12870 | "Null cipher notification operations unsupported by modem"); |
| 12871 | } |
| 12872 | } |
| 12873 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12874 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12875 | * Get the SIM state for the slot index. |
| 12876 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12877 | * |
| 12878 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12879 | */ |
| 12880 | @Override |
| 12881 | @SimState |
| 12882 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12883 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12884 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12885 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12886 | IccCardConstants.State simState; |
| 12887 | if (slotIndex < 0) { |
| 12888 | simState = IccCardConstants.State.UNKNOWN; |
| 12889 | } else { |
| 12890 | Phone phone = null; |
| 12891 | try { |
| 12892 | phone = PhoneFactory.getPhone(slotIndex); |
| 12893 | } catch (IllegalStateException e) { |
| 12894 | // ignore |
| 12895 | } |
| 12896 | if (phone == null) { |
| 12897 | simState = IccCardConstants.State.UNKNOWN; |
| 12898 | } else { |
| 12899 | IccCard icc = phone.getIccCard(); |
| 12900 | if (icc == null) { |
| 12901 | simState = IccCardConstants.State.UNKNOWN; |
| 12902 | } else { |
| 12903 | simState = icc.getState(); |
| 12904 | } |
| 12905 | } |
| 12906 | } |
| 12907 | return simState.ordinal(); |
| 12908 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12909 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12910 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12911 | boolean enableLogcat, |
| 12912 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12913 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12914 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12915 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12916 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12917 | ecdDataBuilder |
| 12918 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12919 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12920 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12921 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12922 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12923 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12924 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12925 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12926 | Executors.newCachedThreadPool(), db, |
| 12927 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12928 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12929 | } |
| 12930 | |
| 12931 | /** |
| 12932 | * Request telephony to persist state for debugging emergency call failures. |
| 12933 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12934 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12935 | * @param enableLogcat whether to collect logcat output |
| 12936 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12937 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12938 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12939 | */ |
| 12940 | @Override |
| 12941 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12942 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12943 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12944 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 12945 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 12946 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 12947 | && Flags.enableReadDropboxPermission()) { |
| 12948 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 12949 | "persistEmergencyCallDiagnosticData"); |
| 12950 | } else { |
| 12951 | // Otherwise, enforce legacy permission. |
| 12952 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12953 | "persistEmergencyCallDiagnosticData"); |
| 12954 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12955 | final long identity = Binder.clearCallingIdentity(); |
| 12956 | try { |
| 12957 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12958 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12959 | |
| 12960 | } finally { |
| 12961 | Binder.restoreCallingIdentity(identity); |
| 12962 | } |
| 12963 | } |
| 12964 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12965 | /** |
| 12966 | * Get current cell broadcast ranges. |
| 12967 | */ |
| 12968 | @Override |
| 12969 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12970 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12971 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12972 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12973 | |
| 12974 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12975 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12976 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12977 | final long identity = Binder.clearCallingIdentity(); |
| 12978 | try { |
| 12979 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12980 | } finally { |
| 12981 | Binder.restoreCallingIdentity(identity); |
| 12982 | } |
| 12983 | } |
| 12984 | |
| 12985 | /** |
| 12986 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12987 | * |
| 12988 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12989 | */ |
| 12990 | @Override |
| 12991 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12992 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12993 | @Nullable IIntegerConsumer callback) { |
| 12994 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12995 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12996 | |
| 12997 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12998 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12999 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13000 | final long identity = Binder.clearCallingIdentity(); |
| 13001 | try { |
| 13002 | Phone phone = getPhoneFromSubId(subId); |
| 13003 | if (DBG) { |
| 13004 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13005 | } |
| 13006 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13007 | if (callback != null) { |
| 13008 | try { |
| 13009 | callback.accept(result); |
| 13010 | } catch (RemoteException e) { |
| 13011 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13012 | } |
| 13013 | } |
| 13014 | }); |
| 13015 | } finally { |
| 13016 | Binder.restoreCallingIdentity(identity); |
| 13017 | } |
| 13018 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13019 | |
| 13020 | /** |
| 13021 | * Returns whether the device supports the domain selection service. |
| 13022 | * |
| 13023 | * @return {@code true} if the device supports the domain selection service. |
| 13024 | */ |
| 13025 | @Override |
| 13026 | public boolean isDomainSelectionSupported() { |
| 13027 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13028 | "isDomainSelectionSupported"); |
| 13029 | |
| 13030 | final long identity = Binder.clearCallingIdentity(); |
| 13031 | try { |
| 13032 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13033 | } finally { |
| 13034 | Binder.restoreCallingIdentity(identity); |
| 13035 | } |
| 13036 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13037 | |
| 13038 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13039 | * Returns whether the AOSP domain selection service is supported. |
| 13040 | * |
| 13041 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13042 | * {@code false} otherwise. |
| 13043 | */ |
| 13044 | @Override |
| 13045 | public boolean isAospDomainSelectionService() { |
| 13046 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13047 | "isAospDomainSelectionService"); |
| 13048 | |
| 13049 | final long identity = Binder.clearCallingIdentity(); |
| 13050 | try { |
| 13051 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13052 | String dssComponentName = mApp.getResources().getString( |
| 13053 | R.string.config_domain_selection_service_component_name); |
| 13054 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13055 | TelephonyDomainSelectionService.class.getName()); |
| 13056 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13057 | + ", aosp=" + componentName.flattenToString()); |
| 13058 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13059 | } |
| 13060 | } finally { |
| 13061 | Binder.restoreCallingIdentity(identity); |
| 13062 | } |
| 13063 | return false; |
| 13064 | } |
| 13065 | |
| 13066 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13067 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13068 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13069 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13070 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13071 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13072 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13073 | * {@code false} to disable. |
| 13074 | * @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] | 13075 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13076 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13077 | * |
| 13078 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13079 | */ |
| 13080 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13081 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13082 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13083 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13084 | if (enableSatellite) { |
| 13085 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13086 | @Override |
| 13087 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13088 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13089 | + ", resultData=" + resultData); |
| 13090 | boolean isAllowed = false; |
| 13091 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13092 | callback::accept); |
| 13093 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13094 | if (resultData != null |
| 13095 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13096 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13097 | } else { |
| 13098 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13099 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13100 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13101 | result.accept(resultCode); |
| 13102 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13103 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13104 | if (isAllowed) { |
| 13105 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13106 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13107 | } else { |
| 13108 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13109 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13110 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13111 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13112 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13113 | subId, resultReceiver); |
| 13114 | } else { |
| 13115 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13116 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13117 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13118 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13119 | } |
| 13120 | |
| 13121 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13122 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13123 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13124 | * @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] | 13125 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13126 | * 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] | 13127 | * |
| 13128 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13129 | */ |
| 13130 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13131 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13132 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13133 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13134 | } |
| 13135 | |
| 13136 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13137 | * Request to get whether the satellite service demo mode is enabled. |
| 13138 | * |
| 13139 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13140 | * is enabled for. |
| 13141 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13142 | * if the request is successful or an error code if the request failed. |
| 13143 | * |
| 13144 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13145 | */ |
| 13146 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13147 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13148 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13149 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13150 | } |
| 13151 | |
| 13152 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13153 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13154 | * |
| 13155 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13156 | * is enabled for. |
| 13157 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13158 | * enabled if the request is successful or an error code if the request failed. |
| 13159 | * |
| 13160 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13161 | */ |
| 13162 | @Override |
| 13163 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13164 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13165 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13166 | } |
| 13167 | |
| 13168 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13169 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13170 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13171 | * @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] | 13172 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13173 | * 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] | 13174 | */ |
| 13175 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13176 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13177 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13178 | } |
| 13179 | |
| 13180 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13181 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13182 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13183 | * @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] | 13184 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13185 | * 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] | 13186 | * |
| 13187 | * @throws SecurityException if the caller doesn't have required permission. |
| 13188 | */ |
| 13189 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13190 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13191 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13192 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13193 | } |
| 13194 | |
| 13195 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13196 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13197 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13198 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13199 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13200 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13201 | * @param resultCallback The callback to get the result of the request. |
| 13202 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13203 | * |
| 13204 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13205 | */ |
| 13206 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13207 | public void startSatelliteTransmissionUpdates(int subId, |
| 13208 | @NonNull IIntegerConsumer resultCallback, |
| 13209 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13210 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13211 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13212 | } |
| 13213 | |
| 13214 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13215 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13216 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13217 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13218 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13219 | * @param resultCallback The callback to get the result of the request. |
| 13220 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13221 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13222 | * |
| 13223 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13224 | */ |
| 13225 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13226 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13227 | @NonNull IIntegerConsumer resultCallback, |
| 13228 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13229 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13230 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13231 | } |
| 13232 | |
| 13233 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13234 | * Register the subscription with a satellite provider. |
| 13235 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13236 | * |
| 13237 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13238 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13239 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13240 | * @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] | 13241 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13242 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13243 | * @return The signal transport used by the caller to cancel the provision request, |
| 13244 | * or {@code null} if the request failed. |
| 13245 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13246 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13247 | */ |
| 13248 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13249 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13250 | @NonNull String token, @NonNull byte[] provisionData, |
| 13251 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13252 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13253 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13254 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13255 | } |
| 13256 | |
| 13257 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13258 | * Unregister the device/subscription with the satellite provider. |
| 13259 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13260 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13261 | * should report as deprovisioned. |
| 13262 | * |
| 13263 | * @param subId The subId of the subscription to be deprovisioned. |
| 13264 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13265 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13266 | * |
| 13267 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13268 | */ |
| 13269 | @Override |
| 13270 | public void deprovisionSatelliteService(int subId, |
| 13271 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13272 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13273 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13274 | } |
| 13275 | |
| 13276 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13277 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13278 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13279 | * @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] | 13280 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13281 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13282 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13283 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13284 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13285 | */ |
| 13286 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13287 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13288 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13289 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13290 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13291 | } |
| 13292 | |
| 13293 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13294 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13295 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13296 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13297 | * @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] | 13298 | * @param callback The callback that was passed to |
| 13299 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13300 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13301 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13302 | */ |
| 13303 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13304 | public void unregisterForSatelliteProvisionStateChanged( |
| 13305 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13306 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13307 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13308 | } |
| 13309 | |
| 13310 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13311 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13312 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13313 | * @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] | 13314 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13315 | * satellite provider if the request is successful or an error code if the |
| 13316 | * request failed. |
| 13317 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13318 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13319 | */ |
| 13320 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13321 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13322 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13323 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13324 | } |
| 13325 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13326 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13327 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13328 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13329 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13330 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13331 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13332 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13333 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13334 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13335 | */ |
| 13336 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13337 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13338 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13339 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13340 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13341 | } |
| 13342 | |
| 13343 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13344 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13345 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13346 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13347 | * @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] | 13348 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13349 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13350 | * |
| 13351 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13352 | */ |
| 13353 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13354 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13355 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13356 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13357 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13358 | } |
| 13359 | |
| 13360 | /** |
| 13361 | * Register to receive incoming datagrams over satellite. |
| 13362 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13363 | * @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] | 13364 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13365 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13366 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13367 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13368 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13369 | */ |
| 13370 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13371 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13372 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13373 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13374 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13375 | } |
| 13376 | |
| 13377 | /** |
| 13378 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13379 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13380 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13381 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13382 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13383 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13384 | * |
| 13385 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13386 | */ |
| 13387 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13388 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13389 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13390 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13391 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13392 | } |
| 13393 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13394 | /** |
| 13395 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13396 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13397 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13398 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13399 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13400 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13401 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13402 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13403 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13404 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13405 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13406 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13407 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13408 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13409 | } |
| 13410 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13411 | /** |
| 13412 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13413 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13414 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13415 | * input to this method. Datagram received here will be passed down to modem without any |
| 13416 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13417 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13418 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13419 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13420 | * SOS_SMS or LOCATION_SHARING. |
| 13421 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13422 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13423 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13424 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13425 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13426 | * |
| 13427 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13428 | */ |
| 13429 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13430 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13431 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13432 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13433 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13434 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13435 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13436 | } |
| 13437 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13438 | /** |
| 13439 | * Request to get whether satellite communication is allowed for the current location. |
| 13440 | * |
| 13441 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13442 | * allowed for the current location for. |
| 13443 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13444 | * for the current location if the request is successful or an error code |
| 13445 | * if the request failed. |
| 13446 | * |
| 13447 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13448 | */ |
| 13449 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13450 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13451 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13452 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13453 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13454 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13455 | } |
| 13456 | |
| 13457 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13458 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13459 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13460 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13461 | * @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] | 13462 | * be visible if the request is successful or an error code if the request failed. |
| 13463 | * |
| 13464 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13465 | */ |
| 13466 | @Override |
| 13467 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13468 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13469 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13470 | } |
| 13471 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13472 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13473 | * Inform that Device is aligned to satellite for demo mode. |
| 13474 | * |
| 13475 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13476 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13477 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13478 | * |
| 13479 | * @throws SecurityException if the caller doesn't have required permission. |
| 13480 | */ |
| 13481 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13482 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13483 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13484 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13485 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13486 | } |
| 13487 | |
| 13488 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13489 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13490 | * by modem. |
| 13491 | * |
| 13492 | * @param subId The subId of the subscription to request for. |
| 13493 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13494 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13495 | * operation. |
| 13496 | * |
| 13497 | * @throws SecurityException if the caller doesn't have required permission. |
| 13498 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13499 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13500 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13501 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13502 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13503 | final long identity = Binder.clearCallingIdentity(); |
| 13504 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13505 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13506 | } finally { |
| 13507 | Binder.restoreCallingIdentity(identity); |
| 13508 | } |
| 13509 | } |
| 13510 | |
| 13511 | /** |
| 13512 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13513 | * by modem. |
| 13514 | * |
| 13515 | * @param subId The subId of the subscription to request for. |
| 13516 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13517 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13518 | * operation. |
| 13519 | * |
| 13520 | * @throws SecurityException if the caller doesn't have required permission. |
| 13521 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13522 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13523 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13524 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13525 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13526 | final long identity = Binder.clearCallingIdentity(); |
| 13527 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13528 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13529 | } finally { |
| 13530 | Binder.restoreCallingIdentity(identity); |
| 13531 | } |
| 13532 | } |
| 13533 | |
| 13534 | /** |
| 13535 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13536 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13537 | * |
| 13538 | * @param subId The subId of the subscription to request for. |
| 13539 | * |
| 13540 | * @return Integer array of reasons for disallowing satellite communication. |
| 13541 | * |
| 13542 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13543 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13544 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13545 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13546 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13547 | final long identity = Binder.clearCallingIdentity(); |
| 13548 | try { |
| 13549 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13550 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13551 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13552 | } finally { |
| 13553 | Binder.restoreCallingIdentity(identity); |
| 13554 | } |
| 13555 | } |
| 13556 | |
| 13557 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13558 | * Request to get the signal strength of the satellite connection. |
| 13559 | * |
| 13560 | * @param subId The subId of the subscription to request for. |
| 13561 | * @param result Result receiver to get the error code of the request and the current signal |
| 13562 | * strength of the satellite connection. |
| 13563 | * |
| 13564 | * @throws SecurityException if the caller doesn't have required permission. |
| 13565 | */ |
| 13566 | @Override |
| 13567 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13568 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13569 | final long identity = Binder.clearCallingIdentity(); |
| 13570 | try { |
| 13571 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13572 | } finally { |
| 13573 | Binder.restoreCallingIdentity(identity); |
| 13574 | } |
| 13575 | } |
| 13576 | |
| 13577 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13578 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13579 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13580 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13581 | * |
| 13582 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13583 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13584 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13585 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13586 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13587 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13588 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13589 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13590 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13591 | */ |
| 13592 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13593 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13594 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13595 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13596 | final long identity = Binder.clearCallingIdentity(); |
| 13597 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13598 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13599 | } finally { |
| 13600 | Binder.restoreCallingIdentity(identity); |
| 13601 | } |
| 13602 | } |
| 13603 | |
| 13604 | /** |
| 13605 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13606 | * If callback was not registered before, the request will be ignored. |
| 13607 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13608 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13609 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13610 | * @param callback The callback that was passed to |
| 13611 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13612 | * |
| 13613 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13614 | */ |
| 13615 | @Override |
| 13616 | public void unregisterForNtnSignalStrengthChanged( |
| 13617 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13618 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13619 | final long identity = Binder.clearCallingIdentity(); |
| 13620 | try { |
| 13621 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13622 | } finally { |
| 13623 | Binder.restoreCallingIdentity(identity); |
| 13624 | } |
| 13625 | } |
| 13626 | |
| 13627 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13628 | * Registers for satellite capabilities change event from the satellite service. |
| 13629 | * |
| 13630 | * @param subId The subId of the subscription to request for. |
| 13631 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13632 | * |
| 13633 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13634 | * |
| 13635 | * @throws SecurityException if the caller doesn't have required permission. |
| 13636 | */ |
| 13637 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13638 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13639 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13640 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13641 | final long identity = Binder.clearCallingIdentity(); |
| 13642 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13643 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13644 | } finally { |
| 13645 | Binder.restoreCallingIdentity(identity); |
| 13646 | } |
| 13647 | } |
| 13648 | |
| 13649 | /** |
| 13650 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13651 | * If callback was not registered before, the request will be ignored. |
| 13652 | * |
| 13653 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13654 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13655 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13656 | * |
| 13657 | * @throws SecurityException if the caller doesn't have required permission. |
| 13658 | */ |
| 13659 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13660 | public void unregisterForCapabilitiesChanged(int subId, |
| 13661 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13662 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13663 | final long identity = Binder.clearCallingIdentity(); |
| 13664 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13665 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13666 | } finally { |
| 13667 | Binder.restoreCallingIdentity(identity); |
| 13668 | } |
| 13669 | } |
| 13670 | |
| 13671 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13672 | * Registers for the satellite supported state changed. |
| 13673 | * |
| 13674 | * @param subId The subId of the subscription to register for supported state changed. |
| 13675 | * @param callback The callback to handle the satellite supported state changed event. |
| 13676 | * |
| 13677 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13678 | * |
| 13679 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13680 | */ |
| 13681 | @Override |
| 13682 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13683 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13684 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13685 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13686 | } |
| 13687 | |
| 13688 | /** |
| 13689 | * Unregisters for the satellite supported state changed. |
| 13690 | * If callback was not registered before, the request will be ignored. |
| 13691 | * |
| 13692 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13693 | * @param callback The callback that was passed to |
| 13694 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13695 | * |
| 13696 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13697 | */ |
| 13698 | @Override |
| 13699 | public void unregisterForSatelliteSupportedStateChanged( |
| 13700 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13701 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13702 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13703 | } |
| 13704 | |
| 13705 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13706 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13707 | * |
| 13708 | * @param servicePackageName The package name of the satellite vendor service. |
| 13709 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13710 | * {@code false} otherwise. |
| 13711 | */ |
| 13712 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13713 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13714 | TelephonyPermissions.enforceShellOnly( |
| 13715 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13717 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13718 | "setSatelliteServicePackageName"); |
| 13719 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13720 | } |
| 13721 | |
| 13722 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13723 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13724 | * |
| 13725 | * @param servicePackageName The package name of the satellite gateway service. |
| 13726 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13727 | * {@code false} otherwise. |
| 13728 | */ |
| 13729 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13730 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13731 | TelephonyPermissions.enforceShellOnly( |
| 13732 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13734 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13735 | "setSatelliteGatewayServicePackageName"); |
| 13736 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13737 | } |
| 13738 | |
| 13739 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13740 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13741 | * |
| 13742 | * @param packageName The package name of the satellite pointing UI app. |
| 13743 | * @param className The class name of the satellite pointing UI app. |
| 13744 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13745 | * {@code false} otherwise. |
| 13746 | */ |
| 13747 | public boolean setSatellitePointingUiClassName( |
| 13748 | @Nullable String packageName, @Nullable String className) { |
| 13749 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13750 | + ", className=" + className); |
| 13751 | TelephonyPermissions.enforceShellOnly( |
| 13752 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13754 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13755 | "setSatelliteGatewayServicePackageName"); |
| 13756 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13757 | } |
| 13758 | |
| 13759 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13760 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13761 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13762 | * listening mode. |
| 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 setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13768 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13769 | TelephonyPermissions.enforceShellOnly( |
| 13770 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13772 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13773 | "setSatelliteListeningTimeoutDuration"); |
| 13774 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13775 | } |
| 13776 | |
| 13777 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13778 | * This API can be used by only CTS to override the timeout durations used by the |
| 13779 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13780 | * |
| 13781 | * @param timeoutMillis The timeout duration in millisecond. |
| 13782 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13783 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13784 | public boolean setDatagramControllerTimeoutDuration( |
| 13785 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13786 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13787 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13788 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13789 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13791 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13792 | "setDatagramControllerTimeoutDuration"); |
| 13793 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13794 | reset, timeoutType, timeoutMillis); |
| 13795 | } |
| 13796 | |
| 13797 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 13798 | * This API can be used by only CTS to override the boolean configs used by the |
| 13799 | * DatagramController module. |
| 13800 | * |
| 13801 | * @param enable Whether to enable or disable boolean config. |
| 13802 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 13803 | */ |
| 13804 | public boolean setDatagramControllerBooleanConfig( |
| 13805 | boolean reset, int booleanType, boolean enable) { |
| 13806 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 13807 | + ", reset=" + reset + ", enable=" + enable); |
| 13808 | TelephonyPermissions.enforceShellOnly( |
| 13809 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 13810 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13811 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13812 | "ssetDatagramControllerBooleanConfig"); |
| 13813 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable); |
| 13814 | } |
| 13815 | |
| 13816 | |
| 13817 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13818 | * This API can be used by only CTS to override the timeout durations used by the |
| 13819 | * SatelliteController module. |
| 13820 | * |
| 13821 | * @param timeoutMillis The timeout duration in millisecond. |
| 13822 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13823 | */ |
| 13824 | public boolean setSatelliteControllerTimeoutDuration( |
| 13825 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13826 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13827 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13828 | TelephonyPermissions.enforceShellOnly( |
| 13829 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13831 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13832 | "setSatelliteControllerTimeoutDuration"); |
| 13833 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13834 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13835 | } |
| 13836 | |
| 13837 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13838 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13839 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13840 | * |
| 13841 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13842 | * of the following values to enable the override: |
| 13843 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13844 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13845 | * To disable the override, use -1 for handoverType. |
| 13846 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13847 | * delaySeconds after the emergency call starts. |
| 13848 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13849 | */ |
| 13850 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13851 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13852 | TelephonyPermissions.enforceShellOnly( |
| 13853 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13855 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13856 | "setEmergencyCallToSatelliteHandoverType"); |
| 13857 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13858 | handoverType, delaySeconds); |
| 13859 | } |
| 13860 | |
| 13861 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13862 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13863 | * |
| 13864 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13865 | * otherwise. |
| 13866 | * @param isProvisioned The overriding provision status. |
| 13867 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13868 | */ |
| 13869 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13870 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13871 | + ", isProvisioned=" + isProvisioned); |
| 13872 | TelephonyPermissions.enforceShellOnly( |
| 13873 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13875 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13876 | "setOemEnabledSatelliteProvisionStatus"); |
| 13877 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13878 | } |
| 13879 | |
| 13880 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13881 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13882 | * |
| 13883 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13884 | */ |
| 13885 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13886 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13887 | long locationCountryCodeTimestampNanos) { |
| 13888 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13889 | + String.join(", ", currentNetworkCountryCodes) |
| 13890 | + ", locationCountryCode=" + locationCountryCode |
| 13891 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13892 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13893 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13894 | TelephonyPermissions.enforceShellOnly( |
| 13895 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13896 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13897 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13898 | "setCachedLocationCountryCode"); |
| 13899 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13900 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13901 | locationCountryCodeTimestampNanos); |
| 13902 | } |
| 13903 | |
| 13904 | /** |
| 13905 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13906 | * access controller. |
| 13907 | * |
| 13908 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13909 | * otherwise. |
| 13910 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13911 | */ |
| 13912 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13913 | String s2CellFile, long locationFreshDurationNanos, |
| 13914 | List<String> satelliteCountryCodes) { |
| 13915 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13916 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13917 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13918 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13919 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13920 | TelephonyPermissions.enforceShellOnly( |
| 13921 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13922 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13923 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13924 | "setSatelliteAccessControlOverlayConfigs"); |
| 13925 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13926 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13927 | } |
| 13928 | |
| 13929 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13930 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13931 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13932 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13933 | * |
| 13934 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13935 | * satellite modem or not. |
| 13936 | * |
| 13937 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13938 | */ |
| 13939 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13940 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13941 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13942 | + "disabled"); |
| 13943 | return false; |
| 13944 | } |
| 13945 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13946 | TelephonyPermissions.enforceShellOnly( |
| 13947 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13949 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13950 | "setShouldSendDatagramToModemInDemoMode"); |
| 13951 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13952 | shouldSendToModemInDemoMode); |
| 13953 | } |
| 13954 | |
| 13955 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 13956 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 13957 | * |
| 13958 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 13959 | * the allowed state. |
| 13960 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 13961 | */ |
| 13962 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 13963 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13964 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 13965 | + "oemEnabledSatelliteFlag is disabled"); |
| 13966 | return false; |
| 13967 | } |
| 13968 | |
| 13969 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 13970 | + "state=" + state); |
| 13971 | TelephonyPermissions.enforceShellOnly( |
| 13972 | Binder.getCallingUid(), |
| 13973 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 13974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13975 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13976 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 13977 | return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache( |
| 13978 | state); |
| 13979 | } |
| 13980 | |
| 13981 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13982 | * Sets the service defined in ComponentName to be bound. |
| 13983 | * |
| 13984 | * This should only be used for testing. |
| 13985 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13986 | * {@code false} otherwise. |
| 13987 | */ |
| 13988 | @Override |
| 13989 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13990 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13991 | |
| 13992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13993 | "setDomainSelectionServiceOverride"); |
| 13994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13995 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13996 | |
| 13997 | final long identity = Binder.clearCallingIdentity(); |
| 13998 | try { |
| 13999 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14000 | return DomainSelectionResolver.getInstance() |
| 14001 | .setDomainSelectionServiceOverride(componentName); |
| 14002 | } |
| 14003 | } finally { |
| 14004 | Binder.restoreCallingIdentity(identity); |
| 14005 | } |
| 14006 | return false; |
| 14007 | } |
| 14008 | |
| 14009 | /** |
| 14010 | * Clears the DomainSelectionService override. |
| 14011 | * |
| 14012 | * This should only be used for testing. |
| 14013 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14014 | * {@code false} otherwise. |
| 14015 | */ |
| 14016 | @Override |
| 14017 | public boolean clearDomainSelectionServiceOverride() { |
| 14018 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14019 | |
| 14020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14021 | "clearDomainSelectionServiceOverride"); |
| 14022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14023 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14024 | |
| 14025 | final long identity = Binder.clearCallingIdentity(); |
| 14026 | try { |
| 14027 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14028 | return DomainSelectionResolver.getInstance() |
| 14029 | .clearDomainSelectionServiceOverride(); |
| 14030 | } |
| 14031 | } finally { |
| 14032 | Binder.restoreCallingIdentity(identity); |
| 14033 | } |
| 14034 | return false; |
| 14035 | } |
| 14036 | |
| 14037 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14038 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14039 | * |
| 14040 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14041 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14042 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14043 | * |
| 14044 | * @param enable if notifications about disclosure events should be enabled |
| 14045 | * @throws SecurityException if the caller does not have the required privileges |
| 14046 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14047 | */ |
| 14048 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14049 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14050 | enforceModifyPermission(); |
| 14051 | checkForIdentifierDisclosureNotificationSupport(); |
| 14052 | |
| 14053 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14054 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14055 | editor.apply(); |
| 14056 | |
| 14057 | // Each phone instance is responsible for updating its respective modem immediately |
| 14058 | // after we've made a preference change. |
| 14059 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14060 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14061 | } |
| 14062 | } |
| 14063 | |
| 14064 | /** |
| 14065 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14066 | * |
| 14067 | * @throws SecurityException if the caller does not have the required privileges |
| 14068 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14069 | */ |
| 14070 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14071 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14072 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14073 | checkForIdentifierDisclosureNotificationSupport(); |
| 14074 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14075 | } |
| 14076 | |
| 14077 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14078 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14079 | * are in use by the cellular modem. |
| 14080 | * |
| 14081 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14082 | * @throws SecurityException if the caller does not have the required privileges |
| 14083 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14084 | * and integrity algorithms in use |
| 14085 | * @hide |
| 14086 | */ |
| 14087 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14088 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14089 | enforceModifyPermission(); |
| 14090 | checkForNullCipherNotificationSupport(); |
| 14091 | |
| 14092 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14093 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14094 | editor.apply(); |
| 14095 | |
| 14096 | // Each phone instance is responsible for updating its respective modem immediately |
| 14097 | // after a preference change. |
| 14098 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14099 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14100 | } |
| 14101 | } |
| 14102 | |
| 14103 | /** |
| 14104 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14105 | * cellular modem. |
| 14106 | * |
| 14107 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14108 | * @throws SecurityException if the caller does not have the required privileges |
| 14109 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14110 | * and integrity algorithms in use |
| 14111 | * @hide |
| 14112 | */ |
| 14113 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14114 | public boolean isNullCipherNotificationsEnabled() { |
| 14115 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14116 | checkForNullCipherNotificationSupport(); |
| 14117 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14118 | } |
| 14119 | |
| 14120 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14121 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14122 | * |
| 14123 | * <p>This method behaves in one of the following ways: |
| 14124 | * <ul> |
| 14125 | * <li>return true : if the calling package has the appop permission {@link |
| 14126 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14127 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14128 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14129 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14130 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14131 | * </ul> |
| 14132 | */ |
| 14133 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14134 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14135 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14136 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14137 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14138 | return true; |
| 14139 | } |
| 14140 | } |
| 14141 | return false; |
| 14142 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14143 | |
| 14144 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14145 | * @return The subscription manager service instance. |
| 14146 | */ |
| 14147 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14148 | return SubscriptionManagerService.getInstance(); |
| 14149 | } |
| 14150 | |
| 14151 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14152 | * Class binds the consumer[callback] and carrierId. |
| 14153 | */ |
| 14154 | private static class CallerCallbackInfo { |
| 14155 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14156 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14157 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14158 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14159 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14160 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14161 | } |
| 14162 | |
| 14163 | public Consumer<Integer> getConsumer() { |
| 14164 | return mConsumer; |
| 14165 | } |
| 14166 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14167 | public Set<Integer> getCarrierIds() { |
| 14168 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14169 | } |
| 14170 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14171 | |
| 14172 | /* |
| 14173 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14174 | * But the context that is passed in is unused if the phone app is already alive. |
| 14175 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14176 | */ |
| 14177 | @VisibleForTesting |
| 14178 | public void setPackageManager(PackageManager packageManager) { |
| 14179 | mPackageManager = packageManager; |
| 14180 | } |
| 14181 | |
| 14182 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14183 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14184 | * But the context that is passed in is unused if the phone app is already alive. |
| 14185 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14186 | */ |
| 14187 | @VisibleForTesting |
| 14188 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14189 | mAppOps = appOps; |
| 14190 | } |
| 14191 | |
| 14192 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14193 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14194 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14195 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14196 | */ |
| 14197 | @VisibleForTesting |
| 14198 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14199 | mFeatureFlags = featureFlags; |
| 14200 | } |
| 14201 | |
| 14202 | /** |
| 14203 | * Make sure the device has required telephony feature |
| 14204 | * |
| 14205 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14206 | */ |
| 14207 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14208 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14209 | if (callingPackage == null || mPackageManager == null) { |
| 14210 | return; |
| 14211 | } |
| 14212 | |
| 14213 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14214 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14215 | Binder.getCallingUserHandle()) |
| 14216 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14217 | // Skip to check associated telephony feature, |
| 14218 | // if compatibility change is not enabled for the current process or |
| 14219 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14220 | return; |
| 14221 | } |
| 14222 | |
| 14223 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14224 | throw new UnsupportedOperationException( |
| 14225 | methodName + " is unsupported without " + telephonyFeature); |
| 14226 | } |
| 14227 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14228 | |
| 14229 | /** |
| 14230 | * Registers for the satellite communication allowed state changed. |
| 14231 | * |
| 14232 | * @param subId The subId of the subscription to register for the satellite communication |
| 14233 | * allowed state changed. |
| 14234 | * @param callback The callback to handle the satellite communication allowed |
| 14235 | * state changed event. |
| 14236 | * |
| 14237 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14238 | * |
| 14239 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14240 | */ |
| 14241 | @Override |
| 14242 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14243 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14244 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
| 14245 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14246 | subId, callback); |
| 14247 | } |
| 14248 | |
| 14249 | /** |
| 14250 | * Unregisters for the satellite communication allowed state changed. |
| 14251 | * If callback was not registered before, the request will be ignored. |
| 14252 | * |
| 14253 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14254 | * allowed state changed. |
| 14255 | * @param callback The callback that was passed to |
| 14256 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14257 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14258 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14259 | */ |
| 14260 | @Override |
| 14261 | public void unregisterForCommunicationAllowedStateChanged( |
| 14262 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14263 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
| 14264 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback); |
| 14265 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14266 | |
| 14267 | /** |
| 14268 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14269 | * |
| 14270 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14271 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14272 | * if the request is successful or an error code if the request failed. |
| 14273 | * |
| 14274 | * @throws SecurityException if the caller doesn't have required permission. |
| 14275 | */ |
| 14276 | @Override |
| 14277 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14278 | enforceModifyPermission(); |
| 14279 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
| 14280 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14281 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14282 | |
| 14283 | /** |
| 14284 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14285 | * |
| 14286 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14287 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14288 | * |
| 14289 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14290 | */ |
| 14291 | @Override |
| 14292 | public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) { |
| 14293 | enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds"); |
| 14294 | mSatelliteController.requestProvisionSubscriberIds(result); |
| 14295 | } |
| 14296 | |
| 14297 | /** |
| 14298 | * Request to get provisioned status for given a satellite subscriber id. |
| 14299 | * |
| 14300 | * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check. |
| 14301 | * @param result The result receiver, which returns the provisioned status of the token if the |
| 14302 | * request is successful or an error code if the request failed. |
| 14303 | * |
| 14304 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14305 | */ |
| 14306 | @Override |
| 14307 | public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) { |
| 14308 | enforceSatelliteCommunicationPermission("requestIsProvisioned"); |
| 14309 | mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result); |
| 14310 | } |
| 14311 | |
| 14312 | /** |
| 14313 | * Deliver the list of provisioned satellite subscriber ids. |
| 14314 | * |
| 14315 | * @param list List of provisioned satellite subscriber ids. |
| 14316 | * @param result The result receiver that returns whether deliver success or fail. |
| 14317 | * |
| 14318 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14319 | */ |
| 14320 | @Override |
| 14321 | public void provisionSatellite(List<ProvisionSubscriberId> list, |
| 14322 | @NonNull ResultReceiver result) { |
| 14323 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
| 14324 | mSatelliteController.provisionSatellite(list, result); |
| 14325 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14326 | } |